//一个74hc595位移寄存器驱动三极管驱动led位,
//两个74hc595驱动led段,方式位5位x8段x2=10个数码管
//5分频,每次扫描时间位1.25ms
//定义特殊符号
#define nul 0xf
#define qc 0xc
#define qb 0xb
#define q_ 0xa
#define q__ 0xd
#define q___ 0xe
#define qp 0x10
#define qe 0x11
#define qj 0x12
#define qn 0x13
#define qf 0x14
#define qa 0x15
#define qr 0x16
#define qd 0x17
#define qu 0x18
#define ql 0x19
#define qh 0x1a
#define qwen 0x1b
#define qt 0x1c
#define qla 0x1d
#define qlb 0x1e
#define qlc 0x1f
#define qld 0x20
#define qle 0x21
#define qlf 0x22
#define qlg 0x23
#define qldp 0x24
//显示段信息,不同led排列组合的段信息只需更改8个数值即可。
//因此,该定义具有通用性。
// 显示
// -d 20
// |c 40 |e 10
// - g 80
// |b 2 |f 4
// _a1 .dp 8
#define pa 1
#define pb 2
#define pc 0x40
#define pd 0x20
#define pe 0x10
#define pf 4
#define pg 0x80
#define pdp 8
//--------------
#define l0 pdp+pg
#define l1 255-pf-pe
#define l2 pdp+pc+pf
#define l3 pdp+pc+pb
#define l4 pdp+pa+pb+pd
#define l5 pdp+pb+pe
#define l6 pdp+pe
#define l7 pdp+pc+pg+pb+pa
#define l8 pdp
#define l9 pdp+pb
#define la pdp+pa
#define lb pdp+pd+pe
#define lc pdp+pg+pe+pf
#define ld pdp+pc+pd
#define le pdp+pe+pf
#define lf pdp+pe+pf+pa
#define l_ 255-pg
#define lnul 255
#define ll pdp+pg+pd+pf+pe
#define lp pdp+pa+pf
#define lt pdp+pd+pe+pf
#define lr pdp+pe+pf+pg+pa
#define ln pdp+pg+pa
#define lh pdp+pd+pe+pa
#define ly pdp+pb+pd
#define lu pdp+pg+pd
#define l__ pdp+pg+pb+pc+pe+pf
#define l___ l__-pg
#define l_1 255-pa
#define l_2 255-pa-pg
#define lj 255-(pe+pf+pa)
#define lwen 255-(pd+pe+pg+pb)
#define lall 0
#define lla 255-pa
#define llb 255-pb
#define llc 255-pc
#define lld 255-pd
#define lle 255-pe
#define llf 255-pf
#define llg 255-pg
#define lldp 255-pdp
//串行送出的位信息,目前是10位led显示。
unsigned char code un_dig[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb};
//串行送出的短信息。
unsigned char code un_disp[]={l0,l1,l2,l3,l4,l5,l6,l7,l8,l9,l_,lb,lc,l__,l___,lnul,lp,le,lj,ln,lf,la,lr,ld,lu,
ll,lh,lwen,lt,lla,llb,llc,lld,lle,llf,llg,lldp,lnul};
sbit d_clk=P0^0; //移位时钟
sbit d_dat=P0^1; //移位数据
sbit d_st=P0^2; //移位锁定
unsigned char dig; //位扫描计数器
unsigned char d[10]; //显示缓冲
//送出8位串行数据
void out_disp(unsigned char dd) {
unsigned char i;
for (i=0;i<8;i++) {
if (dd&1) d_dat=1; else d_dat=0;
d_clk=0;
dd>>=1;
d_clk=1;
}
}
//控制小数点和闪烁,显示数据|0x040表示有小数点;显示数据|0x80表示闪烁。
void out_displ(unsigned char dd) {
if (dd>=0x80) {
if (s001>flash_time) {out_disp(0xff);return;}
}
dd&=0x7f;
if (dd>=0x40) {
dd=un_disp[dd&0x3f]^pdp;
} else dd=un_disp[dd];
out_disp(dd);
}
unsigned int s001; //闪烁时间参考
void int_t0(void) interrupt 1 {
unsigned char dd;
TL0=TL0+30;TH0=0xfb; //800
time++;
if ((++s001)>=800) s001=0;
// 显示
if ((++dig)>4) dig=0;
d_st=0;
dd=d[dig+5];
out_displ(dd);
dd=d[dig];
out_displ(dd);
out_disp(un_dig[dig]);
d_st=1;
}
void main(void) {
unsigned char i;
TMOD=0x1;
TR0=ET0=1;
EA=1;
for (i=0;i<10;i++) d[i]=i; //display test
while (1) {}
}