C8051关闭看门狗汇编语言,请教关于C8051F单片机看门狗程序问题

本文主要是介绍C8051关闭看门狗汇编语言,请教关于C8051F单片机看门狗程序问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

看门狗程序,网上找了一个,看不懂,也不知道哪句有用,求大神帮忙分析,小弟不胜感激!

//-----------------------------------------------------------------------------

// F41x_Watchdog.c

//-----------------------------------------------------------------------------

// Copyright 2006 Silicon Laboratories, Inc.

// http://www.silabs.com

//

// Program Description:

//

// This program helps the user to learn about operating the Watch Dog Timer.

// The WDT is used to generate resets if the times between writes to the WDT

// update register (PCA0CPH5) exceed a specified limit. The WDT can be disabLED

// and enabled in the software as needed. When enabled the PCA Module 5 acts as

// the WDT. This program resets the MCU when P1.4 switch is pressed for 3

// seconds.  Also upon reset the LED blinks approximately five times faster

// when compared to before. The reset is caused due to a WDT oveRFlow and can

// be confirmed by checking the value of the RSTSRC register where bit 3 is

// set to indicate a reset caused by WDT.

//

// How to Test:

// 1) Compile and download code to a 'F410 device

// 2) Place shorting blocks on P2.1/D3 and P1.4/SW2 pin pairs on jumper J5.

// 3) Run the code:

//        - The test will blink the LED at a rate of 8Hz until the switch SW2

//          (P0.7) is pressed for at least 3 secs.

//        - Once the the switch is pressed and held for a long enough time,

//          it will prevent the WDT from being touched and the WDT will

//          cause a reset.

//        - Upon reset the code checks for a WDT reset and blinks the LED five

//          times faster than before to indicate the same.

//

//

// FID:            41X000031

// Target:         c8051f410

// Tool chain:     Keil C51 7.50 / Keil EVAL C51

// Command Line:   None

//

// Release 1.0

//    -Initial Revision SM

//    -20 JULY 2006

//-----------------------------------------------------------------------------

// Includes

//-----------------------------------------------------------------------------

#include                  // SFR declarations

//-----------------------------------------------------------------------------

// 16-bit SFR Definitions for 'F41x

//-----------------------------------------------------------------------------

sfr16 TMR2RL   = 0xca;                 // Timer2 reload value

sfr16 TMR2     = 0xcc;                 // Timer2 counter

//-----------------------------------------------------------------------------

// Global CONSTANTS

//-----------------------------------------------------------------------------

#define SYSCLK       24500000 / 8      // SYSCLK frequency in Hz

sbit LED = P2^1;                       // LED='1' means ON

sbit SW2 = P1^4;                       // SW2='0' means switch pressed

//-----------------------------------------------------------------------------

// Function PROTOTYPES

//-----------------------------------------------------------------------------

void OSCILLATOR_Init (void);

void PORT_Init (void);

void PCA_Init (void);

void Timer2_Init (int counts);

void Timer2_ISR (void);

//-----------------------------------------------------------------------------

// main() Routine

//-----------------------------------------------------------------------------

//

// The MAIN routine performs all the intialization, and then loops until the

// switch is pressed. When SW2 (P1.4) is pressed the code checks the RSTSRC

// register to make sure if the last reset is because of WDT.

//-----------------------------------------------------------------------------

void main (void)

