题目是要求数码管显示60秒,然后熄灭。然后LED从左往右循环点亮。然而我搞了好久都没搞定。。。。
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char;
#define uint unsigned int;
sbit LED = P1;
sbit we = P2^7;
sbit du = P2^6;
uchar ledflow = 0x7f;
uchar a,b,ge,shi;
unsigned char sum[]={
0x3F, //"0"
0x06, //"1"
0x5B, //"2"
0x4F, //"3"
0x66, //"4"
0x6D, //"5"
0x7D, //"6"
0x07, //"7"
0x7F, //"8"
0x6F, //"9"
0x77, //"A"
0x7C, //"B"
0x39, //"C"
0x5E, //"D"
0x79, //"E"
0x71, //"F"
0x76, //"H"
0x38, //"L"
0x37, //"n"
0x3E, //"u"
0x73, //"P"
0x5C, //"o"
0x40, //"-"
0x00, //熄灭
0x00 //自定义
}
void main()
{
void delay(uint z);
void display(uchar i);
TMOD = 0x10;
TH1 = (65536-46082)/256;
TL1 = (65536-46082)%256;
TR1 = 1;
while(1)
{
if(TF1 == 1)
{
TF1 = 0;
TH1 = (65535-11285)/256;
TL1 = (65535-11285)%256;
a=a+1;
}
if(a == 20)
{ a = 0;
display(b);
b=b+1;
}
if(b == 60)
{
we = 1;
P0 = 0xff;
we = 0; //打开位选,才能打开或关闭数码管
TR1 = 1; //关闭定时器
P1 = ledflow;
ledflow=_crol_(ledflow,1);
}
}
}
void delay(uint z)
{
uint x,y;
for(x = z; x > 0; x--)
for(y = 120; y > 0 ; y--);
}
void display(uchar i)
{
shi = i/10;
ge = i%10;
P0 = 0xff;
we = 1;
P0 = 0xfd;
we = 0;
du = 1;
P0 = sum[shi];
du = 0;
delay (1);
P0 = 0xff;
we = 1;
P0 = 0xfe;
we = 0;
du = 1;
P0 = sum[ge];
du = 0;
delay(1);
}
|