您的位置 首页 资料

LM3S9B96 的看门狗定时器

看门狗定时器是为了防止程序跑飞而设计的,当到达设置的定时时间,程序还没有喂狗(重新设置定时初值),程序就会被强制复位。ls3s9b96的看…

看门狗守时器是为了避免程序跑飞而规划的,当抵达设置的守时时刻,程序还没有喂狗(从头设置守时初值),程序就会被强制复位。

ls3s9b96的看门狗守时器,不用在程序中手动喂狗,在API函数中现已完成了这项作业。
下面是watchdog装备的比如

#include “inc/lm3s9b96.h”
#include “inc/hw_memmap.h”
#include “inc/hw_types.h”
#include “inc/hw_ints.h”
#include “driverlib/interrupt.h”
#include “driverlib/gpio.h”
#include “driverlib/watchdog.h”
#include “driverlib/timer.h”
#include “driverlib/sysctl.h”

/* 用于调试 PF1 <-> LED —————————————————–*/
#define LED_PERIPH SYSCTL_PERIPH_GPIOF
#define LED_PORT GPIO_PORTF_BASE
#define LED_PIN GPIO_PIN_1
#define LED_OFF 1 << 1
#define LED_ON ~(1 << 1) // 低电平点亮LED
//*****************************************************************************
//
// 延时函数
//
//*****************************************************************************
void Delay(volatile signed long nCount)
{
for(; nCount != 0; nCount–);
}

//*****************************************************************************
//
// LED初始化函数,用于调试timer, watchdog等
//
//*****************************************************************************
void LED_Init(void)
{
// 使能LED地点的GPIO端口
SysCtlPeripheralEnable(LED_PERIPH);

// 设置LED地点管脚为输出
GPIOPinTypeGPIOOutput(LED_PORT, LED_PIN);

// 平息LED(默许LED是点亮的,低电平点亮LED)
GPIOPinWrite(LED_PORT, LED_PIN, LED_OFF);
}

//*****************************************************************************
//
// 看门狗初始化函数
//
//*****************************************************************************
void Watchdog_Init(void)
{
// 使能看门狗
SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);

// 使能看门狗中止
IntEnable(INT_WATCHDOG);

// 设置看门狗守时器重载值(8000000个体系时钟周期)
WatchdogReloadSet(WATCHDOG0_BASE, SysCtlClockGet() / 2);

WATCHDOG0_TEST_R = 0x100;

// 使能看门狗复位输出
WatchdogResetEnable(WATCHDOG0_BASE);

// 看门狗中止使能
WatchdogEnable(WATCHDOG0_BASE);
}

//*****************************************************************************
//
// 主函数
//
//*****************************************************************************
int main(void)
{
// Set the clocking to run directly from the crystal.
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

LED_Init();
Watchdog_Init();
IntMasterEnable(); // 开总中止

while (1)
{
}
}

//*****************************************************************************
//
// This feeds the dog and winks the LED
//
//*****************************************************************************
void WatchdogIntHandler(void)
{
// 铲除看门狗守时中止
WatchdogIntClear(WATCHDOG0_BASE);

// 置反LED灯状况
GPIOPinWrite(LED_PORT, LED_PIN, (GPIOPinRead(LED_PORT, LED_PIN) ^ LED_PIN));
}

依照前面讲的中止映射表的装备,将startup_ewarm.c文件中增加两处代码。编译、运转即可。

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/275154.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部