16進(jìn)制轉(zhuǎn)換算成10進(jìn)制程序
//顯示段信息,不同led排列組合的段信息只需更改8個(gè)數(shù)值即可。
//因此,該定義具有通用性。本文引用地址:http://m.butianyuan.cn/article/172812.htm
// 顯示
// -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; //移位時(shí)鐘
sbit d_dat=P0^1; //移位數(shù)據(jù)
sbit d_st=P0^2; //移位鎖定
unsigned char dig; //位掃描計(jì)數(shù)器
unsigned char d[10]; //顯示緩沖
//送出8位串行數(shù)據(jù)
void out_disp(unsigned char dd) {
unsigned char i;
for (i=0;i8;i++) {
if (dd1) d_dat=1; else d_dat=0;
d_clk=0;
dd>>=1;
d_clk=1;
}
}
//控制小數(shù)點(diǎn)和閃爍,顯示數(shù)據(jù)|0x040表示有小數(shù)點(diǎn);顯示數(shù)據(jù)|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[dd0x3f]^pdp;
} else dd=un_disp[dd];
out_disp(dd);
}
unsigned int s001; //閃爍時(shí)間參考
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;i10;i++) d[i]=i; //display test
while (1) {}
}
評論