欢迎来到天天文库
浏览记录
ID:49702872
大小:312.50 KB
页数:6页
时间:2020-03-03
《两片74HC595级联驱动8个数码管.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、两片74HC595级联动态驱动8位数码管 51单片机#includesbitSCK=P1^1; //数据输入时钟线,脉冲sbitSI =P1^0; //数据线sbitRCK=P1^2; //锁存unsignedcharcodeSMG[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; //段码unsignedcharcodeWei[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //位选
2、unsignedcharVal[8] ={0}; //要显示的数据 ************************函数声明************************voidinterrupt_init(void);voidtimer_init(void); 控制74HC595输出数据voidOutput(void){ RCK=0; RCK=1;} 向74HC595中写入一字节数据voidWrite_Byte(unsignedchardat){ unsignedchari=0; for(i=
3、0;i<8;i++) { SCK=0; SI =dat&0x80; SCK=1; dat<<=1; }} 显示函数voidDisplay(unsignedchar*p){ unsignedchar*pt=Wei; Write_Byte(*(pt+0)); Write_Byte(SMG[*(p+7)]); Output(); Write_Byte(*(pt+1)); Write_Byte(SMG[*(p+6)]
4、); Output(); Write_Byte(*(pt+2)); Write_Byte(SMG[*(p+5)]); Output(); Write_Byte(*(pt+3)); Write_Byte(SMG[*(p+4)]); Output(); Write_Byte(*(pt+4)); Write_Byte(SMG[*(p+3)]); Output(); Write_Byte(*(pt+5)); Write_Byte(SMG[*(p+2)]);
5、 Output(); Write_Byte(*(pt+6)); Write_Byte(SMG[*(p+1)]); Output(); Write_Byte(*(pt+7)); Write_Byte(SMG[*(p+0)]); Output(); } intmain(void){ timer_init(); interrupt_init(); while(1) { Display(Val); } return0;}voidinterr
6、upt_init(void){ EA =1; //开总中断 ET0=1; //开定时器0中断 ET1=1; //开定时器1中断}voidtimer_init(void){ TMOD=TMOD
7、0x01; //定时器0工作方式1 TMOD=TMOD&0xFD; TH0 =0x4B; //装初值,50ms计数 TL0 =0xFF; TR0 =1; //开启定时器0}voidtimer0()interrupt1{ staticunsignedcharcounter0=0; counter0++; TH0
8、 =0x4B; //重新装入初值,定时器0从头开始计数,计数50ms TL0 =0xFF; if(2==counter0) //2*50ms=100ms=0.1s { counter0=0; //counter0置零,定时器0从头开始计数 Val[0]++; if(10==Val[0]) { Val[0]=0; Val[1]++; if(10==Val[1])
9、 { Val[1]=0; Val[2]++; if(10==Val[2]) { Val[2]=0;
此文档下载收益归作者所有