mcu_init();
while (1){
//TODO Auto-generated main function
if (!TO) {
//CLRWDT(); //clear wdt status
wdt_counter++; //if wdt reset
LED_PORT = wdt_counter;
while (1); //wait for the next wdt
}
//do something here
}
}
==============end code==========================
============code====================
#include <htc.h>
#include "gpio.h"
__CONFIG(MCLRDIS & WDTEN & BORDIS & PWRTEN & INTIO);
#define LED_PORT GPIO
#define LED_DDR TRISIO
#define LED_PINs 0xff
void mcu_init(void) {
ANSEL=0x00; //all pins digital
CMCON=0x07; //analog comparators off
PSA=1; //prescaller to wdt
// PS2=1, PS1=1, PS0=1; //prescaler to 1<<0b111. time-out period=18ms*128=2s
PS2=0, PS1=1, PS0=1; //prescaler to 1<<0b011. time-out period=18ms*8=160ms
IO_CLR(LED_PORT, LED_PINs); //led_pins low
IO_OUT(LED_DDR, LED_PINs);
}
void
main(void)
{
static unsigned char wdt_counter=0;
mcu_init();
while (1){
//TODO Auto-generated main function
if (!TO) {
//CLRWDT(); //clear wdt status
wdt_counter++; //if wdt reset
LED_PORT = wdt_counter;
while (1); //wait for the next wdt
}
//do something here
}
}
==============end code==========================
一周热门 更多>