tweak voltage divider for my config
[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 <avr/pgmspace.h>
16 #include <inttypes.h>
17 #define F_CPU 8000000UL  // 8 MHz
18 #include <util/delay.h>
19 #include "lcd.h"
20 #include "kbd.h"
21 #include <stdlib.h>
22 #include <string.h> 
23
24
25 void delay_ms(uint16_t ms)
26 /* delay for a minimum of <ms> */
27 {
28         // we use a calibrated macro. This is more
29         // accurate and not so much compiler dependent
30         // as self made code.
31         while(ms){
32                 _delay_ms(0.96);
33                 ms--;
34         }
35 }
36
37
38 int main(void)
39 {
40         int16_t cnt;
41         uint8_t i=0;
42         lcd_init();
43         lcd_clrscr();
44         lcd_puts("LCD works");
45         init_kbd();
46         delay_ms(500);
47         while (1) {
48                 i++;
49                 cnt=1;
50                 check_u_button(&cnt);
51                 if (cnt>1){
52                         lcd_clrscr();
53                         lcd_puts_p(PSTR("U+ pressed"));
54                         i=0;
55                 }
56                 if (cnt<1){
57                         lcd_clrscr();
58                         lcd_puts_p(PSTR("U- pressed"));
59                         i=0;
60                 }
61                 cnt=1;
62                 check_i_button(&cnt);
63                 if (cnt>1){
64                         lcd_clrscr();
65                         lcd_puts_p(PSTR("I+ pressed"));
66                         i=0;
67                 }
68                 if (cnt<1){
69                         lcd_clrscr();
70                         lcd_puts_p(PSTR("I- pressed"));
71                         i=0;
72                 }
73                 if (check_store_button()){
74                         lcd_clrscr();
75                         lcd_puts_p(PSTR("store"));
76                         lcd_gotoxy(0,1);
77                         lcd_puts_p(PSTR("pressed"));
78                         i=0;
79                 }
80                 delay_ms(10);
81                 if (i>150){
82                         lcd_clrscr();
83                         lcd_puts_p(PSTR("press"));
84                         lcd_gotoxy(0,1);
85                         lcd_puts_p(PSTR("a button"));
86                         i=0;
87                 }
88
89         }
90         return(0);
91 }
92