program the pic16f877a timer0 for 10sec delay


// PIC16F877A Configuration Bit Settings


// 'C' source line config statements


// CONFIG

#pragma config FOSC = HS    // Oscillator Selection bits (HS oscillator)

#pragma config WDTE = OFF    // Watchdog Timer Enable bit (WDT disabled)

#pragma config PWRTE = OFF   // Power-up Timer Enable bit (PWRT disabled)

#pragma config BOREN = OFF   // Brown-out Reset Enable bit (BOR disabled)

#pragma config LVP = OFF    // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)

#pragma config CPD = OFF    // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)

#pragma config WRT = OFF    // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)

#pragma config CP = OFF     // Flash Program Memory Code Protection bit (Code protection off)


#define _XTAL_FREQ 20000000

#include<xc.h>

void delay(int a);

void timerinterupt();

int main()

{

  TRISD=0X00;

  while(1)

  {

    PORTD=0X00;

    delay(10);

    PORTD=0XFF;

    delay(10);

  }

}

void delay(int a)  //how much time isr is to be called

{

  int i=0;

  for(i=0;i<=a-1;i++)

  {

    timerinterupt();

  }

   

}

void timerinterupt()   //for creating the perfect isr for 1sec delay calculation for 1sec

{

   OPTION_REG=0x07;

   int j=0;

 for(j=0;j<75;j++)

 {

  while(!T0IF);

  T0IF=0;

 }

   

}


要查看或添加评论,请登录

Embedded enthusiastic的更多文章

社区洞察

其他会员也浏览了