El TIMER0
es un contador de 16bits, a interrumpir cada 1 segundo establece:
Prescaler @ 16
TMR0 Carga @ 3036
La ecuación:
$$T = \left(\frac{4}{Fosc}\right) \cdot Presc \cdot (Resolution - Preload)$$
Donde:
- T = período = 1s
- FOSC = frecuencia del oscilador = 4MHz
- Presc = Prescaler = 16
- Resolución = 216 = 65535
- Precarga = 3036
Código de ejemplo:
// Timer0 Registers:16-Bit Mode; Prescaler=1:16; TMRH Preset=$BD;
// TMRL Preset=$DC; Freq=1,00Hz; Period=1,00 s
T0CON.TMR0ON = 1; // Timer0 On/Off Control bit: 1=Enables Timer0 / 0=Stops Timer0
T0CON.T08BIT = 0; // Timer0 8-bit/16-bit Control bit: 1=8-bit timer/counter / 0=16-bit timer/counter
T0CON.T0CS = 0; // TMR0 Clock Source Select bit: 0=Internal Clock (CLKO) / 1=Transition on T0CKI pin
T0CON.T0SE = 0; // TMR0 Source Edge Select bit: 0=low/high / 1=high/low
T0CON.PSA = 0; // Prescaler Assignment bit: 0=Prescaler is assigned; 1=NOT assigned/bypassed
T0CON.T0PS2 = 0; // bits 2-0 PS2:PS0: Prescaler Select bits
T0CON.T0PS1 = 1;
T0CON.T0PS0 = 1;
TMR0H = $BD; // preset for Timer0 MSB register
TMR0L = $DC; // preset for Timer0 LSB register