freetech

kinetis入门之——看门狗

0
阅读(4294)

kinetis内置看门狗,当程序长时间不喂狗时,程序复位执行。下面做一个例子,详述具体步骤:

1、点“文件->新建->bareboard project”出现下面对话框:

image

为工程起个名字(该示例为k10_wd_pe),点“下一步”,出现:

clip_image003

选择你所用的芯片型号(这里是“PK10X256”)即可。点“下一步”,出现:

clip_image005

“Connetion to be used”中先选我们先前建好的“USBDM K10X256”,点“下一步”,一直点“下一步”直到出现:

clip_image007

选“Processor Export”,点“下一步”,出现:

clip_image009

选实际用到的芯片(我用的是144-pins LQFP),点“完成”,出现:

image 

等待上面对话框消失,一个工程就建好了。

双击“Timer”下的“WatchDog_LDD”添加一个“WatchDog Bean”,如下图:

image

配置如下图:

image

Methods”里

clip_image017

点“项目”->“Generate Processor Export Code”如下图:

image 

下面是“ProcessorExpert.c”的“main()”函数代码:

/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "Events.h"
#include "WDog1.h"
/* Including shared modules, which are used for whole project */
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"

/* User includes (#include below this line is not maintained by Processor Expert) */
LDD_TDeviceData *MyWDog1Ptr;
LDD_TError Error;

void main(void)
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  /* For example: for(;;) { } */
  MyWDog1Ptr = WDog1_Init(
          (LDD_TUserData *)NULL
          );
  while(1)
  {
      /* User actions, no longer than 2 seconds */
      Error = WDog1_Clear(MyWDog1Ptr);                 /* Clear watchdog timer */
  }
  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END ProcessorExpert */