Hallo Leute, Hier habe ich ein code für eine einfache Uhr zusammengestellt. Leider kriege ich nicht das was ich will am LCD. Die zahl der sekunden zahlt bis 59 oder 60 und springt zu 19 und aufwärts also nicht wieder von null. Kann jemand mir helfen um festzustellen wo liegt ein Fehler im code. Ich benütze ATmega8 @4 MHz, Genauigkeit ist mir jetzt nicht wichtig. Ich lerne die TIMERx_OVF in Zahlen auf Display zu setzen. Danke im Vorraus
1 | \\Uhr Versuch, Atmega8. 4MHz. |
2 | |
3 | #include <stdio.h> |
4 | #include <avr/delay.h> |
5 | #include <stdlib.h> |
6 | #include <avr/io.h> |
7 | #include <avr/pgmspace.h> |
8 | #include <avr/signal.h> |
9 | #include <avr/interrupt.h> |
10 | #include "lcd.h" |
11 | |
12 | |
13 | // define global variables
|
14 | |
15 | volatile uint8_t Seconds; |
16 | volatile uint8_t Minutes; |
17 | volatile uint8_t Hours; |
18 | char buffer[4]; |
19 | |
20 | // ISR
|
21 | ISR(TIMER1_OVF_vect)// |
22 | {
|
23 | |
24 | if (++Seconds ==60) |
25 | {
|
26 | Seconds=0; |
27 | |
28 | if (++Minutes == 60) |
29 | {
|
30 | Minutes = 0; |
31 | |
32 | |
33 | if (++Hours == 24) |
34 | {
|
35 | Hours = 0; |
36 | |
37 | Seconds=0; |
38 | |
39 | }
|
40 | |
41 | }
|
42 | |
43 | }
|
44 | |
45 | }
|
46 | |
47 | |
48 | void init_timer(void) |
49 | {
|
50 | |
51 | TIMSK|=(1<<TOIE1);//enable overflow interrrupt. |
52 | TCCR1B|=(1<<CS11); |
53 | sei(); // enable global interrupts |
54 | }
|
55 | |
56 | |
57 | int main(void) |
58 | {
|
59 | |
60 | |
61 | |
62 | init_timer(); // Timer init |
63 | lcd_init(LCD_DISP_ON); // LCD-Display init |
64 | |
65 | lcd_puts("Time"); |
66 | lcd_gotoxy(4,1); |
67 | |
68 | |
69 | for (;;) // Loop |
70 | |
71 | {
|
72 | |
73 | lcd_gotoxy(4,1);// |
74 | lcd_puts(":"); |
75 | itoa(Hours, buffer,10); |
76 | lcd_puts(buffer); |
77 | |
78 | |
79 | lcd_gotoxy(7,1); |
80 | lcd_puts(":"); |
81 | itoa(Minutes, buffer,10); |
82 | lcd_puts(buffer); |
83 | |
84 | |
85 | lcd_gotoxy(10,1); |
86 | lcd_puts(":"); |
87 | itoa(Seconds,buffer,10); |
88 | lcd_puts(buffer); |
89 | |
90 | }
|
91 | }
|