摇椅厂家
免费服务热线

Free service

hotline

010-00000000
摇椅厂家
热门搜索:
行业资讯
当前位置:首页 > 行业资讯

串行口驱动led显示程序

发布时间:2020-07-21 19:15:52 阅读: 来源:摇椅厂家

//本文介绍一个串行口驱动led显示的c语言源程序//一个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

//串行口驱动led显示程序定义结束

//串行送出的位信息,目前是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;i8;i++) { if (dd1) 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[dd0x3f]^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; //800time++;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;}

//串行口驱动led显示程序主程序开始void main(void) {unsigned char i;TMOD=0x1;TR0=ET0=1;EA=1;for (i=0;i10;i++) d[i]=i; //display testwhile (1) {}}

手机电池相关文章:手机电池修复

c语言相关文章:c语言教程

面部填充

哈尔滨双眼皮

重庆热玛吉价格

相关阅读