Académique Documents
Professionnel Documents
Culture Documents
Timer 0 - Examples
T0CON:
Exercise 1:
Solution:
7
T0CON
TMR0
ON
T08BIT
T0CS
T0SE
PSA
T0PS2
T0PS1
T0PS0
0xFD5
so:
T0CON = 0x08;
Exercise 2:
Calculate the amount of time delay generated by Timer 0 with the following specifications:
fosc = 10 MHz,
TMR0H:TMR0L=0XFFF22
Solution:
Tic =
4
4
=
= 0.4 106 s = 0.4 s
6
f osc 10 10
How many clock ticks are counted before timer reaches its full count?
(0xFFFF 0xFFF2) + 1 = 0x000D + 1 = 0x000E = 14
Time delay: Td = 14 Tic = 14 0.4 = 5.6 s
Exercise 3:
Write a C program to toggle all the bits of PORTB continuously with 1 ms delay.
Use Timer 0 in 16-bit mode and no prescaler options. Assume fosc = 20 MHz.
Solution:
Tic =
4
4
=
= 0.2 106 s = 0.2 s
f osc 20 106
N=
Td
1 ms
1 103
=
=
= 5 103 = 5000 = 0x1388
6
Tic 0.2 s 0.2 10
Solution:
Tic =
4
4
=
= 0.2 106 s = 0.2 s
6
f osc 20 10
T
50 ms
N= d =
= 250 103 = 250000 = 0x3D090
Tic 0.2 s