我在做毕业设计,题目数显装置系统设计。基于AT89C51的,LED数码管显示。大家有相关资料帮忙回一个。谢谢!
谢谢了 帮忙一下!
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar temp,a,b,c,d,e,bai,shi,ge,flag,flag1;
uint shu;
sbit H1=P2^0;
sbit H2=P2^1;
sbit H3=P2^2;
sbit H4=P2^3;
sbit H5=P2^4;
sbit H6=P2^5;
void init() ;
void display(uchar c,uchar d,uchar e,uchar bai,uchar shi,uchar ge);
uchar code table[]={0xc0,0xf9,0xa4,0xb0
,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x89,0x86,0xc7,0xc0,0};
void delay(uint z);
void main()
{
init();
while(1)
{
if(flag1!=1)
display(7,6,5,bai,shi,ge);
else
display(16,17,18,18,19,20);
}
}
void init()
{
shu=432;
temp=0xfe;
P0=temp;
TMOD=0X11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
a++;
if(flag!=1)
{if(a==10)
a=0;
temp=_crol_(temp,1);
P1=temp;
}
else
{
if(a%6==0)
P1=~P1;
if(a==60)
{
TR0=0;
P1=0Xff;
flag1=1;
}
}
}
void time1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
b++;
if(b==2)
b=0;
shu--;
bai=shu/100;
shi=shu%100/10;
ge=shu%10;
if(shu==398)
{ TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
flag=1;
a=0;
P1=0xff;
TR1=0;
}
}
void display(uchar c,uchar d,uchar e,uchar bai,uchar shi,uchar ge)
{
H1=0;
P0=table[c];
delay(1);
H1=1;
H2=0;
P0=table[d];
delay(1);
H2=1;
H3=0;
P0=table[e];
delay(1);
H3=1;
H4=0;
P0=table[bai];
delay(1);
H4=1;
H5=0;
P0=table[shi];
delay(1);
H5=1;
H6=0;
P0=table[ge];
delay(1);
H6=1;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}