用STC官方示例改写即可
源文件:
- /*---------------------------------------------------------------------*/
- /* --- STC MCU Limited ------------------------------------------------*/
- /* --- STC15F4K60S4 系列 INT4下降沿唤醒掉电模式举例--------------------*/
- /* --- Mobile: (86)13922805190 -------------- -------------------------*/
- /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
- /* --- Tel: 86-0513-55012928,55012929,55012966-------------------------*/
- /* --- Web: www.STCMCU.com --------------------------------------------*/
- /* --- Web: www.GXWMCU.com --------------------------------------------*/
- /* 如果要在程序中使用此代码,请在程序中注明使用了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 INT_CLKO = 0x8F; //外部中断与时钟输出控制寄存器
- sbit INT4 = P3^0; //INT4引脚定义
- sbit P10 = P1^0;
- //-----------------------------------------
- //中断服务程序
- void exint4() interrupt 16
- {
- P10 = !P10; //将测试口取反
-
- // INT_CLKO &= 0xBF; //若需要手动清除中断标志,可先关闭中断,此时系统会自动清除内部的中断标志
- // INT_CLKO |= 0x40; //然后再开中断即可
- }
- //-----------------------------------------------
- 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;
- INT_CLKO |= 0x40; //(EX4 = 1)使能INT4下降沿中断
- EA = 1;
- while (1)
- {
- PCON = 0x02; //MCU进入掉电模式
- _nop_(); //掉电模式被唤醒后,首先执行此语句,然后再进入中断服务程序
- _nop_();
- }
- }
复制代码
改后的文件
- /*---------------------------------------------------------------------*/
- /* --- STC MCU Limited ------------------------------------------------*/
- /* --- STC15F4K60S4 系列 INT4下降沿唤醒掉电模式举例--------------------*/
- /* --- Mobile: (86)13922805190 -------------- -------------------------*/
- /* --- Fax: 86-0513-55012956,55012947,55012969 ------------------------*/
- /* --- Tel: 86-0513-55012928,55012929,55012966-------------------------*/
- /* --- Web: www.STCMCU.com --------------------------------------------*/
- /* --- Web: www.GXWMCU.com --------------------------------------------*/
- /* 如果要在程序中使用此代码,请在程序中注明使用了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 INT_CLKO = 0x8F; //外部中断与时钟输出控制寄存器
- sbit INT4 = P3^0; //INT4引脚定义
- sbit P10 = P1^0;
- //-----------------------------------------------
- void Delay(int t)//1T@11.0592MHz
- {
- int i,j;
- for(i=t;i>0;i--)
- for(j=1110;j>0;j--);
- }
- 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;
- // INT_CLKO |= 0x40; //(EX4 = 1)使能INT4下降沿中断
- // EA = 1;
- while (1)
- {
- if(!INT4)
- {
- Delay(20);//延时消抖
- if(!INT4)
- {
- while(!INT4);//等待松手
- INT_CLKO |= 0x40; //(EX4 = 1)使能INT4下降沿中断
- EA = 1; //开总中断
- PCON = 0x02; //MCU进入掉电模式
- _nop_(); //掉电模式被唤醒后,首先执行此语句,然后再进入中断服务程序
- _nop_();
- }
- }
- }
- }
- //-----------------------------------------
- //中断服务程序
- void exint4() interrupt 16
- {
- // P10 = !P10; //将测试口取反
- EA = 0; //关总中断
- INT_CLKO &= 0xBF; //若需要手动清除中断标志,可先关闭中断,此时系统会自动清除内部的中断标志
- // INT_CLKO |= 0x40; //然后再开中断即可
- }
复制代码
|