Appendix
UPC-7210 Series
User’s Manual
67
C.
Watchdog Timer Configuration
The Watchdog Timer (WDT) is used to generate a variety of output signals after a user programmable count. The
WDT is suitable for use in the prevention of system lock-up, such as when software becomes trapped in a
deadlock. Under these sorts of circumstances, the timer will count to zero and the selected outputs will be driven.
Under normal circumstance, you will need to restart the WDT at regular intervals before the timer counts to zero.
Sample Code:
//---------------------------------------------------------------------------
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
// PURPOSE.
//
//---------------------------------------------------------------------------
#include <dos.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "F81866.H"
//---------------------------------------------------------------------------
int main (int argc, char *argv[]);
void EnableWDT(int);
void DisableWDT(void);
//---------------------------------------------------------------------------
int main (int argc, char *argv[])
{
unsigned char bBuf;
unsigned char bTime;
char **endptr;
char SIO;
printf("Fintek 81866 watch dog program\n");
SIO = Init_F81866();
if (SIO == 0)
{
printf("Can not detect Fintek 81866, program abort.\n");
return(1);
}//if (SIO == 0)
if (argc != 2)
{
printf(" Parameter incorrect!!\n");
return (1);
}
bTime = strtol (argv[1], endptr, 10);
printf("System will reset after %d seconds\n", bTime);
if (bTime)
{ EnableWDT(bTime); }
else
{ DisableWDT();
}
return 0;
}
//---------------------------------------------------------------------------
void EnableWDT(int interval)
{
unsigned char bBuf;
bBuf = Get_F81866_Reg(0x2B);
bBuf &= (~0x20);
Set_F81866_Reg(0x2B, bBuf);
//Enable WDTO
Set_F81866_LD(0x07);
//switch to logic device 7
Set_F81866_Reg(0x30, 0x01);
//enable timer
bBuf = Get_F81866_Reg(0xF5);
bBuf &= (~0x0F);
bBuf |= 0x52;
Set_F81866_Reg(0xF5, bBuf);
//count mode is second
Set_F81866_Reg(0xF6, interval);
//set timer
bBuf = Get_F81866_Reg(0xFA);
bBuf |= 0x01;
Set_F81866_Reg(0xFA, bBuf);
//enable WDTO output
bBuf = Get_F81866_Reg(0xF5);
bBuf |= 0x20;
Set_F81866_Reg(0xF5, bBuf);
//start counting
}
//---------------------------------------------------------------------------
void DisableWDT(void)