|
#include<reg51.h>
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
code uint8 number[]={ 0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
uint8 a[8];
uint16 counter = 0;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
void timer1_init()
{
TMOD|=0x10;
TMOD&=0xDF;
TH1 =0xFC;
TL1 =0x67;
TR1 =1;
}
void int_init()
{
ET1 = 1;
EA = 1;
}
void refresh_led()
{
static uint8 j=7;
switch(j)
{
case 7:LSA=0;LSB=0;LSC=0;j--;P0=number[a[0]];break;
case 6:LSA=1;LSB=0;LSC=0;j--;P0=number[a[1]];break;
case 5:LSA=0;LSB=1;LSC=0;j--;P0=number[a[2]];break;
case 4:LSA=0;LSB=0;LSC=1;j--;P0=number[a[3]];break;
case 3:LSA=1;LSB=0;LSC=1;j--;P0=number[a[4]];break;
case 2:LSA=0;LSB=1;LSC=1;j--;P0=number[a[5]];break;
case 1:LSA=1;LSB=1;LSC=0;j--;P0=number[a[6]];break;
case 0:LSA=1;LSB=1;LSC=1;j=7;P0=number[a[7]];break;
default :break;
}
}
void main()
{
timer1_init();
int_init();
while(1);
}
void interrupt_timer1() interrupt 3
{
static uint32 m;
TH1 = 0xFC;
TL1 = 0x67;
P0 = 0x00;
counter++;
if(counter == 1000)
{
m++;
counter = 0;
a[0]=m%10;
a[1]=m/10%10;
a[2]=m/100%10;
a[3]=m/1000%10;
a[4]=m/10000%10;
a[5]=m/100000%10;
a[6]=m/1000000%10;
a[7]=m/10000000%10;
}
refresh_led();
}
|
评分
-
查看全部评分
|