Rev 205 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 205 | arune | 1 | /********************************************* |
| 2 | * vim:sw=8:ts=8:si:et |
||
| 3 | * To use the above modeline in vim you must have "set modeline" in your .vimrc |
||
| 4 | * Author: Guido Socher, Copyright: GPL V2 |
||
| 5 | * This program is to test basic functionallity by getting an LED to blink. |
||
| 6 | * See http://linuxfocus.org/English/November2004/ for details. |
||
| 7 | * Chip type : ATMEGA88 |
||
| 8 | *********************************************/ |
||
| 9 | #include <avr/io.h> |
||
| 10 | #include <inttypes.h> |
||
| 11 | #include <util/delay.h> |
||
| 12 | |||
| 13 | |||
| 14 | void delay_ms(unsigned int ms) |
||
| 15 | /* delay for a minimum of <ms> */ |
||
| 16 | { |
||
| 17 | // we use a calibrated macro. This is more |
||
| 18 | // accurate and not so much compiler dependent |
||
| 19 | // as self made code. |
||
| 20 | while(ms){ |
||
| 21 | _delay_ms(0.96); |
||
| 22 | ms--; |
||
| 23 | } |
||
| 24 | } |
||
| 25 | |||
| 26 | int main(void) |
||
| 27 | { |
||
| 28 | /* INITIALIZE */ |
||
| 29 | // Be very careful with low frequencies (less than 1MHz). Modern and fast programmers |
||
| 30 | // can not supply such low programming clocks. It can lock you out! |
||
| 31 | // |
||
| 32 | // set the clock prescaler. First write CLKPCE to enable setting of clock the |
||
| 33 | // next four instructions. |
||
| 34 | CLKPR=(1<<CLKPCE); |
||
| 35 | CLKPR=0; // 8 MHZ |
||
| 36 | //CLKPR=(1<<CLKPS0); // 4MHz |
||
| 37 | //CLKPR=((1<<CLKPS0)|(1<<CLKPS1)); // 1MHz |
||
| 38 | //CLKPR=((1<<CLKPS0)|(1<<CLKPS2)); // 0.25MHz |
||
| 39 | |||
| 40 | /* enable PB1 as output */ |
||
| 41 | DDRB|= (1<<DDB1); |
||
| 42 | |||
| 43 | while (1) { |
||
| 44 | /* led on, pin=0 */ |
||
| 45 | PORTB &= ~(1<<PB1); |
||
| 46 | delay_ms(500); |
||
| 47 | /* set output to 5V, LED off */ |
||
| 48 | PORTB|= (1<<PB1); |
||
| 49 | delay_ms(500); |
||
| 50 | } |
||
| 51 | return(0); |
||
| 52 | } |
||
| 53 | |||
| 54 |