看看我编的程序对不对。对应的电路如图。
#include<reg51.h>
#define smg P0
sbit a=P2^2;
sbit b=P2^3;
sbit c=P2^4;
unsigned char code xs[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,
0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char i=0,t=0;
unsigned int j=0;
void Delay(unsigned char c);
void play(void);
void TimeConfig();
void main(void)
{
TimeConfig();
t=10;
smg=0x00;
while(1)
{
if (i>=10)
{
j++;
}
if (j==9999)
{
j=0;
}
play();
}
}
void play(void)
{
c=1;b=0;a=0;
smg=xs[j/1000];
Delay(t);
smg=0x00;
Delay(t);
c=0;b=1;a=1;
smg=xs[(j%1000)/100];
Delay(t);
smg=0x00;
Delay(t);
c=0;b=1;a=0;
smg=xs[(j%100)/10];
Delay(t);
smg=0x00;
Delay(t);
c=0;b=0;a=1;
smg=xs[(j%10)/1];
Delay(t);
smg=0x00;
Delay(t);
}
void Delay(unsigned char c)
{
unsigned char b;
for(c;c>0;c--)
for(b=10;b>0;b--);
}
void TimeConfig()
{
TMOD = 0x01;
TH0 = 0x3c; //设置初始值,定时50ms
TL0 = 0xb0;
EA = 1; //总中断开启
ET0 = 1; //定时器0中断开启
TR0 = 1; //启动定时器0
}
void Time0() interrupt 1//定时器0中断服务函数
{
TH0 = 0x3c; //重装初值
TL0 = 0xb0;
i++;
}
|