Ich habe Timer0 so implementiert, so dass alle 10ms ein Interrupt
ausgelöst wird. Nun möchte ich nach einer bestimmten Zeit z.B. , dass
alle 0.5 Sekunden das Display EINMAL aktualisiert wird. Wie
implementiere ich dies richtig?
1 | uint8_t counter = 0;
|
2 |
|
3 | void timer0()
|
4 | {
|
5 | TCCR0 = (1<<CS02)|(1<<CS00); // divide by 1024
|
6 | TCNT0 = (-72); // preload for 10ms
|
7 | TIMSK |= 1<<TOIE0; // enable timer interrupt
|
8 | }
|
9 |
|
10 | ISR( TIMER0_OVF_vect ) // every 10ms
|
11 | {
|
12 | static uint8_t ct0, ct1, rpt;
|
13 | uint8_t i;
|
14 |
|
15 | TCNT0 = (-72); // preload for 10ms
|
16 | counter++;
|
17 | if(counter==100) // 1 Sekunde
|
18 | {
|
19 | sekunden++;
|
20 | counter=0;
|
21 | }
|
22 |
|
23 |
|
24 | uint8_t ms_Zehn(uint16_t n)
|
25 | {
|
26 | uint8_t status=0;
|
27 | if((counter%n==0)&&(TCCR0-old_tccr0 != 0))return status=1;
|
28 | else return status=0;
|
29 | }
|
30 |
|
31 | int main( void )
|
32 |
|
33 | while(1)
|
34 | {
|
35 | if ((ms_Zehn(50))==1) aktualisiere();
|
36 | }
|
Mein Problem liegt vorallem darin, dies nur einmal auszuführen. Aktuell
aktualisiert der das quasi 10ms konsiquent durch und dass alle 500ms.
PS: Aktuell ist counter mit bis 100 begrenzt, mir ist schon bewusst,dass
meine aktuelle Funktion nur bis 100*ms_Zehn sinn ergibt ;).