- /*---------------------------------------------------------------------*/
- /* --- STC MCU Limited ------------------------------------------------*/
- /* --- STC15F4K60S4 系列 掉电唤醒定时器举例----------------------------*/
- /* 如果要在程序中使用此代码,请在程序中注明使用了STC的资料及程序 */
- /* 如果要在文章中应用此代码,请在文章中注明使用了STC的资料及程序 */
- /*---------------------------------------------------------------------*/
- //本示例在Keil开发环境下请选择Intel的8058芯片型号进行编译
- //若无特别说明,工作频率一般为11.0592MHz
- #include "reg51.h"
- #include "intrins.h"
- //-----------------------------------------------
- sfr P0M1 = 0x93;
- sfr P0M0 = 0x94;
- sfr P1M1 = 0x91;
- sfr P1M0 = 0x92;
- sfr P2M1 = 0x95;
- sfr P2M0 = 0x96;
- sfr P3M1 = 0xb1;
- sfr P3M0 = 0xb2;
- sfr P4M1 = 0xb3;
- sfr P4M0 = 0xb4;
- sfr P5M1 = 0xC9;
- sfr P5M0 = 0xCA;
- sfr P6M1 = 0xCB;
- sfr P6M0 = 0xCC;
- sfr P7M1 = 0xE1;
- sfr P7M0 = 0xE2;
- sfr WKTCL = 0xaa; //掉电唤醒定时器计时低字节
- sfr WKTCH = 0xab; //掉电唤醒定时器计时高字节
- sbit P10 = P1^0;
- sbit P11 = P1^1;
- char count=0;
- //-----------------------------------------------
- void main()
- {
- P0M0 = 0x00;
- P0M1 = 0x00;
- P1M0 = 0x00;
- P1M1 = 0x00;
- P2M0 = 0x00;
- P2M1 = 0x00;
- P3M0 = 0x00;
- P3M1 = 0x00;
- P4M0 = 0x00;
- P4M1 = 0x00;
- P5M0 = 0x00;
- P5M1 = 0x00;
- P6M0 = 0x00;
- P6M1 = 0x00;
- P7M0 = 0x00;
- P7M1 = 0x00;
- WKTCL = 255; //设置唤醒周期为488us*(30719+1) = 15s
- WKTCH = 0xF7; //使能掉电唤醒定时器
-
- while (1)
- {
- PCON = 0x02; //进入掉电模式
- _nop_(); //掉电模式被唤醒后,直接从此语句开始向下执行,不进入中断服务程序
- _nop_();
- count++;
- if(count >=4)
- {
- P11 = !P11; // 每隔一分钟 取反测试口
- count=0;
- }
- P10 = !P10; //掉电唤醒后,取反测试口
- }
- }
复制代码 |