Question

Please comment and or provide information on what each function or line does within the following...

Please comment and or provide information on what each function or line does within the following code. The code is a Arduino Atmega C programming language code which which creates a piano keyboard outputting different frequencies per. I would really appreciate a detailedf explanation on what each function and line does as I am a beginner and need to use this within lab.

volatile unsigned char *TCCR1A = (unsigned char *) 0x80; /* Address location for Timer/Counter Control Register A. */
volatile unsigned char *TCCR1B = (unsigned char *) 0x81; /* Address location for Timer/Counter Control Register B. */
volatile unsigned char *TCCR1C = (unsigned char *) 0x82; /* Address location for Timer/Counter Control Register C. */
volatile unsigned char *TIMSK1 = (unsigned char *) 0x6F; /* Address location for Timer/Counter 1 Interrupt Mask Register. */
volatile unsigned int *TCNT1 = (unsigned int *) 0x84; /* Address location for Timer/Counter 1L (lower 8-bits). */
volatile unsigned char *TIFR1 = (unsigned char *) 0x36; /* Address location for Timer/Counter 1 Interrupt Flag Register. */
volatile unsigned char *PORT_B = (unsigned char *) 0x25; /* Address location for PORT B. */
volatile unsigned char *PORT_DDRB = (unsigned char *) 0x24; /* Address location for PORT B Data Direction Register. */
unsigned int Value[13] = {18181, 17167, 16194, 15286, 14440, 13628, 12820, 12139, 11461, 10810, 10204, 9626, 0};
unsigned char Input[13] = {'a', 'A', 'b', 'c', 'C', 'd', 'D', 'e', 'f', 'F', 'g', 'G', 'q'};
volatile unsigned int note;

void myTimer(unsigned int note);


byte byteRead;

void setup()
{
  
Serial.begin(9600);

*TCNT1 &= 0;

*TCCR1A &= 0;
*TCCR1B &= 0;
*TCCR1C &= 0;
*TIMSK1 &= 0;
  
*PORT_DDRB |= 0x40;
  
}


void loop()
{


  
if (Serial.available())
{
  
byteRead = Serial.read();
  

Serial.write(byteRead);
}

  
for(int i = 0; i<13; i++){
if(Input[i] == byteRead){
note = Value [i];
}
}
  
  
*PORT_B |= 0x40;
myTimer(note);
*PORT_B &= 0xBF;
myTimer(note);
  

}

