0.6.0 this is the first version for the new hardware
[digitaldcpower] / test_lcd.c
1 /*********************************************
2 * vim: set sw=8 ts=8 si :
3 * Author: Guido Socher, Copyright: GPL 
4 * This is a test program which will write "LCD works"
5 * on the LCD display. 
6 * This program is also used to test the keypad. It
7 * displays the button last pressed.
8
9 * See http://www.tuxgraphics.org/electronics/
10
11 * Chip type           : ATMEGA8
12 * Clock frequency     : Internal clock 8 Mhz 
13 *********************************************/
14 #include <avr/io.h>
15 #include <inttypes.h>
16 #define F_CPU 8000000UL  // 8 MHz
17 #include <util/delay.h>
18 #include "lcd.h"
19 #include "kbd.h"
20 #include <stdlib.h>
21 #include <string.h> 
22
23
24 void delay_ms(uint16_t ms)
25 /* delay for a minimum of <ms> */
26 {
27         // we use a calibrated macro. This is more
28         // accurate and not so much compiler dependent
29         // as self made code.
30         while(ms){
31                 _delay_ms(0.96);
32                 ms--;
33         }
34 }
35
36
37 int main(void)
38 {
39         int16_t cnt;
40         uint8_t i=0;
41         lcd_init();
42         lcd_clrscr();
43         lcd_puts("LCD works");
44         init_kbd();
45         delay_ms(500);
46         while (1) {
47                 i++;
48                 cnt=1;
49                 check_u_button(&cnt);
50                 if (cnt>1){
51                         lcd_clrscr();
52                         lcd_puts_P("U+ pressed");
53                         i=0;
54                 }
55                 if (cnt<1){
56                         lcd_clrscr();
57                         lcd_puts_P("U- pressed");
58                         i=0;
59                 }
60                 cnt=1;
61                 check_i_button(&cnt);
62                 if (cnt>1){
63                         lcd_clrscr();
64                         lcd_puts_P("I+ pressed");
65                         i=0;
66                 }
67                 if (cnt<1){
68                         lcd_clrscr();
69                         lcd_puts_P("I- pressed");
70                         i=0;
71                 }
72                 if (check_store_button()){
73                         lcd_clrscr();
74                         lcd_puts_P("store");
75                         lcd_gotoxy(0,1);
76                         lcd_puts_P("pressed");
77                         i=0;
78                 }
79                 delay_ms(10);
80                 if (i>150){
81                         lcd_clrscr();
82                         lcd_puts_P("press");
83                         lcd_gotoxy(0,1);
84                         lcd_puts_P("a button");
85                         i=0;
86                 }
87
88         }
89         return(0);
90 }
91