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
  • C Language! Please, comment what each line of code does in the code below and answer...

    C Language! Please, comment what each line of code does in the code below and answer this question: (sentence is fine) 1. Aside from pressing ctrl-(d/z) at the beginning of a line causing the getnchar() function to return NULL, is there any way to enter less than 9 characters? Code: void exer1(void) {    char input[LEN];    char *check; getchar(); // Clearing character buffer. printf("Please enter 9 characters: "); // Prompting the user to enter // a specific input.   ...

  • 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...

  • 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...

  • 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...

  • This question is about the Arduino code. Please complete a 4-input circuit on your Arduino. Your...

    This question is about the Arduino code. Please complete a 4-input circuit on your Arduino. Your circuit, in addition to cycling through a binary representation of the numbers 0-15 using LEDs, should use the Serial port to output the decimal equivalent of each of the numbers in the format: Output: 15 ... if the value was 1111, and so forth. You will be asked to upload your code as well as a photo of your working breadboard circuit. Add comments...

  • Please, explain clearly each line of code with your answers. Question 1 Consider the following code...

    Please, explain clearly each line of code with your answers. Question 1 Consider the following code snippet: int ctr = 0; int myarray[3]; for (int i = 0; i < 3; i++) { myarray[i] = ctr; ctr = ctr + i; } cout << myarray[2]; What is the output of the code snippet? Question 2 Consider the following code snippet: int cnt = 0; int numarray[2][3]; for (int i = 0; i < 3; i++) {   for (int j =...

  • Need help writing Java code for this question. CircleFrame class is provided below. what happen after...

    Need help writing Java code for this question. CircleFrame class is provided below. what happen after u add the code and follow the requirement? It would be nice to be able to directly tell the model to go into wait mode in the same way that the model's notify method is called. (i.e. notify is called directly on the model, whereas wait is called indirectly through the suspended attribute.) Try altering the the actionPerformed method of the SliderListener innner class...

  • Programing In C Add Command Line Arguments (Argc and Argv) and use files to the following...

    Programing In C Add Command Line Arguments (Argc and Argv) and use files to the following program. My program is called Ultimo.exe and it is in (C:\Users\Dell\source\repos\Ultimo\Debug). The file used is a .txt file in the directory of the .exe program. The text file which is address.txt is at the same location as Ultimo.exe (C:\Users\Dell\source\repos\Ultimo\Debug). The program takes information in the address.txt file and sorts it by zip code, from smallest to largest. The program works by using input/output redirection...

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