#include "reg51.h"
#include "intrins.h"
typedef unsigned int uint16;
sfr P3M1 = 0x93;
sfr P3M0 = 0x94;
sfr AUXR = 0x8e;
sbit MCU_ONKEY_L=P3^4;
sbit MCU_RUN_LED=P3^3;
sbit RESET=P3^5;
sbit TK1_TEST=P3^2;
uint16 flag=0;
uint16 low_power=0;
//ƵÂÊ11.0592MHz
void Delay10ms() //@11.0592MHz
{
unsigned char i, j;
_nop_();
_nop_();
i = 108;
j = 144;
do
{
while (--j);
} while (--i);
}
void Timer0Init(void) //10ms@11.0592MHz
{
AUXR &= 0x7F; //?????12T??
TMOD &= 0xF0; //???????
TL0 = 0x00; //??????
TH0 = 0xDC; //??????
TF0 = 0; //??TF0??
// TR0 = 1; //???0????
flag++;
if(flag==200)
{
flag=0;
}
}
void exint0() interrupt 0 //中断路口
{
TR0 = 1; //ʹÄܶ¨Ê±Æ÷
low_power++;
}
void init()
{
P3M0 = 0x00;//³õʼ»¯IO¿Ú
P3M1 = 0x00;
MCU_ONKEY_L=0;
MCU_RUN_LED=1;
RESET=0;
INT0 = 1;
IT0 = 0; //ÉèÖÃÖжÏÀàÐÍ
EX0 = 1; //ʹÄÜÖжÏ
EA = 1;
}
void main(void)
{
Delay10ms();
Timer0Init();
init();
MCU_ONKEY_L=1;//Éϵç¸ø10msµÄ¸ß
Delay10ms();
MCU_ONKEY_L=0;
while(1)
{
if(low_power==2)//检测2个低电平
{
TR0 = 0;
low_power=1;
if(flag<100)
{
MCU_RUN_LED=0;//³ÌÐòÕý³£
flag=0;
RESET=0;
}
if(flag>100)
{
MCU_RUN_LED=1;
RESET=1;//重启
}
}
}
} |