|
//看门狗测试程序,输出反相
#include
#include
#include
unsigned int pba; //primary base i/o address
unsigned int pba_h,pba_l;
/*
WDT_INIT for enable Watch_dog and Logical device 0A.
*/
void wdt_init()
{
outportb(0x2e,0x55); //entering the configuration state
outportb(0x2e,0x07);
outportb(0x2f,0x0a);
outportb(0x2e,0xf0);
outportb(0x2f,0x01);
//get primary base I/O address
outportb(0x2e,0x60);
pba_h = inportb(0x2f);
outportb(0x2e,0x61);
pba_l = inportb(0x2f);
pba = pba_h * 0x100 + pba_l;
outportb(0x2e,0xaa); //exiting the configuration state
}
/* REG OFFSET = 0x47
General Purpose I/O bit 6.0
Bit[0] In/Out : =1 Input, =0 Output
Bit[1] Polarity : =1 Invert, =0 No Invert
Bit[3:2] Alternate Function Select
11=WDT
10=Either Edge Triggered Interrupt Input 4 (Note 26.20)
01=LED1
00=GPIO
Bits[6:4] Reserved
Bit[7] Output Type Select
1=Open Drain
0=Push Pull
*/
void wdt_define(pin)
{
outportb(pba + 0x47,pin);
}
/*
Watch_dog count mode select.
time_out=0 Minutes
time_out=1 Seconds
*/
void wdt_mode(mode)
{
outportb(pba + 0x65,mode * 0x80);
}
/*
WDT_TIME Setting Watch-dog Timer-out value.
time=0x00 Time out Disabled.
0x01 Time out= 1 minute(second)
........
0xff Time out= 255 minute(second)
*/
void wdt_time(time)
{
outportb(pba + 0x66,time);
}
void main(void)
{
wdt_init();
wdt_define(0x0e);//如果你的复位反向需改成0c
wdt_mode(1);
wdt_time(10);
printf("\nSystem will RESET after %d seconds.",10);
} |
|