{

PCA0MD &= ~0x40;                    // WDTE = 0 (clear watchdog timer

// enable)

OSCILLATOR_Init ();                 // Initialize system clock to 24.5/8 MHz

PCA_Init();                         // Intialize the PCA

PORT_Init();                        // Initialize crossbar and GPIO

if ((RSTSRC & 0x02) == 0x00)        // First check the PORSF bit. if PORSF

{                                   // is set, all other RSTSRC flags are

// invalid

// Check if the last reset was due to the Watch Dog Timer

if (RSTSRC == 0x08)

{

// Make LED blink at 12Hz

Timer2_Init (SYSCLK / 12 / 6);

// Enable global interrupts

EA = 1;

while(1);                   // wait forever

}

else

{

// Init Timer2 to generate interrupts at a 4Hz rate.

Timer2_Init (SYSCLK / 12 / 4);

}

}

// Calculate Watchdog Timer Timeout

// Offset calculated in PCA clocks

// Offset = ( 256 x PCA0CPL5 ) + 256 - PCA0L

//        = ( 256 x 255(0xFF)) + 256 - 0

// Time   = Offset * (12/SYSCLK)

//        = ~255 ms ( PCA uses SYSCLK/12 as its clock source)

PCA0MD  &= ~0x40;                   // WDTE = 0 (clear watchdog timer

// enable)

PCA0L    = 0x00;                    // Set lower byte of PCA counter to 0

PCA0H    = 0x00;                    // Set higher byte of PCA counter to 0

PCA0CPL5 = 0xFF;                    // Write offset for the WDT

PCA0MD  |= 0x40;                    // Enable the WDT

EA = 1;                             // Enable global interrupts

//--------------------------------------------------------------------------

// Main Application Loop/Task Scheduler

//--------------------------------------------------------------------------

while (1)

{

//----------------------------------------------------------------------

// Task #1 - Check Port I/O

//----------------------------------------------------------------------

while(!SW2);                     // Force the MCU to stay in this task as

// long as SW2 is pressed. This task

// must finish before the watchdog timer

// timeout expires.

//-----------------------------------------------------------------------

// Task #2 - Reset Watchdog Timer

//-----------------------------------------------------------------------

PCA0CPH5 = 0x00;                 // Write a 'dummy' value to the PCA0CPH5

// register to reset the watchdog timer

// timeout. If a delay longer than the

// watchdog timer delay occurs between

// successive writes to this register,

// the device will be reset by the watch

// dog timer.

}

}

//-----------------------------------------------------------------------------

// Initialization Subroutines

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------

// OSCILLATOR_Init

//-----------------------------------------------------------------------------

// Return Value : None

// Parameters   : None

// This routine initializes the system clock to use the internal 24.5MHz / 8

// oscillator as its clock source.  Also enables missing clock detector reset.

//-----------------------------------------------------------------------------

void OSCILLATOR_Init (void)

{

OSCICN = 0x84;                      // Configure internal oscillator

RSTSRC = 0x04;                      // Enable missing clock detector

}

//-----------------------------------------------------------------------------

// PCA_Init

//-----------------------------------------------------------------------------

// Return Value : None

// Parameters   : None

// This routine initializes the PCA to use the SYSCLK / 12

// as its clock source.  It also sets the offset value by writing to PCA0CPL2.

//-----------------------------------------------------------------------------

void PCA_Init()

{

PCA0CN     =  0x40;                        // PCA counter enable

PCA0MD    &= ~0x40 ;                       // Watchdog timer disabled-clearing bit 6

PCA0MD    &=  0xF1;                        // Timebase selected - System clock / 12

PCA0CPL5   =  0xFF;                        // Offset value

}

//-----------------------------------------------------------------------------

// PORT_Init

//-----------------------------------------------------------------------------

// Return Value : None

// Parameters   : None

//

// This function configures the Crossbar and GPIO ports.

// P2.1   digital   push-pull     LED

//-----------------------------------------------------------------------------

void PORT_Init (void)

{

XBR0     = 0x00;                    // No digital peripherals selected

XBR1     = 0x40;                    // Enable crossbar and weak pull-ups

P2MDOUT |= 0x02;                    // Enable LED as a push-pull output

}

//-----------------------------------------------------------------------------

// Timer2_Init

//-----------------------------------------------------------------------------

// Return Value : None

// Parameters   :

//   1)  int counts - calculated Timer overflow rate

//                    range is positive range of integer: 0 to 32767

//

// Configure Timer2 to 16-bit auto-reload and generate an interrupt at

// interval specified by using SYSCLK/48 as its time base.

//-----------------------------------------------------------------------------

