#include <htc.h>
__CONFIG(0xFF36);
#define u8 unsigned char
#define u16 unsigned int
#define CLRWDT() asm("clrwdt")
void delay(u16 ms)
{
int i,j;
for(i=0;i<ms;i++)
for(j=0;j<71;j++);
}
void port_init()
{
TRISD=0x00;
PORTD=0xFF;
}
void watch_init()
{
PSA=1; //分频器给看门狗
PS2=1; //1:64,18ms*64≈1156
PS1=1;
PS0=0;
}
void main()
{
port_init();
watch_init();
PORTD=0x00;
delay(500);
PORTD=0xFF;
while(1)
{
CLRWDT();
PORTD=0xFE;
delay(200);
PORTD=0xFd;
delay(200);
PORTD=0xFb;
delay(200);
PORTD=0xF7;
delay(200);
PORTD=0xEF;
delay(200);
//CLRWDT(); //如果这句屏蔽后程序复位了,说明看门狗起作用了
PORTD=0xDF;
delay(200);
PORTD=0xBF;
delay(200);
PORTD=0x7F;
delay(200);
}
}