本帖最后由 yangmm11 于 2014-11-20 10:19 编辑
在Timer例程中,程序如下:
* This is an example of the usage of WDTIM functions for 5509.
\*----------------------------------------------------------------------*/
#include <csl.h>
#include <csl_wdtim.h>
#include <stdio.h>
int i, pscVal;
WDTIM_Config getConfig;
WDTIM_Config myConfig = {
0x1000, /* WDPRD */
0x0000, /* WDTCR */
0x1000 /* WDTCR2 */
};
main()
{
CSL_init();
#if (_WDTIM_SUPPORT)
WDTIM_config(&myConfig);
WDTIM_FSET(WDTCR, WDOUT, 1); /* Connect to NMI */
WDTIM_FSET(WDTCR, TDDR, 0xF); /* Value to load PSC field */
WDTIM_FSET(WDTCR2, PREMD, 0); /* Set direct mode */
WDTIM_service(); /* enable watchdog */
for (;;)
{
WDTIM_getConfig(&getConfig);
pscVal = WDTIM_FGET(WDTCR,PSC);
printf("pscVal: %x, wdtcr: %x\n",
pscVal, getConfig.wdtcr);
/* write periodically to WDTIMER - when this line is commented out,
the watchdog times out, WDFLAG set to 1, indicating
that a Watchdog time-out occurred.*/
WDTIM_service();
} //end for loop
#endif
}
程序运行完之后,单步执行输出结果为:
pscVal: c, wdtcr: 134f
pscVal: 4, wdtcr: 114f
pscVal: 8, wdtcr: 124f
pscVal: c, wdtcr: 134f
。。。。。。
1、手册中PSC代表的是wdtcr中的9~6位,但是上述结果,pscVal的值也不是wdtcr中的9~6位的值啊,这是为什么?
其中,当wdtcr=134f时,9~6位值为1101=13;
当wdtcr=114f时,9~6位值为0101=3;
当wdtcr=124f时,9~6位值为1001=9;
2、在程序 WDTIM_getConfig(&getConfig); pscVal = WDTIM_FGET(WDTCR,PSC);
下面如加入 WDTIM_getConfig(&getConfig);
得到寄存器wdtcr中的值会变化,这是为什么?
|