Type(1) One Second Task Program
Type(1) One Second Task Program
#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)
#include <xc.h>
#define _XTAL_FREQ 4000000
unsigned char count;
void init(void);
void main(void)
{
init();
while(1)
{
PORTC=~PORTC;
__delay_ms(1000);
}
void init()
{
TRISC=0x00;
PORTC=0x00;
TRISD=0x00;
PORTD=0x00;
INTCON |=(3<<6);
T1CON =0x01;
PIE1 |=0x01;
PIR1 &=~(1<<0);
TMR1=15535;
}
void __interrupt()_isr()
{
if(PIR1 & 0x01)
{
count++;
if (count==20)
{
PORTD=~PORTD;
count=0;
}
TMR1=15535;
PIR1 &=~(1<<0);
}