#include<reg52.h>
sbit xuanshou1=P1^0;
sbit xuanshou2=P1^1;
sbit xuanshou3=P1^2;
sbit led1=P1^3;
sbit led2=P1^4;
sbit led3=P1^5;
sbit we7=P2^1;
sbit we8=P2^0;
unsigned char geflag;
unsigned char ge,shi;
unsigned int num,k1,k2,k3;
unsigned char code table1[ ]={
0xC0, //"0"
0xF9, //"1"
0xA4, //"2"
0xB0, //"3"
0x99, //"4"
0x92, //"5"
0x82, //"6"
0xF8, //"7"
0x80, //"8"
0x90, //"9"
};
unsigned char code table2[ ]={
0x40, //"0"
0x79, //"1"
0x24, //"2"
0x30, //"3"
0x19, //"4"
0x12, //"5"
0x02, //"6"
0x78, //"7"
0x00, //"8"
0x10, //"9"
};
void smg_init();
void delay(unsigned int i);
void display();
void main()
{
num=1;
// ge=0;
// shi=1;
TMOD=0X01;
EA=1;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
ET0=1;
TR0=0;
while(1)
{
if(num%500==0)
{
ge++;
if(ge==10)
{
ge=0;
shi++;
if(shi==10)
shi=0;
}
}
if(xuanshou1==0)
{
k2=1;
k3=1;
if(k1==0)
{
TR0=1;
led1=0;
}
}
if(xuanshou2==0)
{
k1=1;
k3=1;
if(k2==0)
{
TR0=1;
led2=0;
}
}
if(xuanshou3==0)
{
k1=1;
k2=1;
if(k3==0)
{
TR0=1;
led3=0;
}
}
display();
}
}
void smg_init( )
{
we7=0;
we8=0;
}
void delay(unsigned int i)
{
while(i--);
}
void display()
{
smg_init( );
P0 = table1[ge];
we7 = 1;
delay(4);
smg_init( );
P0 = table2[shi];
we8 = 1;
delay(4);
}
void
time0() interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
num++;
if(num==16500)
{
TR0=0;
num=1;
led1=1;
led2=1;
led3=1;
}
}
TMOD=0X01;
EA=1;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
ET0=1;
TR0=0;
void display()
{
smg_init( );
P0 = table1[ge];
we7 = 1;
delay(4);
smg_init( );
P0 = table2[shi];
we8 = 1;
delay(4);
}
这两段程序有什么用?
明白了!第一次不太清楚
一周热门 更多>