sources from initial AVR turn-on for TeleTerra
[fw/altos] / avr / tthello.c
1 #include <inttypes.h>
2 #include <avr/io.h>
3 #include <avr/interrupt.h>
4 #include <avr/sleep.h>
5
6 void wait_until_key_pressed(void)
7 {
8     unsigned char temp1, temp2;
9     unsigned int i;
10     
11     do {
12         temp1 = PINC;                  // read input
13         for(i=0;i<65535;i++);
14         temp2 = PINC;                  // read input
15         temp1 = (temp1 & temp2);       // debounce input
16     } while ( temp1 & _BV(PINC4) );
17     
18     loop_until_bit_is_set(PINC,PINC4); /* wait until key is released */
19 }
20
21 int main (void)
22 {
23         // configure to read center press on joy switch
24         DDRC &=~ (1 << PC4);        /* Pin PC4 input              */
25         PORTC |= (1 << PC4);        /* Pin PC4 pull-up enabled    */
26
27         for (;;) {                           /* loop forever */
28                 // turn on LCD backlight LED
29                 PORTD = 0xff;
30                 wait_until_key_pressed();
31                 PORTD = 0;
32                 wait_until_key_pressed();
33         }
34         return 0;
35 }