找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 2497|回復: 2
打印 上一主題 下一主題
收起左側(cè)

單片機定時器LCD1602顯示簡易電子鐘代碼Proteus仿真圖

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1057281 發(fā)表于 2022-12-13 10:49 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
這是一個簡單的電子時鐘設計,利用LCD1602顯示,均為原創(chuàng),請大家指正
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機源程序如下:
  1. #include<reg51.h>
  2. //#include<lcd1602.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. uchar int_time;
  6. uchar second;
  7. uchar minute;
  8. uchar hour;

  9. void write_data(uchar date);
  10. void write_com(uchar com);
  11. void init1602();
  12. void write_string(uchar *pp, uint n);
  13. void write_sfm(uchar add,uchar date);

  14. uchar code date[]="wwj 2604200321";
  15. uchar code time[]=" TIME  23:59:55 ";
  16. uchar second=55,minute=59,hour=23;

  17. void clock_init(){

  18.         uchar i,j;
  19.         for(i=0;i<16;i++){
  20.                 write_data(date[i]);
  21.         }

  22.         write_com(0x80+0x40);
  23.         for(j=0;j<16;j++){
  24.                 write_data(time[j]);
  25.         }
  26. }

  27. void clock_write(uint s, uint m, uint h){
  28.         write_sfm(0x47,h);
  29.         write_sfm(0x4a,m);
  30.         write_sfm(0x4d,s);
  31. }
  32. void main(){
  33.         init1602();
  34.         clock_init();
  35.         TMOD=0x01;
  36.         EA=1;
  37.         ET0=1;
  38.         TH0=(65536-46483)/256;
  39.         TL0=(65536- 46483)%256;
  40.         TR0=1;
  41.         int_time=0;
  42.         second=55;
  43.         minute=59;
  44.         hour=23;

  45.         while(1){
  46.                 clock_write(second,minute,hour);
  47.         }
  48. }
  49. void T0_interserve(void) interrupt 1 using 1{
  50.         int_time++;
  51.         if(int_time==20){
  52.                 int_time=0;
  53.                 second++;
  54.         }
  55.         if(second==60){
  56.                 second=0;
  57.                 minute++;
  58.         }
  59.         if(minute==60){
  60.                 minute=0;
  61.                 hour ++;
  62.         }
  63.         if(hour==24){
  64.                 hour=0;
  65.         }

  66.         TH0=(65536-46083)/256;
  67.         TL0=(65536- 46083)%256;
  68. }

  69. //#ifndef LCD_CHAR_1602_2011_5_9
  70. #define LCD_CHAR_1602_2011_5_9
  71. #define uchar unsigned char
  72. #define uint unsigned int
  73. sbit Icdrs = P2^0;
  74. sbit Icdrw= P2^1;
  75. sbit Icden= P2^2;

  76. void delay(uint z){
  77.         uint x,y;
  78.         for(x=z;x>0;x--){
  79.                 for(y=110;y>0;y--);
  80.         }
  81. }

  82. void write_com(uchar com){
  83.         Icdrw=0;
  84.         Icdrs=0;
  85.         P3=com;
  86.         delay(5);
  87.         Icden=1;
  88.         delay(5);
  89.         Icden=0;
  90. }

  91. void write_data(uchar date){
  92.         Icdrw=0;
  93.         Icdrs=1;
  94.         P3=date;
  95.         delay(5);
  96.         Icden=1;
  97.         delay(5);
  98.         Icden=0;
  99. }

  100. void init1602(){
  101.         Icdrw=0;
  102.         Icden=0;
  103.         write_com(0x3C);
  104.         write_com(0x0c);
  105.         write_com(0x06);
  106.         write_com(0x01);
  107.         write_com(0x80);
  108. }

  109. void write_string(uchar *pp, uint n){
  110.         int i;
  111.         for(i=0;i<n;i++){
  112.                 write_data(pp[i]);
  113.         }
  114. }

  115. void write_sfm(uchar add,uchar date){
  116.         uchar shi,ge;
  117.         shi=date/10;
  118.         ge=date%10;
  119.         write_com(0x80+add);
  120.         write_data(0x30+shi);
  121.         write_data(0x30+ge);
  122. }
  123. //#endif
復制代碼

Keil代碼與Proteus8.13仿真下載:
LCD.7z (35.31 KB, 下載次數(shù): 57)

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:1103226 發(fā)表于 2023-12-8 08:54 | 只看該作者
樓主,代碼全嗎?
回復

使用道具 舉報

板凳
ID:884711 發(fā)表于 2024-5-5 09:38 | 只看該作者
路過學習,謝謝分享!
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表