编了一个1秒内LED1闪10次的程序(12MHZ,STC89C52),编译OK,但在实验板上运行失败,网友也帮忙写了个程序,结果也是失败。现在将此程序贴上来,请大家来一起来帮帮忙,指教指教,探讨探讨
题目要求:1秒内LED1闪10次后停止(或是说灯在1秒之内只闪10次)
我写的:
程序分析:闪10次即亮10次灭10次,共20次,1S/20=50MS每次。
#include<reg52.h>
#define uchar unsigned char
sbit P1_4=P1^4;
sbit LED1=P0^0;
uchar a;
void main()
{
P1_4=0;
a=0;
TMOD=0X01;
TH0=0X3C;
TL0=0Xb0;
EA=1;
ET0=1;
TR0=1;
while(1);
}
void time0() interrupt 1
{
TH0=0X3c;
HL0=0Xb0;
a++;
if(a==1)
{
a=0;
LED1=~LED1;
}
if(a==20)
{
TR0=0;
}
}
当以上程序运行失败之后,我在if(a==1)之前加了个while(1)将两个if都放在了{ }中,但结果仍然达不到题目要求:1秒钟之内LED1闪烁10次后停止。
网友的程序:
#include<reg52.h>
#define uchar unsigned char
sbit P1_4=P1^4;
sbit LED1=P0^0;
uchar a,b;
void main()
{
P1_4=0;
a=0;
b=0;
TMOD=0X01;
TH0=0X3C;
TL0=0Xb0;
EA=1;
ET0=1;
TR0=1;
while(1);
}
void time0() interrupt 1
{
TH0=0X3c;
HL0=0Xb0;
a++;
if(a==1)
{
a=0;
}
for(b=0;b<=10;b++)
{
LED1=~LED1;
}
}
以上是网友的程序,大概是这样吧,因为他给我的资料没带在身边 编译OK,实验板上得不到题目要求的结果。
[此贴子已经被作者于2010-10-12 18:56:49编辑过]
|