1.当出现物理情况比如单片机不小心摔了会发生灯亮的情况,所以我们得增加个延迟函数
2.这个错误是缺少头文件#include <intrins.h>
3.
#include "reg52.h"
#include <intrins.h>
sbit key2 = P2^0;
sbit key1 = P2^1;
sbit ledone = P3^7;
void Delay50ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 3;
j = 26;
k = 223;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void main()
{
while(1)
{
if(key1 == 0)
{
Delay50ms();
if(key1 == 0){
ledone = 0;
}
}
else if(key2 ==0)
{
ledone = 1;
}
}
}