tutorial timer and counters
tutorial timer and counters
Example 1
create a square wave of 50% duty cycle (with equal portions high and low) on the P1.5 bit. Timer 0
is used to generate the time delay. Analyze the program. Also calculate the delay generated. Assume
XTAL=11.0592MHz.
Example 1
Find the delay generated by timer 0 in the following code, using hex as wellas decimal method. Do not
include the overhead due to instruction.
Program:
Example 3: Assume that XTAL = 11.0592 MHz. What value do we need to load the
timer’s register if we want to have a time delay of 5 ms ? Show the program for timer 0
to create a pulse width of 5 ms on P2.3.
Example 4: Assume that XTAL = 11.0592 MHz, write a program to generate a square
wave of 2 kHz frequency on pin P1.5. Assume XTAL = 11.0592 MHz, find the frequency of the
square wave
generated on pin P1.0 in the following program
Program:
MOV TMOD, #20H ; T1/8-bit/auto reload
MOV TH1, #5 ; TH1 = 5
SETB TR1 ; start the timer 1
BACK: JNB TF1, BACK ; till timer rolls over
CPL P1.0 ; P1.0 to high, low
CLR TF1 ; clear Timer 1 flag
SJMP BACK ; mode 2 is auto-reload