CONFIG TIMER0/de
Contents |
Funktion
Konfigurieren des TIMER0.
Syntax
CONFIG TIMER0 = COUNTER , EDGE=RISING/FALLING , CLEAR_TIMER = 1|0 [,CONFIGURATION=NAME]
CONFIG TIMER0 = TIMER , PRESCALE= 1|8|64|256|1024 [,CONFIGURATION=NAME]
CONFIG TIMER2 = TIMER | PWM , ASYNC=ON |OFF,PRESCALE = 1 | 8 | 32 | 64 | 128 | 256 | 1024 ,COMPARE = CLEAR | SET | TOGGLE | DISCONNECT ,PWM = ON | OFF ,COMPARE_PWM = CLEAR_UP| CLEAR_DOWN | DISCONNECT ,CLEAR_TIMER = 1|0 [,CONFIGURATION=NAME]
Anmerkungen
TIMER0 ist ein 8-Bit Zähler. Siehe Hardwarebeschreibung des TIMER0.
Wenn als COUNTER konfiguriert:
EDGE |
Man kann konfigurieren, ob auf fallende oder steigende Flanke gezählt werden soll. |
Wenn als TIMER konfiguriert:
PRESCALE |
In diesem Fall ist der Timer mit dem Systemtakt verbunden. Man kann die Vorteilung des Systemtaktes mit diesem Parameter auswählen.
Mögliche Werte sind 1 , 8, 64, 256 oder 1024 |
Beachen Sie, dass einige AVR Chips andere Prescale-Werte haben. Sie können diese benutzen.
CONFIGURATION ist optional. Wenn Sie configuration=mysetting benutzen dann kann man diese Settings beim Start des Timers benutzen: START TIMER0 , mysetting
Wenn man mehrere Settings hat dann kann man den Timer mit dieses unterschiedlichen Settings starten.
Beachten Sie, dass die Hilfe im Hinblick auf die AT90S2313 und AT90S8515 geschrieben wurde.
Wenn Sie den CONFIG TIMER0 Befehl benutzen dann wird der Modus gespeichert und das TCCRO Register wird gesetzt.
Wenn der STOP TIMER0 Befehl benutzt wird dann wird der Timer gestoppt.
Wenn der START TIMER0 Befehl benutzt wird dann wird das TIMER TCCR0 Register mit dem letzten Wert, der durch den CONFIG TIMER0 Befehl konfiguriert wurde geladen
Vor Benutzung des START oder STOP TIMER0 Befehls sollte daher erst der CONFIG Befehl benutzt werden.
Example
'----------------------------------------------------------------------------------------- 'name : timer0.bas 'copyright : (c) 1995-2005, MCS Electronics 'purpose : shows how to use TIMER0 related statements 'micro : 90S2313 'suited for demo : yes 'commercial addon needed : no '----------------------------------------------------------------------------------------- $regfile = "2313def.dat" ' specify the used micro $crystal = 8000000 ' used crystal frequency $baud = 19200 ' use baud rate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space 'First you must configure the timer to operate as a counter or as a timer 'Lets configure it as a COUNTER now 'You must also specify if it will count on a rising or falling edge Config Timer0 = Counter , Edge = Rising 'Config Timer0 = Counter , Edge = falling 'unremark the line aboven to use timer0 to count on falling edge 'To get/set the value from the timer access the timer/counter register 'lets reset it to 0 Tcnt0 = 0 Do Print Tcnt0 Loop Until Tcnt0 >= 10 'when 10 pulses are count the loop is exited 'or use the special variable TIMER0 Timer0 = 0 'Now configire it as a TIMER 'The TIMER can have the systemclock as an input or the systemclock divided 'by 8,64,256 or 1024 'The prescale parameter excepts 1,8,64,256 or 1024 Config Timer0 = Timer , Prescale = 1 'The TIMER is started now automaticly 'You can STOP the timer with the following statement : Stop Timer0 'Now the timer is stopped 'To START it again in the last configured mode, use : Start Timer0 'Again you can access the value with the tcnt0 register Print Tcnt0 'or Print Timer0 'when the timer overflows, a flag named TOV0 in register TIFR is set 'You can use this to execute an ISR 'To reset the flag manual in non ISR mode you must write a 1 to the bit position 'in TIFR: Set Tifr.1 'The following code shows how to use the TIMER0 in interrupt mode 'The code is block remarked with '( en ') '( 'Configute the timer to use the clock divided by 1024 Config Timer0 = Timer , Prescale = 1024 'Define the ISR handler On Ovf0 Tim0_isr 'you may also use TIMER0 for OVF0, it is the same Enable Timer0 ' enable the timer interrupt Enable Interrupts 'allow interrupts to occur Do 'your program goes here Loop 'the following code is executed when the timer rolls over Tim0_isr: Print "*"; Return ') End
Languages | English • Deutsch |
---|