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单片机看门狗程序问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:https://blog.csdn.net/weixin_39611331/article/details/117166825
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/546375

相关文章

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

nginx中端口无权限的问题解决

《nginx中端口无权限的问题解决》当Nginx日志报错bind()to80failed(13:Permissiondenied)时,这通常是由于权限不足导致Nginx无法绑定到80端口,下面就来... 目录一、问题原因分析二、解决方案1. 以 root 权限运行 Nginx(不推荐)2. 为 Nginx

解决1093 - You can‘t specify target table报错问题及原因分析

《解决1093-Youcan‘tspecifytargettable报错问题及原因分析》MySQL1093错误因UPDATE/DELETE语句的FROM子句直接引用目标表或嵌套子查询导致,... 目录报js错原因分析具体原因解决办法方法一:使用临时表方法二:使用JOIN方法三:使用EXISTS示例总结报错原

Windows环境下解决Matplotlib中文字体显示问题的详细教程

《Windows环境下解决Matplotlib中文字体显示问题的详细教程》本文详细介绍了在Windows下解决Matplotlib中文显示问题的方法,包括安装字体、更新缓存、配置文件设置及编码調整,并... 目录引言问题分析解决方案详解1. 检查系统已安装字体2. 手动添加中文字体(以SimHei为例)步骤

SpringSecurity整合redission序列化问题小结(最新整理)

《SpringSecurity整合redission序列化问题小结(最新整理)》文章详解SpringSecurity整合Redisson时的序列化问题,指出需排除官方Jackson依赖,通过自定义反序... 目录1. 前言2. Redission配置2.1 RedissonProperties2.2 Red

nginx 负载均衡配置及如何解决重复登录问题

《nginx负载均衡配置及如何解决重复登录问题》文章详解Nginx源码安装与Docker部署,介绍四层/七层代理区别及负载均衡策略,通过ip_hash解决重复登录问题,对nginx负载均衡配置及如何... 目录一:源码安装:1.配置编译参数2.编译3.编译安装 二,四层代理和七层代理区别1.二者混合使用举例

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

怎样通过分析GC日志来定位Java进程的内存问题

《怎样通过分析GC日志来定位Java进程的内存问题》:本文主要介绍怎样通过分析GC日志来定位Java进程的内存问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、GC 日志基础配置1. 启用详细 GC 日志2. 不同收集器的日志格式二、关键指标与分析维度1.

Java 线程安全与 volatile与单例模式问题及解决方案

《Java线程安全与volatile与单例模式问题及解决方案》文章主要讲解线程安全问题的五个成因(调度随机、变量修改、非原子操作、内存可见性、指令重排序)及解决方案,强调使用volatile关键字... 目录什么是线程安全线程安全问题的产生与解决方案线程的调度是随机的多个线程对同一个变量进行修改线程的修改操