BACK
NEXT
3.2. Timer/ Counter
Mode 1 : 16 bit Counter
Mode 1 is the same as Mode 0, except that the
Timer register is being run with all 16 bits.

Figure 3.2. Timer/Counter Mode
1: 16-Bit Counter
3.2.1.
Generate pulse by using Timer 1 mode 1
By using Timer function, we can
design a pulse generator and outputs data to port. as you see on figure
3.3.1., with frequency 1 Hz
Step
1st
Build the circuit as shown in figure 3.2.1. As you seen on figure 3.2.1.
P0.0 is connected to LED. Remember, that all we want to do with this
lesson is generate a pulse with frequency 1 Hz
Step
2nd
In this step, you must tipe the assembly program to make your Timer
get action, we assume that you have already known the editor, we used
MIDE-51 to edit the program. ( Download File : exp32.zip
)

Figure 3.2.1. A pulse generator
from timer function

Figure 3.2.2. Pulse Periode 1
second
Note that in this mode, with
a 12 MHz crystal frequency, the timer overflows every 65,536 microseconds.
In this experiment, to generate interruption every 1000 micro second,
then :
65536 - 10000 = 55536 d or D8F0h
Interruption will come out every 1000 x 1 microsecond = 0.01 second.
R0 is implemented as a software counter, Register R0 is incremented
every Timer 0 overflows. If Register R7 detected with value 50 then
port P0.0 will output data with Ton = 0,01 x 50 second = 0,5 second.
Org 0h Start: Setb P0.0 ;P0.0 = 1 call Delay ;call delay time Clr P0.0 ;P0.0 = 0 Sjmp Start ;Looping Forever ; Delay: Mov R0,#0 ;R0 = 0 Mov TMOD,#00010000b ;mode 1, Timer 1 Load: Mov TH1, #0D8h ;TH1 = D8h Mov TL1, #0F0h ; TL1 = F0h Setb TR1 ; TR1 = 1, Start Running OFlow: JNB TF1, OFlow ; jump to OFlow if TF1 =0 Inc R0 ; R0 = R0+1 CJNE R0,#50,Load; Ret ; End
Step
3rd
Safe your assembly program above, and name it with timer2.asm (for example)
Compile the program that you have been save by using MIDE-51, see the
software instruction.
Step 4th
Download your hex file ( timer2.hex ) into the microcontroller
by using Microcontroller ATMEL ISP software, see the instruction.After
download this hex file you'll see the action of Timer( of course if
your cable connection and your program are corrected ).
BACK
NEXT
|