Program:
/***************************************/
//Author : Palak Patel
//Contact No:9173211683
//Title:Timer 2 For PIC18F4520
//Platform: PIC18f4520
/*Calculation
(64us/0.25us)= 256
convert this 256 in to hex
hex=FF*/
//Fosc=16Mhz//Timer Frequency=16Mhz/4=4Mhz
//Timer Period=1/4Mhz=0.00000025=0.25us=0.00025ms
//Max time=256*0.25us=0.000064=64us
/***************************************/
#include<p18f4520.h>
#pragma config OSC = HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config STVREN = OFF
#pragma config LVP = OFF
#define led PORTC
void delay();
void main()
{
TRISC=0x00;
T2CONbits.T2OUTPS3=0; //Postscaler=1:1
T2CONbits.T2OUTPS2=0;
T2CONbits.T2OUTPS1=0;
T2CONbits.T2OUTPS0=0;
T2CONbits.T2CKPS1=0;
T2CONbits.T2CKPS0=0; //Prescaler=1:1
while(1)
{
led=0x00;
delay();
led=0xFF;
delay();
}
}
void delay()
{
TMR2=0x00;
PR2=0xFF; //PR2=256
T2CONbits.TMR2ON=1; //Timer2=on
while(PIR1bits.TMR2IF==0);
PIR1bits.TMR2IF=0; //Timer 2 Overflow flag
T2CONbits.TMR2ON=0; //Timer2=off
}
Proteus Simulation:
^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^
No comments:
Post a Comment