Hi, I'm new here. I am having problems reading this code, to understand what each function does as I do not have much experience with this computer programming. I hope to get an idea of this code as a base, to use it as a LED blinker to allow me to show that it can signal time.
The following code is suppose to light an LED after being switched on for 10 seconds. We are using an Atmega88 AVR Chip that will be programed.
// AVR IO memory space
#include <avr/io.h>
// Macro defn to select bit n, assuming 0 <= n <= 7
#define BIT(n) (1 << (n)) [b]//what does this do, I am unfamiliar with this call[/b]
// Delay function
void delay (unsigned char time)
{
unsigned char t1, t2;
unsigned int count = 0;
for (t1 = time; t1 > 0; --t1){ [b]//this will be the timer countdown[/b]
for (t2 = 255; t2 > 0; --t2){ [b]//why do we count down from 255 here?[/b]
count += 1;
}
}
return;
}
// Main function
int main (void)
{
unsigned char LEDbit;
DDRD = 0xFF; // set all PortD to output [b]I assume this is the output of the AVR port that will be used to light the LED[/b]
LEDbit = 0;
while(1){ // forever looped
LEDbit += 1;
if (LEDbit > 7) LEDbit = 0;
// turn on LED # by writing 0 to its MCU pin
PORTD = ~BIT(LEDbit); [b]//This is the function that I am getting confused, PORTD is probably an output variable from the io.h, but what does the ~BIT(LEDbit) do, and why the new for the LEDbit counter?[/b]
// delay by (#) seconds
delay(10);
}
return 0;
}
Thanks for the help, much appreciated