找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2760|回复: 2
收起左侧

51单片机加74hc595加时钟程序Proteus仿真 无按键

[复制链接]
ID:899160 发表于 2021-4-30 19:50 | 显示全部楼层 |阅读模式
用 2 个 74LS595 芯片设计 8 位显示电路,,实现“时、分、秒、ms”走时显示,“时、分、秒、ms”分别用 2 位数码显示

顺便附上关于我理解595b站视频

视频连接:74HC595原理讲解,嵌入式系统原理及设计,单片机开发_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili

单片机源程序如下:
  1. #include<reg52.h>

  2. sbit LATCH=P2^0;    //输出时钟
  3. sbit SRCLK=P2^1;    //输入时钟
  4. sbit SDATA=P2^2;   //数据输入

  5. //unsigned char BJTY_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//笔芯码
  6. unsigned char BJTY_DuanMa[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//笔芯码

  7. unsigned char BJTY_WeiMa[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//位选码

  8. unsigned char x=0,k,b=0;
  9. unsigned char showdata[10]=0;
  10. unsigned int hour,min,sec,mil,count;
  11. unsigned int hour1,min1,sec1,mil1,count1;
  12. unsigned int hour2,min2,sec2,mil2,count2;


  13. void init()                                       
  14. {
  15.         count=0;
  16.         hour=00;
  17.         min=00;
  18.         sec=00;
  19.         mil=00;
  20.         hour1=0;
  21.         hour2=0;
  22.         min1=0;
  23.         min2=0;
  24.         sec1=0;
  25.         sec2=0;
  26.         mil1=0;
  27.         mil2=0;
  28.        
  29.        
  30.        
  31.         TMOD=0x01;//定时器1
  32.         TH0=(65536-10000)/256;//大约10ms
  33.         TL0=(65536-10000)%256;
  34.         TR0=1;
  35.         ET0=1;
  36.         EA=1;
  37. }

  38. void count0() interrupt 1
  39. {
  40.         TH0=(65536-10000)/256;
  41.         TL0=(65536-10000)%256;
  42.         mil++;
  43.         if(mil==100)
  44.                 {
  45.                         mil=0;
  46.                         sec++;
  47.                         if(sec==60)
  48.                         {
  49.                                 sec=0;
  50.                                 min++;
  51.                                 if(min==60)
  52.                                 {
  53.                                         min=0;
  54.                                         hour++;
  55.                                         if(hour==24)
  56.                                         {
  57.                                                   hour=0;
  58.                                         }
  59.                                 }
  60.                         }

  61.                 }
  62. }

  63. void delay1ms(unsigned int x)//延时函数
  64. {
  65.         unsigned int i,j;
  66.         for(j=0;j<x;j++)
  67.                 for(i=0;i<123;i++);
  68. }

  69. void LAT595(void)//输出时钟发出上升沿
  70. {
  71.     LATCH=0;   
  72.     LATCH=1;
  73. }



  74. void SendByte(unsigned char dat)
  75. {   
  76.     unsigned char y;
  77.     for(y=0;y<8;y++)
  78.     {
  79.         SRCLK=0;   
  80.         if(dat&0x80)    //与1000 0000 相与 输入数据
  81.             SDATA=1;   
  82.         else
  83.             SDATA=0;   
  84.         dat<<=1;        //输入段码的下一个字的数据
  85.         SRCLK=1;       //输入上升沿触发
  86.     }
  87. }


  88. void Send2Byte(unsigned char dat1,unsigned char dat2)//段选 位选逐个发送
  89. {   
  90.    SendByte(dat1);     
  91.    SendByte(dat2);     
  92. }

  93. void show_led(void)
  94. {
  95.         Send2Byte(BJTY_WeiMa[7],BJTY_DuanMa[mil2]);
  96.         LAT595();
  97.         Send2Byte(BJTY_WeiMa[6],BJTY_DuanMa[mil1]);
  98.         LAT595();
  99.         Send2Byte(BJTY_WeiMa[5],BJTY_DuanMa[sec2]);
  100.         LAT595();
  101.         Send2Byte(BJTY_WeiMa[4],BJTY_DuanMa[sec1]);
  102.         LAT595();
  103.         Send2Byte(BJTY_WeiMa[3],BJTY_DuanMa[min2]);
  104.         LAT595();
  105.         Send2Byte(BJTY_WeiMa[2],BJTY_DuanMa[min1]);
  106.         LAT595();
  107.         Send2Byte(BJTY_WeiMa[1],BJTY_DuanMa[hour2]);
  108.         LAT595();
  109.         Send2Byte(BJTY_WeiMa[0],BJTY_DuanMa[hour1]);
  110.         LAT595();                  

  111. }
  112.        



  113. void main(void)
  114. {
  115.         init();
  116.         delay1ms(1000);
  117.         while (1)
  118.         {
  119.                 mil1=mil/10;
  120.                 mil2=mil%10;
  121.                 sec1=sec/10;
  122.                 sec2=sec%10;
  123.                 min1=min/10;
  124.                 min2=min%10;
  125.                 hour1=hour/10;
  126.                 hour2=hour%10;
  127.                 show_led();
  128.                
  129.        
  130.         }
  131.        
  132. }
复制代码

仿真代码51hei下载地址:
595.zip (42.67 KB, 下载次数: 27)
74HC595的原理图.png

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:899160 发表于 2021-4-30 19:53 | 显示全部楼层
屏幕截图 2021-04-30 195241.png
回复

使用道具 举报

ID:600695 发表于 2021-10-25 03:48 | 显示全部楼层
屏幕截图 2021-10-25 034732.png 程序拷过去是乱码怎么破
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表