本帖最后由 思宁 于 2014-5-14 08:37 编辑
这程序,首先中断号写错!其次,你声明sbit led1=P3^0;而你下面程序却用led.还有最好加个检测释放按键的动作。你想实现的效果是按键按一次LED灯灭,在按一次按键LED灯亮吗?如果是的话
#include <reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar num;
sbit led1=P3^0;
sbit key=P3^4;
void main()
{
TMOD=0x01;
EA=1;
ET0=1;
//TR0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
while(1)
{
if(key==0)
{
TR0 = 1;
while(num<=1);
TR0 = 0;
num = 0;
if(key==0)
{
while(!key);
led1 = ~led1;
}
}
}
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
num++;
}
|