Experiment - 9:
DATE:
CO2: Describe the architecture of 8051 microcontroller for programming and interfacing
applications.
A. Aim
a) Write an 8051 C program to toggle the bit of P3.5 continuously every 500ms using
Timer 1, mode 1 by creating a delay and realize it with ESA MCB 51 board
hardware.
b) Assume 1-Hz external clock that is being fed into pin T1 (P2.5). Write a C program
for counter 1 in mode 2 (8-bit auto reload) to count up and display the state of the
TL1 count on P1. Start the count at 0H. P1 is connected to 8 LEDs.
B. Theory
• TIMER 0 and Timer 1 register
The 16 bit register of timer 0 is accessed as low byte and high byte. The low byte register is
called TL0 (timer 0 low byte) and the high byte register is referred to as TH0 ( timer 0 high byte).
• TCON register
1|Page Win 24-25: course handled by M.A Inayathullaah
• TMOD register
C. Model Calculation
• Steps for finding the TH, TL register values
o Divide the desired time delay by 1.085 μs.
o Perform 65536 – n, where n is the decimal value, we got in Step 1.
o Convert the result of Step2 to hex, where yyxx is the initial hex value to be loaded into
the timer’s register.
o Set TL = xx and TH = yy.
• Delay Calculation: A5FEH = 42494 in decimal
o 25ms/1.085 μs =23042
o 65536 – 23042 = 42494
o 42494 in decimal = A5FEH in hexadecimal
o Using for loop 20 times to get desired delay (20 × 25 ms = 500 ms )
D. Hardware Implementation
2|Page Win 24-25: course handled by M.A Inayathullaah
26 Pin Male Connector for ports P0, P1 and P2
E. C language Program
• Timer Program
3|Page Win 24-25: course handled by M.A Inayathullaah
• Counter Program
Output window
• Timer operation
4|Page Win 24-25: course handled by M.A Inayathullaah
• Counter operation
Learning Outcome:
5|Page Win 24-25: course handled by M.A Inayathullaah
Exercise-9:
1. Write an 8051 C program to toggle only pin P1.4 continuously every 250 ms. Use Timer
0, mode 2 (8-bit auto-reload) to create the delay.
Time Delay:
o 25 μs /1.085 μs =23
o 256 – 23 = 233 =E9H
o 25 μs × 250 × 40 = 250 ms
2. Write a C Program, Assuming that XTAL=11.0592 MHz to generate a time delay of 5ms using the
Timer 0 to create a pulse width of 5 ms on P2.3.
3. Write a C Program, Assuming that XTAL = 11.0592 MHz, to generate a square wave of 2 kHz frequency
on pin P1.5.
6|Page Win 24-25: course handled by M.A Inayathullaah
4. Write a C Program, Assuming that XTAL = 11.0592 MHz, to generate a square wave of frequency 72Hz
on pin P1.0 using auto reload mode.
5. Assume that a 1-Hz external clock is being fed into pin T0 (P3.4). Write a C program for counter 0 in
mode 1 (16-bit) to count the pulses and display the state of the TH0 and TL0 registers on P2 and P1,
respectively.
Pre Lab Marks (2-mark Max) In Lab Marks (3-mark Max) Post Lab Marks (5-mark Max)
7|Page Win 24-25: course handled by M.A Inayathullaah