用8位的数码管显示秒数
本人刚入门的菜鸟
向求助大神!!!
程序:
#include "reg52.h"
#define uchar unsigned char
#define ulong unsigned long
#define uint unsigned int
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
uchar code SmgDuan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
uchar SmgWei[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uchar cnt=0;
uchar i=0;
ulong flag1s=0;
void Delay_50us()
{
uchar a,b;
for(b=1;b>0;b--)
for(a=22;a>0;a--);
}
void main()
{
ulong sec=0;
EA=1;
TMOD=0x01;
TH0=0xFC;
TL0=0x18;
ET0=1;
TR0=1;
while(1)
{
if(flag1s==1)
{
flag1s=0;
sec++;
SmgWei[0]=SmgDuan[sec%10];
SmgWei[1]=SmgDuan[sec/10%10];
SmgWei[2]=SmgDuan[sec/100%10];
SmgWei[3]=SmgDuan[sec/1000%10];
SmgWei[4]=SmgDuan[sec/10000%10];
SmgWei[5]=SmgDuan[sec/100000%10];
SmgWei[6]=SmgDuan[sec/1000000%10];
SmgWei[7]=SmgDuan[sec/10000000%10];
}
}
}
void Interrupt
time0() interrupt 1
{
TH0=0xFC;
TL0=0x18;
cnt++;
if(cnt>=1000)
{
cnt=0;
flag1s=1;
}
P0=0xFF;//ÏûÒþ
switch(i)
{
case 0:LSA=0;LSB=0;LSC=0;i++;P0=SmgWei[0];break;
case 1:LSA=1;LSB=0;LSC=0;i++;P0=SmgWei[1];break;
case 2:LSA=0;LSB=1;LSC=0;i++;P0=SmgWei[2];break;
case 3:LSA=1;LSB=1;LSC=0;i++;P0=SmgWei[3];break;
case 4:LSA=0;LSB=0;LSC=1;i++;P0=SmgWei[4];break;
case 5:LSA=1;LSB=0;LSC=1;i++;P0=SmgWei[5];break;
case 6:LSA=0;LSB=1;LSC=1;i++;P0=SmgWei[6];break;
case 7:LSA=1;LSB=1;LSC=1;i=0;P0=SmgWei[7];break;
default:break;
}
}
用的开发板 8位共阴极数码管 PO控制断 38译码器控制位 我连线应该是对的
一周热门 更多>