___________________________________________________________________________________________________
- 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 operate. 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) also called flag bit. Some timers also used prescalar technique to enhance its limits.
- Applications- Generating rectangular pulses (signal modulation), Watchdog timers, Counting objects, Measuring intervals, generating delay, etc.
1. Circuit diagram creating a pulse using timers of PIC18F458 micrcontroller
________________________________________________________________________________________
1. PROGRAM TO CREATE A DELAY OF 1 SEC AT PORTD using timers of PIC18f458
/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- CREATE A DELAY OF 1 SEC ON PORTD OF PIC18F458
******************************************************/
/* header file used in this program is already included in software microC pro for pic*/
void timer_0(); // timer delay
void main()
{
TRISD=0X00; //PORTD AS OUTPUT MODE
T0CON=0X08; //TIMER0, 16 BIT MODE, NO PRESCALER
PORTD=0X00;
while(1)
{
PORTD=0X00; // TOGGLE THE VALUE OF PORTB
timer_0(); // CALLING FUNCTION
PORTD=0XFF;
timer_0();
}
}
void timer_0() //creating a delay of 1 sec
{
int i;
for(i=0;i<5;i++)
{
TMR0H=0X00; // LOAD TH0
TMR0L=0X00; //LOAD TL0
T0CON|=(1<<7); // TURN ON T0
while((INTCON & 0X04)==0); //WAIT FOR OVERFLOW
T0CON&=~(1<<7); // TURN OFF T0
INTCON&=~(1<<2); //CLEAR TF0
}
}
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
_____________________________________________________________________________________________
2. PROGRAM TO CREATE SQUARE WAVE OF 100 MS AT PORTC.0 using timers of PIC18F458
/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- CREATE A SQUARE WAVE OF 100 MS AT PORTC.0 OF PIC18F458
******************************************************/
/* header file used in this program is already included in software microC pro for pic*/
void timer_0(); // timer delay
#define PULSE portc.RC0
void main()
{
TRISC=0X00; //PORTD AS OUTPUT MODE
T0CON=0X08; //TIMER0, 16 BIT MODE, NO PRESCALER
PORTD=0X00;
while(1)
{
PULSE=0;
timer_0(); // CALLING FUNCTION
PULSE=1;
timer_0();
}
}
void timer_0() //creating a delay of 1 sec
{
TMR0H=0XFF; // LOAD TH0
TMR0L=0X00; //LOAD TL0
T0CON|=(1<<7); // TURN ON T0
while((INTCON & 0X04)==0); //WAIT FOR OVERFLOW
T0CON&=~(1<<7); // TURN OFF T0
INTCON&=~(1<<2); //CLEAR TF0
}
PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)
_____________________________________________________________________________________________
Content for the tab VIDEO


