0% found this document useful (0 votes)
22 views

Lab Task 11 (Timer As A Counter)

The document discusses using a timer register as a counter on a microcontroller. It provides background on microcontrollers and timers. The lab objective is to use a timer register as a counter and learn counter programming. The experiment connects an AT89C51 microcontroller development board to receive a clock signal on pin T1 and count up and display the value on port P1.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Lab Task 11 (Timer As A Counter)

The document discusses using a timer register as a counter on a microcontroller. It provides background on microcontrollers and timers. The lab objective is to use a timer register as a counter and learn counter programming. The experiment connects an AT89C51 microcontroller development board to receive a clock signal on pin T1 and count up and display the value on port P1.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Course Code and Name: Introduction to

Mechatronics Lab (ME-332L) Date:

Lab No: 11 Course Instructor: Engr. Zia Ur Rahman

Name of Student: Semester: 6th

Registration No: Department: Mechanical Engineering

Lab Task Using Timer Register as a Counter

1. To Learn how to use timer register as a counter


Objectives 2. To familiar with the counter programming and instruction

 STC AT89C51 Microcontroller


 Development Board
Hardware  Keil µ vision IDE
and Software  Prog-ISP
Requirements  Wires
 LEDs
 Proteus

Theory Microcontroller:
A microcontroller is a compact integrated circuit designed to govern a specific operation in
an embedded system. A typical microcontroller includes a processor, memory and input/output
(I/O) peripherals on a single chip.

Microcontroller 8051:
8051 microcontrollers are designed by Intel in 1981. It is an 8-bit microcontroller. It is built with
40 pins DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit
timers. It consists of are four parallel 8-bit ports, which are programmable as well as addressable
as per the requirement. An on-chip crystal oscillator is integrated in the microcontroller having
crystal frequency of 12 MHz.

Counter Programming:
Timers can also be used as counters counting events happening outside the 8051. When it is used
as a counter, however, it is a pulse outside the 8051 that increments the TH, TL registers. In
counter mode, notice that the TMOD and TH, TL registers are the same as for the timer.

Prepared by Tanveer Uz Zaman


C/T Bit in TMOD Register:
The C/T bit in the TMOD registers decides the source of the clock for the timer. If C/T = 0, the
timer gets pulses from the crystal. In contrast, when C/T = 1, the timer is used as a counter and
gets its pulses from outside the 8051. The counter counts up as pulses are fed from pins 14 and 15,
these pins are called T0 (timer 0 input) and T1 (timer 1 input). These two pins belong to port 3. In
the case of Timer 0, when C/T = 1, pin P3.4 provides the clock pulse and the counter counts up for
each clock pulse coming from that pin. Similarly, for Timer 1, when C/T = 1 each clock pulse
coming in from pin P3.5 makes the counter count up.

Fig. Table for Port 3 Pins for Timer 0 and 1

Diagram:

Fig. Development Board with AT89C51 Microcontroller

Prepared by Tanveer Uz Zaman


Procedure  First we have to write a code in C language in keil Software.
 In that code we have to specify pin T1 (P3.5).
 So, A Timer can be used as a counter if we provide pulses from outside the chip
instead of using the frequency of the crystal oscillator as the clock source.
 After that we have to create a hex file of that code.
 On the basis of that code we will use one microcontroller AT89C51 as a source to
provide frequency to the receiver microcontroller.
 The hex file will be uploaded into STC AT89C51 Microcontroller through Prog-
ISP.

Connection Diagram:

Fig. Connection Diagram

Prepared by Tanveer Uz Zaman


Programming Assume that a 1-Hz external clock is being fed into pin T1 (P3.5). Write a C program for counter
Code 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.

Results and
Conclusions

Prepared by Tanveer Uz Zaman

You might also like