用 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)
|