Search

Friday, December 26, 2014

Timer 1 For PIC 18

Program:

/***************************************/
//Author : Palak Patel
//Contact No:9173211683
//Title:Timer 1 For PIC 18 F 4520
//Platform: PIC18f4520

/*Calculation

(1ms/0.25us)= 4000

65536-4000=61536

convert this 61536 in to hex

hex=F060*/

/***************************************/



#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;

while(1)

{

led=0x00;

delay();

led=0xFF;

delay();

}

}

//Timer For 16ms

void delay()

{

TMR1H = 0x00;

        TMR1L = 0x00;

T1CON = 0x01;

while (PIR1bits.TMR1IF == 0); 

  PIR1bits.TMR1IF = 0;

T1CON = 0xC0;

}


/***************************************/

//Timer For 0.25ms

//void delay()

/*{

TMR1H  = 0xFF;

   TMR1L  = 0xFF;

T1CON  = 0x01;

while (PIR1bits.TMR1IF == 0); // timer 1 interrupt flag

   PIR1bits.TMR1IF = 0;

T1CON  = 0xC0;

}


//Timer For 1ms

void delay()

{

TMR1H  = 0xF0;

   TMR1L  = 0x60;

T1CON  = 0x01;

while (PIR1bits.TMR1IF == 0); // timer 1 interrupt flag

   PIR1bits.TMR1IF = 0;

T1CON  = 0xC0;

}*/

/***************************************/

Proteus Simulation:



^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^&^


No comments:

Post a Comment