void Timer2_Init (int counts)

{

TMR2CN  = 0x00;                     // Stop Timer2; Clear TF2;

// use SYSCLK/12 as timebase

CKCON   = 0x30;                     // Timer2 clocked based on SYSCLK

TMR2RL  = -counts;                  // Init reload values

TMR2    = 0xffff;                   // Set to reload immediately

ET2     = 1;                        // Enable Timer2 interrupts

TR2     = 1;                        // Start Timer2

}

//-----------------------------------------------------------------------------

// Interrupt Service Routines

//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------

// Timer2_ISR

//-----------------------------------------------------------------------------

// This routine changes the state of the LED whenever Timer2 overflows.

//-----------------------------------------------------------------------------

void Timer2_ISR (void) interrupt 5

{

TF2H = 0;                           // Clear Timer2 interrupt flag

LED = ~LED;                         // Change state of LED

}

//-----------------------------------------------------------------------------

// End Of File

//-----------------------------------------------------------------------------

699ba7046c51816a17b33a7caa85f179.png

1

97b4b3417991aabde46fdac613e34292.png

已退回1积分

这篇关于C8051关闭看门狗汇编语言,请教关于C8051F单片机看门狗程序问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/546375

相关文章

Nginx启动失败:端口80被占用问题的解决方案

《Nginx启动失败:端口80被占用问题的解决方案》在Linux服务器上部署Nginx时,可能会遇到Nginx启动失败的情况,尤其是错误提示bind()to0.0.0.0:80failed,这种问题通... 目录引言问题描述问题分析解决方案1. 检查占用端口 80 的进程使用 netstat 命令使用 ss

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了

pip install jupyterlab失败的原因问题及探索

《pipinstalljupyterlab失败的原因问题及探索》在学习Yolo模型时,尝试安装JupyterLab但遇到错误,错误提示缺少Rust和Cargo编译环境,因为pywinpty包需要它... 目录背景问题解决方案总结背景最近在学习Yolo模型,然后其中要下载jupyter(有点LSVmu像一个

解决jupyterLab打开后出现Config option `template_path`not recognized by `ExporterCollapsibleHeadings`问题

《解决jupyterLab打开后出现Configoption`template_path`notrecognizedby`ExporterCollapsibleHeadings`问题》在Ju... 目录jupyterLab打开后出现“templandroidate_path”相关问题这是 tensorflo

如何解决Pycharm编辑内容时有光标的问题

《如何解决Pycharm编辑内容时有光标的问题》文章介绍了如何在PyCharm中配置VimEmulator插件,包括检查插件是否已安装、下载插件以及安装IdeaVim插件的步骤... 目录Pycharm编辑内容时有光标1.如果Vim Emulator前面有对勾2.www.chinasem.cn如果tools工

最长公共子序列问题的深度分析与Java实现方式

《最长公共子序列问题的深度分析与Java实现方式》本文详细介绍了最长公共子序列(LCS)问题,包括其概念、暴力解法、动态规划解法,并提供了Java代码实现,暴力解法虽然简单,但在大数据处理中效率较低,... 目录最长公共子序列问题概述问题理解与示例分析暴力解法思路与示例代码动态规划解法DP 表的构建与意义动

Java多线程父线程向子线程传值问题及解决

《Java多线程父线程向子线程传值问题及解决》文章总结了5种解决父子之间数据传递困扰的解决方案,包括ThreadLocal+TaskDecorator、UserUtils、CustomTaskDeco... 目录1 背景2 ThreadLocal+TaskDecorator3 RequestContextH

在不同系统间迁移Python程序的方法与教程

《在不同系统间迁移Python程序的方法与教程》本文介绍了几种将Windows上编写的Python程序迁移到Linux服务器上的方法,包括使用虚拟环境和依赖冻结、容器化技术(如Docker)、使用An... 目录使用虚拟环境和依赖冻结1. 创建虚拟环境2. 冻结依赖使用容器化技术(如 docker)1. 创