Spread the love
___________________________________________________________________________________________________
- What is Timer ?- Timer is used to calculating the amounts of time between events.
- What is Counter ?- Counter is used to count external events.
- About Timer & Counter- Timer is fully depend upon the oscillator that attached externally to the microcontroller because it uses the frequency of oscillator to run. When we trigger timer it start from initial value and run up to decided value stored by user in special function registers. When it reach its maximum value, it overflows and a certain bit is decided to show over flow in SFR(special function register). Some timers also used prescalar technique to enhance its limits. AT89C51 contain two timer/counter T0 and T1 and which can be used in different mode like 8bit ,13bit and 16 bit. Maximum value that can be achieved by timer is depending upon its size. Suppose a timer is of 16 bit so it can achieved up to = 65536
- Applications- Generating rectangular pulses (signal modulation), Watchdog timers, Counting objects, Measuring intervals, generating delay, etc.
Click Here : Understanding of counter and timers in 8051
1. Generating delay of 1 sec using Timer 1 mode 0 and blink all LEDs using this delay.
/****************************************************** IDE :- Keil DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com) WHAT PROGRAM DO:- GENERATING 1SEC DELAY USING TIMER 0 ******************************************************/ #include<reg51.h> sfr led=0xa0; void timer_delay(); int i; void main() { TMOD=0X01; // MODE 1 OF TIMER O IS SELECTED while(1) { led=0x00; timer_delay(); led=0xff; timer_delay(); } } void timer_delay() { /* time delay of 1sec using 12MHz crystal oscillator*/ i=15; while(i--) { TL0=0X00; TH0=0X00; TR0=1; while(!TF0); TF0=0; TR0=0; } TL0=0X01; TH0=0X42; TR0=1; while(!TF0); TF0=0; TR0=0; }
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
____________________________________________________________________________________________________
2. Generating square ware of 100 us.
/****************************************************** IDE :- Keil DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com) WHAT PROGRAM DO:- GENERATING A SQUIRE WAVE OF 100 MICRO SECOND ******************************************************/ /*pulse of 100 micro second is created on pin p1.0*/ #include<reg51.h> sbit pin=P1^0; void timer_delay(); int i; void main() { TMOD=0X01; // MODE 1 OF TIMER O IS SELECTED while(1) { pin=0; timer_delay(); pin=1; timer_delay(); } } void timer_delay() { // time delay of 100 micro sec using 12MHz crystal oscillator TL0=0Xdb; TH0=0Xff; TR0=1; while(!TF0); TF0=0; TR0=0; }
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
____________________________________________________________________________________________________
Content for the tab VIDEO