📄 f_8_11_reset.c
字号:
#include "config.h"#include "serial.c"// tests power-on reset bits, watchdog timer, and persistent variables char getch (void);
void putch (char c);// return 8 bit char from Recieve port char getch (void){ unsigned char c; while (!RCIF); // check RCIF bit c = RCREG; return(c);}// send 8 bit char to Recieve port void putch (char c){ // wait until transmit reg empty while (!TXIF); // check TXIF bit TXREG = c;} void pcrlf (void){ putch(0x0a); putch(0x0d);}// 'persisent' prevents reset_cnt from being cleared on reset// however, reset_cnt is still stored in register bank, so is volatile// For persistent variables, CANNOT assume any initial values!
#if defined(HI_TECH_C)persistent char reset_cnt;
#endif
#if defined(__18CXX)
//MCC18 initialization controlled by startup code that is linked
// in - either init all memory zero, just do explicit initializations,
// or do no initialization at all. This project uses
// the startup code that only does explicit initialization, so
// the variable below is not initialized, cannot assume an initial value
char reset_cnt;
#endif
void main(void){ int i; char c; serial_init(95,1); // 19200 in HSPLL mode, crystal = 7.3728 MHz pcrlf(); // this subroutine prints a newline to the terminal if (POR == 0){ // bit 2 in RCON register, cleared to 0 on power-up reset printf("Power-on reset has occurred."); pcrlf(); POR = 1; // setting to bit to 1 means that will remain a '1' for other reset types reset_cnt = 0; } if (TO == 0) { SWDTEN = 0; // disable watchdog timer printf("Watchdog timer reset has occurred.\n"); pcrlf(); } i = reset_cnt; printf("Reset cnt is: %d",i); pcrlf(); reset_cnt++; while(1) { printf("'1' to enable watchdog timer"); pcrlf(); printf("'2' for sleep mode"); pcrlf(); printf("'3' for both watchdog timer and sleep mode"); pcrlf(); printf("Anything else does nothing, enter keypress: "); c = getch(); putch(c); pcrlf(); if (c == '1') SWDTEN = 1; // enable watchdog timer else if (c == '2') { // use SLEEP() instead of asm("sleep") for portability // between HI-TECH and MCC Compilers SLEEP(); } else if (c == '3') { SWDTEN = 1; // enable watchdog timer SLEEP(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -