Tuesday 20 October 2015

PIC12F675 TIMER0 1SEC




#include<pic.h>
#include<htc.h>
#define __PIC12F675_H                    //header file for ic
__CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_ON & MCLRE_OFF & BOREN_ON & CP_OFF & CPD_OFF);
#define _XLAT_FREQ 4000000             //define cpu frequency

unsigned int a;

void delay()
{
unsigned int i;
for(i=0;i<3;i++)
{

while((T0IF&(0x01))==0);
T0IF|=0x01;

}
}

void InitTimer0(void)
{
OPTION_REG &= 0x87;     // Make Prescalar 1:2

T0IE = 1; // Enable Timer0
GIE = 1; // Enable global interrupts
}


void interrupt ISR(void)
{
if(T0IF)  //If Timer0 Interrupt
{
        a++;
        if(a>=15)
        {
GP0 = ~GP0; // Toggle GP0 pin
        a=0;
        }
T0IF = 0;   // Clear the interrupt
}
}

void main()
{
ANSEL  = 0x00;       // Set ports as digital I/O, not analog input
ADCON0 = 0x00; // Shut off the A/D Converter
CMCON  = 0x07; // Shut off the Comparator
VRCON  = 0x00;     // Shut off the Voltage Reference
TRISIO = 0x08;       // GP3 input, rest all output
GPIO   = 0x00;       // Make all pins 0

InitTimer0();

while(1)
{
}
}

No comments:

Post a Comment