電路很簡(jiǎn)單,我就不畫(huà)圖了,四位數(shù)碼管 通過(guò)2個(gè)74hc595連起來(lái),1個(gè)595負(fù)責(zé)段選,1個(gè)595負(fù)責(zé)位選,利用單片機(jī)的定時(shí)器中斷實(shí)現(xiàn)0-100數(shù)字的循環(huán)顯示.程序已經(jīng)通過(guò)本人測(cè)試通過(guò)#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)//對(duì)595芯片進(jìn)行設(shè)初始化{for(k=0;k<8;k++) //移位寄存器{x>>=1;sck=0;si=CY;sck=1;}}void date_danpianji()//對(duì)單片機(jī)計(jì)時(shí)器進(jìn)行初始化{EA=1;//總中斷開(kāi)啟ET1=1;//定時(shí)器開(kāi)啟TMOD=0X10;//選擇定時(shí)器工作模式TH1=(65536-33333)/256;//除整賦給高八位TL1=(65536-33333)%256;//除余賦給第八位TR1=1; //啟動(dòng)定時(shí)器 }void main()//主函數(shù){date_danpianji();//調(diào)用定時(shí)器中斷while(1)//循環(huán){ if(b==20)//檢測(cè)中斷函數(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 //定時(shí)器中斷{TH1=(65536-33333)/256;TL1=(65536-33333)%256;b++;}
評(píng)論