1 | #include <stdlib.h>
|
2 | #include <avr/io.h>
|
3 | #include <avr/pgmspace.h>
|
4 | #include "lcd.h"
|
5 |
|
6 | /*
|
7 | ** constant definitions
|
8 | */
|
9 | static const PROGMEM unsigned char copyRightChar[] =
|
10 | {
|
11 | 0x07, 0x08, 0x13, 0x14, 0x14, 0x13, 0x08, 0x07,
|
12 | 0x00, 0x10, 0x08, 0x08, 0x08, 0x08, 0x10, 0x00
|
13 | };
|
14 |
|
15 |
|
16 | /*
|
17 | ** function prototypes
|
18 | */
|
19 | void wait_until_key_pressed(void);
|
20 |
|
21 |
|
22 | void wait_until_key_pressed(void)
|
23 | {
|
24 | unsigned char temp1, temp2;
|
25 | unsigned int i;
|
26 |
|
27 | do {
|
28 | temp1 = PIND; // read input
|
29 | for(i=0;i<65535;i++);
|
30 | temp2 = PIND; // read input
|
31 | temp1 = (temp1 & temp2); // debounce input
|
32 | } while ( temp1 & _BV(PIND2) );
|
33 |
|
34 | loop_until_bit_is_set(PIND,PIND2); /* wait until key is released */
|
35 |
|
36 | }
|
37 |
|
38 |
|
39 | int main(void)
|
40 | {
|
41 |
|
42 | int adc_wert;
|
43 | char buffer[7];
|
44 |
|
45 |
|
46 | DDRD &=~ (1 << PD2); /* Pin PD2 input */
|
47 | PORTD |= (1 << PD2); /* Pin PD2 pull-up enabled */
|
48 |
|
49 |
|
50 | /* initialize display, cursor off */
|
51 | lcd_init(LCD_DISP_ON);
|
52 |
|
53 | while(1)
|
54 | {
|
55 | /* clear display and home cursor */
|
56 | lcd_clrscr();
|
57 |
|
58 | /* put string to display (line 1) with linefeed */
|
59 | lcd_puts(" Digi - Waage\n");
|
60 |
|
61 | /* cursor is now on second line, write second line */
|
62 |
|
63 | lcd_puts("Gewicht:");
|
64 |
|
65 | // ******************************************************************** //
|
66 | // ****************************ADC************************************* //
|
67 | // ******************************************************************** //
|
68 | ADCSRA = 0x86; // 1000 0110
|
69 | ADMUX = 0x41; // 0100 0001
|
70 |
|
71 | ADCSRA |= (1<<ADSC);
|
72 | while(ADCSRA & (1<<ADSC));
|
73 |
|
74 | for(int i=0;i<10;i++) {
|
75 | // Eine Wandlung
|
76 | ADCSRA |= (1<<ADSC);
|
77 | // Auf Ergebnis warten...
|
78 | while(ADCSRA & (1<<ADSC));
|
79 |
|
80 | adc_wert = ADCL;
|
81 | adc_wert += (ADCH >> 8);
|
82 | }
|
83 |
|
84 | // ADC wieder deaktivieren
|
85 | //ADCSRA &= ~(1<<ADEN);
|
86 | // ******************************************************************** //
|
87 | // ******************************************************************** //
|
88 | // ******************************************************************** //
|
89 |
|
90 |
|
91 | /* move cursor to position 9 on line 2 */
|
92 |
|
93 | itoa(adc_wert,buffer,10);
|
94 | lcd_gotoxy(9,1);
|
95 |
|
96 | lcd_puts(buffer);
|
97 |
|
98 | lcd_gotoxy(14,1);
|
99 | lcd_puts("g");
|
100 |
|
101 | /* wait until push button PD2 (INT0) is pressed */
|
102 | wait_until_key_pressed();
|
103 |
|
104 |
|
105 | }
|
106 | }
|