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

相关文章

线上Java OOM问题定位与解决方案超详细解析

《线上JavaOOM问题定位与解决方案超详细解析》OOM是JVM抛出的错误,表示内存分配失败,:本文主要介绍线上JavaOOM问题定位与解决方案的相关资料,文中通过代码介绍的非常详细,需要的朋... 目录一、OOM问题核心认知1.1 OOM定义与技术定位1.2 OOM常见类型及技术特征二、OOM问题定位工具

python获取指定名字的程序的文件路径的两种方法

《python获取指定名字的程序的文件路径的两种方法》本文主要介绍了python获取指定名字的程序的文件路径的两种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 最近在做项目,需要用到给定一个程序名字就可以自动获取到这个程序在Windows系统下的绝对路径,以下

Vue3绑定props默认值问题

《Vue3绑定props默认值问题》使用Vue3的defineProps配合TypeScript的interface定义props类型,并通过withDefaults设置默认值,使组件能安全访问传入的... 目录前言步骤步骤1:使用 defineProps 定义 Props步骤2:设置默认值总结前言使用T

sysmain服务可以禁用吗? 电脑sysmain服务关闭后的影响与操作指南

《sysmain服务可以禁用吗?电脑sysmain服务关闭后的影响与操作指南》在Windows系统中,SysMain服务(原名Superfetch)作为一个旨在提升系统性能的关键组件,一直备受用户关... 在使用 Windows 系统时,有时候真有点像在「开盲盒」。全新安装系统后的「默认设置」,往往并不尽编

Web服务器-Nginx-高并发问题

《Web服务器-Nginx-高并发问题》Nginx通过事件驱动、I/O多路复用和异步非阻塞技术高效处理高并发,结合动静分离和限流策略,提升性能与稳定性... 目录前言一、架构1. 原生多进程架构2. 事件驱动模型3. IO多路复用4. 异步非阻塞 I/O5. Nginx高并发配置实战二、动静分离1. 职责2

解决升级JDK报错:module java.base does not“opens java.lang.reflect“to unnamed module问题

《解决升级JDK报错:modulejava.basedoesnot“opensjava.lang.reflect“tounnamedmodule问题》SpringBoot启动错误源于Jav... 目录问题描述原因分析解决方案总结问题描述启动sprintboot时报以下错误原因分析编程异js常是由Ja

MySQL 表空却 ibd 文件过大的问题及解决方法

《MySQL表空却ibd文件过大的问题及解决方法》本文给大家介绍MySQL表空却ibd文件过大的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录一、问题背景:表空却 “吃满” 磁盘的怪事二、问题复现:一步步编程还原异常场景1. 准备测试源表与数据

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec

SysMain服务可以关吗? 解决SysMain服务导致的高CPU使用率问题

《SysMain服务可以关吗?解决SysMain服务导致的高CPU使用率问题》SysMain服务是超级预读取,该服务会记录您打开应用程序的模式,并预先将它们加载到内存中以节省时间,但它可能占用大量... 在使用电脑的过程中,CPU使用率居高不下是许多用户都遇到过的问题,其中名为SysMain的服务往往是罪魁

MySQ中出现幻读问题的解决过程

《MySQ中出现幻读问题的解决过程》文章解析MySQLInnoDB通过MVCC与间隙锁机制在可重复读隔离级别下解决幻读,确保事务一致性,同时指出性能影响及乐观锁等替代方案,帮助开发者优化数据库应用... 目录一、幻读的准确定义与核心特征幻读 vs 不可重复读二、mysql隔离级别深度解析各隔离级别的实现差异