题主刚刚休学两年回来读大三,有点笨基础也薄弱,学校布置了一个带救护车的交通灯实验,自己又刚刚学习了数组和计时器,想先至少把无中断的信号灯制作出来,学校为了学生方便计算规定的晶振是6MHz,这里是我自己设想的交通灯代码,采用的是C语言,想法是通过计时器(比较偷懒的)控制灯的切换,延时就直接用数组里后续时刻相同的亮灯代替了,但是程序做出来之后,导入进proteus做仿真,灯居然是全亮的,令我想不明白。我认为应当是我自学的时候遗漏了关键的51电路知识,但又不知从何找起,还请各路大神帮我看看到底是我编程问题还是我画的电路出了大毛病,谢过各位大神了!
单片机源程序如下:
#include<reg52.h>
unsigned char code Ledchar[]={
0x81,0x81,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,
0x01,0x01,0x41,0x41,0x01,0x01,0x41,0x41,0x01,0x01,0x41,0x41,0x01,0x01,0x41,0x41,
0x01,0x01,0x41,0x41,0x81,0x81,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x84,
0x80,0x80,0x82,0x82,0x80,0x80,0x82,0x82,0x80,0x80,0x82,0x82,0x80,0x80,0x82,0x82,
0x80,0x80,0x82,0x82};
void mian()
{
unsigned char cnt = 0;
unsigned char sec = 0;
TMOD = 0x01;
TH0 = 0x3C;
TL0 = 0xB0;
TR0 = 1;
ET0 = 1;
EA = 1;
while(1)
{
if(TF0 == 1)
{
TF0 = 0;
TH0 = 0x3C;
TL0 = 0xB0;
cnt++;P0 = Ledchar[sec];
if(cnt>=10)
{
cnt = 0;
sec++;
if(sec>=64)
{
sec = 0;
}
}
}
}
}
简化后单独的交通灯
|