⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shuzizhong.c

📁 自己写的数字电子钟的代码(含液晶)
💻 C
字号:
//液晶显示数字钟
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int

sbit RS=P2^6;
sbit RW=P2^4;
sbit EN=P2^2;

uchar count,shi,fen,miao;

uchar code table[]="   2008 7 24   ";
uchar code table1[]="  00:00:00     ";

void delay(uint z)

  {
       uint x,y;
     for(x=z;x>0;x--)
       for(y=120;y>0;y--);
   }

   void write_com(uchar com)
   {
     EN=0;
     RS=0;
     RW=0;
     P0=com;
     delay(5);
     EN=1;
     delay(5);
     EN=0;
    }
 void write_data(uchar date)
   {
     EN=0;
     RS=1;
     RW=0;
     P0=date;
     delay(5);
     EN=1;
     delay(5);
     EN=0;
   }


   void init()
   {
     uchar num;
     EN=0;
	 write_com(0x38);
	 write_com(0x0c);  //开显示
	 write_com(0x06);
	 write_com(0x01);  //清零

     write_com(0x80);   //给地址
	 for(num=0;num<16;num++)
      {
	   write_data(table[num]);
	    delay(5);
       }
	 write_com(0x80+0x40);//换行给地址
	 for(num=0;num<16;num++)
      {
	   write_data(table1[num]);
	     delay(5);
       }

	    TMOD=0x01;
		TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;

		EA=1;
		ET0=1;
		TR0=1;

	 }
   void write_sfm(uchar addr, uchar dat)
   {
        uchar sh,ge;
		sh=dat/10;
		ge=dat%10;
       write_com(0x80+0x40+addr);
	   write_data(0x30+sh);
	   write_data(0x30+ge);
   }
   void main()
   {

     init();
	 while(1)
	 {
		 if (count==20)
			  {
			   count=0;
		       miao++;
			   if(miao==60)
				     { miao=0;
					  fen++;
					  if(fen==60)
							    { fen=0;
								  shi++;
								  if (shi==24)
								    {shi==0;}
                                    write_sfm(2,shi);
								}
                        write_sfm(5,fen);
			         }
			   write_sfm(8,miao);
			  }
	     }
   }


   void timer0() interrupt 1
   {
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
		count++;

   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -