用 2 個 74LS595 芯片設計 8 位顯示電路,,實現“時、分、秒、ms”走時顯示,“時、分、秒、ms”分別用 2 位數碼顯示
順便附上關于我理解595b站視頻
視頻連接:74HC595原理講解,嵌入式系統原理及設計,單片機開發_嗶哩嗶哩 (゜-゜)つロ 干杯~-bilibili
單片機源程序如下:
- #include<reg52.h>
- sbit LATCH=P2^0; //輸出時鐘
- sbit SRCLK=P2^1; //輸入時鐘
- sbit SDATA=P2^2; //數據輸入
- //unsigned char BJTY_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//筆芯碼
- unsigned char BJTY_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//筆芯碼
- unsigned char BJTY_WeiMa[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位選碼
- unsigned char x=0,k,b=0;
- unsigned char showdata[10]=0;
- unsigned int hour,min,sec,mil,count;
- unsigned int hour1,min1,sec1,mil1,count1;
- unsigned int hour2,min2,sec2,mil2,count2;
- void init()
- {
- count=0;
- hour=00;
- min=00;
- sec=00;
- mil=00;
- hour1=0;
- hour2=0;
- min1=0;
- min2=0;
- sec1=0;
- sec2=0;
- mil1=0;
- mil2=0;
-
-
-
- TMOD=0x01;//定時器1
- TH0=(65536-10000)/256;//大約10ms
- TL0=(65536-10000)%256;
- TR0=1;
- ET0=1;
- EA=1;
- }
- void count0() interrupt 1
- {
- TH0=(65536-10000)/256;
- TL0=(65536-10000)%256;
- mil++;
- if(mil==100)
- {
- mil=0;
- sec++;
- if(sec==60)
- {
- sec=0;
- min++;
- if(min==60)
- {
- min=0;
- hour++;
- if(hour==24)
- {
- hour=0;
- }
- }
- }
-
- }
- }
- void delay1ms(unsigned int x)//延時函數
- {
- unsigned int i,j;
- for(j=0;j<x;j++)
- for(i=0;i<123;i++);
- }
- void LAT595(void)//輸出時鐘發出上升沿
- {
- LATCH=0;
- LATCH=1;
- }
- void SendByte(unsigned char dat)
- {
- unsigned char y;
- for(y=0;y<8;y++)
- {
- SRCLK=0;
- if(dat&0x80) //與1000 0000 相與 輸入數據
- SDATA=1;
- else
- SDATA=0;
- dat<<=1; //輸入段碼的下一個字的數據
- SRCLK=1; //輸入上升沿觸發
- }
- }
- void Send2Byte(unsigned char dat1,unsigned char dat2)//段選 位選逐個發送
- {
- SendByte(dat1);
- SendByte(dat2);
- }
- void show_led(void)
- {
- Send2Byte(BJTY_WeiMa[7],BJTY_DuanMa[mil2]);
- LAT595();
- Send2Byte(BJTY_WeiMa[6],BJTY_DuanMa[mil1]);
- LAT595();
- Send2Byte(BJTY_WeiMa[5],BJTY_DuanMa[sec2]);
- LAT595();
- Send2Byte(BJTY_WeiMa[4],BJTY_DuanMa[sec1]);
- LAT595();
- Send2Byte(BJTY_WeiMa[3],BJTY_DuanMa[min2]);
- LAT595();
- Send2Byte(BJTY_WeiMa[2],BJTY_DuanMa[min1]);
- LAT595();
- Send2Byte(BJTY_WeiMa[1],BJTY_DuanMa[hour2]);
- LAT595();
- Send2Byte(BJTY_WeiMa[0],BJTY_DuanMa[hour1]);
- LAT595();
- }
-
- void main(void)
- {
- init();
- delay1ms(1000);
- while (1)
- {
- mil1=mil/10;
- mil2=mil%10;
- sec1=sec/10;
- sec2=sec%10;
- min1=min/10;
- min2=min%10;
- hour1=hour/10;
- hour2=hour%10;
- show_led();
-
-
- }
-
- }
復制代碼
仿真代碼51hei下載地址:
595.zip
(42.67 KB, 下載次數: 27)
2021-4-30 19:39 上傳
點擊文件名下載附件
proteus+程序 下載積分: 黑幣 -5
|