電路很簡單,我就不畫圖了,四位數(shù)碼管 通過2個74hc595連起來,1個595負(fù)責(zé)段選,1個595負(fù)責(zé)位選,利用單片機(jī)的定時器中斷實(shí)現(xiàn)0-100數(shù)字的循環(huán)顯示.程序已經(jīng)通過本人測試通過#include#define uint unsigned int#define uchar unsigned charsbit rck=P0^0;sbit sck=P0^1;sbit si=P0^2;uchar num[]={0x80,0xed,0x42,0x48,0x2c,0x18,0x10,0xcc,0x00,0x08};uint b=0,i=0,j=0,k;void write_595(uchar x)//對595芯片進(jìn)行設(shè)初始化{for(k=0;k<8;k++) //移位寄存器{x>>=1;sck=0;si=CY;sck=1;}}void date_danpianji()//對單片機(jī)計時器進(jìn)行初始化{EA=1;//總中斷開啟ET1=1;//定時器開啟TMOD=0X10;//選擇定時器工作模式TH1=(65536-33333)/256;//除整賦給高八位TL1=(65536-33333)%256;//除余賦給第八位TR1=1; //啟動定時器 }void main()//主函數(shù){date_danpianji();//調(diào)用定時器中斷while(1)//循環(huán){ if(b==20)//檢測中斷函數(shù)是否滿足b==20,如果滿足則執(zhí)行{b=0;i++;if(i==10){i=0;j++;if(j==10)j=0;}}write_595(num[j]);write_595(num[i]);rck=0;rck=1; }} void ext() interrupt 3 using 1 //定時器中斷{TH1=(65536-33333)/256;TL1=(65536-33333)%256;b++;}
評論