void myTimer(unsigned int note)
{
*TCCR1B &= 0xF8;
/* Load Timer/Counter 1 and delay for half of the period. */
*TCNT1 = unsigned int (65536 - note);
/* Set the precsaler to 1, Timer 1, NORMAL mode. */
*TCCR1B |= 0x01;
/* Set PORT_B HIGH. */
*PORT_B |= 0x40;
/* Wait for TIFR1 overflow flag bit to be set. */
while ((*TIFR1 & 0x01) == 0);
/* Turn off the Timer after getting delay. */
*TCCR1B &= 0xF8;
/* Clear the flag bit on TIFR1 for next use. */
*TIFR1 |= 0x01;
  
  
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Serial.begin(9600): this line is for selection of baud rate. Here it selects baud rate of 9600 means 9600 bits information transfer per sec.

*TCNT1 &= 0;

*TCCR1A &= 0;
*TCCR1B &= 0;
*TCCR1C &= 0;
*TIMSK1 &= 0;(These lines are for assigning off condition to the arduino ports.)

byteRead = Serial.read(); This line is for taking input signals.

if(Input[i] == byteRead) : this will compare the value of input with byte entered.
note = Value [i]; Here if above condition will be true then note will get assigned value of value[i].

Add a comment
Know the answer?
Add Answer to:
Please comment and or provide information on what each function or line does within the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Name: Grade: 710 [10] 1) For the following MSP430 C program, fill in the comments next...

    Name: Grade: 710 [10] 1) For the following MSP430 C program, fill in the comments next to the // to indicate the function of the corresponding line. Be brief, no more than one line per comment; be inspired by the existing comments. #include <msp43092553.b> //LEDI mounted on bit as an output #define LEDI B ITO #define LED2 BITO #define BUTTON BIT3 unsigned int folds = 1; int i=1; void main(void) WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer PLOUT...

  • Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code...

    Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code for 8-bit signed array, 16-bit unsigned array, 16-bit signed array, 32-bit signed array and 32-bit signed array. 2) Fill in all the blanks in Table 1 using your completed code, following the hints provided within the table. 3) Fill in all the blanks in Table 2 using your completed code, following the hints provided within the table. C++ Program #include <stdio.h> #include <iostream> int...

  • Translate the following C code into assembly BIT PONG #define Led(1) = 0.01 #define Led(2) =...

    Translate the following C code into assembly BIT PONG #define Led(1) = 0.01 #define Led(2) = 0.02 #define Led(3) = 0.01 #define Led(4) = 0.08 #define Led(5) = 0.10 #define Led(6) = 0.10 #define Led(7) = #define Led(8) = Unsigned int_delay (){ do a--i while (a! = 0) return } int main (void) { while (1) { int a = 1000 i volatile int i = 0: for { delay(a): }

  • The following C code keeps returning a segmentation fault! Please debug so that it compiles. Also...

    The following C code keeps returning a segmentation fault! Please debug so that it compiles. Also please explain why the seg fault is happening. Thank you #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // @Name loadMusicFile // @Brief Load the music database // 'size' is the size of the database. char** loadMusicFile(const char* fileName, int size){ FILE *myFile = fopen(fileName,"r"); // Allocate memory for each character-string pointer char** database = malloc(sizeof(char*)*size); unsigned int song=0; for(song =0; song < size;...

  • Question: Please Provide Comments on each Line of code explaining what the C Function is doing throughout the code. // Function used for substitution encryption                     void SubEncrypt(cha...

    Question: Please Provide Comments on each Line of code explaining what the C Function is doing throughout the code. // Function used for substitution encryption                     void SubEncrypt(char *message, char *encryptKey) { int iteration = 0; printf("Enter Aphabet Encryption Key: \n"); scanf("%s", encryptKey);    for (iteration = 0; iteration < strlen(message); iteration++) { char letter = message[iteration]; if (letter >= 'A' && letter <= 'Z') {    letter = encryptKey[letter - 'A']; } message[iteration] = letter; } printf("CipherText message: %s\n", message); } //_________________________________________________________________________________________________________________________________________________...

  • Given the following code and keypad layout, what will the function GetKey() return when it is...

    Given the following code and keypad layout, what will the function GetKey() return when it is run while keys 2, 3, 7, B, E, and F are pressed? DDRH = 0x0F; RDRH = 0x00; PERH = 0x00; PIEH = 0x00; PTH = 0x0F; unsigned char GetKey(void) { unsigned char KeyMask[16] = { 0xEE, 0xDE, 0xBE, 0x7E, 0XED, 0xDD, 0xBD, 0x7D, 0xEB, 0xDB, 0xBB, 0x7B, 0xE7, 0xD7, 0xB7, 0x77 }; int i; char Key; for (Key=0, i=0; i<16; i++) { PTH...

  • Question 1: Pointers You are given the following C code and memory diagram. The “contents” column...

    Question 1: Pointers You are given the following C code and memory diagram. The “contents” column of the memory diagram shows the value of the variable. Update the “contents” column of the memory diagram for each assignment in main(). long *pt; long data;    long buffer[4]; void main(void){   pt = &buffer[1];   *pt = 1234;   data = *pt; } address      contents   variable 0x20000000 0x00000000    pt 0x20000004 0x00000000    data 0x20000008 0x00000000    buffer[0] 0x2000000C 0x00000000    buffer[1] 0x20000010 0x00000000    buffer[2] 0x20000014 0x00000000    buffer[3]...

  • (f) and (g) please f and g please letters Question 2 Indirect addressing mode in assembly language is sanilar to pointers in C. Answer the following questions: (1 point) a) How many 8-bit reg...

    (f) and (g) please f and g please letters Question 2 Indirect addressing mode in assembly language is sanilar to pointers in C. Answer the following questions: (1 point) a) How many 8-bit registers can a FSR access in the PICI8F452 MCU? b) Write the assembly language command to load the address of the variable with name: PVal into one of the FSR? (2 points) (2 points) (2 points) c) What is the meaning of: movf PREINC2, F? d) What...

  • Provide comments for this code explaining what each line of code does import java.util.*; public class...

    Provide comments for this code explaining what each line of code does import java.util.*; public class Chpt8_Project {    public static void main(String[] args)       {        Scanner sc=new Scanner(System.in);        int [][]courses=new int [10][2];        for(int i=0;i<10;i++)        {            while(true)            {                System.out.print("Enter classes and graduation year for student "+(i+1)+":");                courses[i][0]=sc.nextInt();                courses[i][1]=sc.nextInt();                if(courses[i][0]>=1...

  • Implement the following statements using MS430 assembly instructions. You may use more than one, ...

    Implement the following statements using MS430 assembly instructions. You may use more than one, but you should minimize the number of instructions required. You can use both native and emulated instructions. Use hex notation for all numbers 1. (a) Move the word located in register R14 to R15 (b) Increment the word in R6 by 2. (c) Perform a bitwise ANDing of the word located at address 0x0240 with the datum in R15, placing the results in R15. (d) Rotate...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT