Commit | Line | Data |
---|---|---|
bc0a8391 | 1 | #define F_CPU 1000000UL // Sets up the default speed for delay.h |
1375f65d H |
2 | // this is the header file that tells the compiler what pins and ports, etc. |
3 | // are available on this chip. | |
4 | #include <avr/io.h> | |
5 | ||
6 | // define what pins the LEDs are connected to. | |
7 | // in reality, PD6 is really just '6' | |
8 | #define LED PD5 | |
9 | ||
10 | // Some macros that make the code more readable | |
11 | #define output_low(port,pin) port &= ~(1<<pin) | |
12 | #define output_high(port,pin) port |= (1<<pin) | |
13 | #define set_input(portdir,pin) portdir &= ~(1<<pin) | |
14 | #define set_output(portdir,pin) portdir |= (1<<pin) | |
15 | ||
16 | // this is just a program that 'kills time' in a calibrated method | |
17 | void delay_ms(uint8_t ms) { | |
18 | uint16_t delay_count = F_CPU / 17500; | |
19 | volatile uint16_t i; | |
20 | ||
21 | while (ms != 0) { | |
22 | for (i=0; i != delay_count; i++); | |
23 | ms--; | |
24 | } | |
25 | } | |
26 | ||
27 | int main(void) { | |
28 | // initialize the direction of PORTD #6 to be an output | |
29 | set_output(DDRD, LED); | |
30 | ||
31 | while (1) { | |
32 | // turn on the LED for 200ms | |
33 | output_high(PORTD, LED); | |
34 | delay_ms(200); | |
35 | // now turn off the LED for another 200ms | |
36 | output_low(PORTD, LED); | |
37 | delay_ms(200); | |
38 | // now start over | |
39 | } | |
40 | } |