8051 Micro-controller

8051 COUNTER
Counter is very useful in embedded system because we always need something for counting events happening outside.
let’s take a example if we want to make a visitor counter for counting visitor in museum then we need a device that count person at entry gate. To make this type of device we need counter in embedded device.
- Now timers can also be used as counters counting events happening outside the 8051.
- When timer is used as a counter, it is a pulse outside of the 8051 that increments the TH, TL registers.
- TMOD and TH, TL registers are the same as for the timer discussed in timer section.
- Programming the timer in the timer section also applies to programming it as a counter except the source of the frequency.
C/T Bit in TMOD Register :
- The C/T bit in the TMOD registers decides the source of the clock for the timer.
- 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).

Pin | Port Pin | Function | Description Function |
14 | P3.4 | T0 | Timer/counter 0 external input |
15 | P3.5 | T1 | Timer/counter 1 external input |
Example:
Assume that a 1-Hz external clock is being fed into pin T1 (P3.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.
Solution:
#include <reg51.h> sbit T1=P3^5; void main(void){ T1=1; TMOD=0x60; TH1=0; while (1) { do { TR1=1; P1=TL1; } while (TF1==0); TR1=0; TF1=0; } }
Example:
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.
Solution:
#include <reg51.h> void main(void){ T0=1; TMOD=0x05; TL0=0 TH0=0; while (1) { do { TR0=1; P1=TL0; P2=TH0; } while (TF0==0); TR0=0; TF0=0; } }
The Intel 8051 microcontroller is among one of the most popular general purpose microcontrollers in use today. The success of the Intel 8051 spawned a number of clones which are collectively referred to as the MCS-51 family of microcontrollers, which includes chips from vendors such as Atmel, Philips, Infineon, and Texas Instruments.
Historical Background
- 1947 Invention of Transistors.
- 1959 Invention of Integrated Circuits.
- 1971 Invention of Microprocessor.
- 1976 Invention of Microcontroller.
Today, over 50 companies produce variations of the 8051. 8051 cores are available for implementations in Field Programmable Gate Arrays (FPGA) or Application Specific Integrated Circuits (ASIC). The 8051 was developed by Intel but other manufacturers (e.g., Siemens, Philips, Atmel, etc.) are second sources of this family of devices.
Course Features
- Lectures 16
- Quizzes 0
- Duration 10 hours
- Skill level All levels
- Language English
- Students 51
- Certificate No
- Assessments Self