12864 Chinese character LCD display--key electronic clock program

Publisher:superstar10Latest update time:2016-01-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include

#include
#define uchar unsigned char
void lcd_ini();
void ascii_change(void);
void delay();
void wri_add(uchar com);
void wri_dat(uchar com1);
void shan(void);
void disp();
void tkey(void);
sbit cs=P1^7;
sbit sid=P1^6;
sbit sclk=P1^5;
bit flag=1;
uchar dat,count,f=1;//f tests which unit is the current flashing state   
uchar data clock[3]={23,45,12};
uchar code clockname[10]={"Beijing time:"};   
uchar data num[6];


void main()
{
 lcd_ini();
 count=10;//The machine cycle is 1us, each timing is 50ms, this variable is used to control the number of loops, and is assigned a value of 20 below, with a total timing of 1 second
 TMOD=0x01;
 TL0=0XB0;
 TH0=0X3C;
 EA=1;
 ET0=1 ;
 IT0=1;
 EX0=1;
 TR0=1;
 while(1)
 {
 back:ascii_change();
 disp();
 delay();
 if(flag==1)
 goto back;
 tkey();
 shan();
 delay();
 }
}


 
void lcd_ini()
{

 wri_add(0x30);
 delay();

 wri_add(0x0c);
 delay();

 wri_add(0x01);
 delay();
 
 wri_add(0x06);
 delay();
}
 

 


 void timer1() interrupt 1 using 2
{
 TL0=0XB0;
 TH0=0X3C;
 count--;
 if(count==0)
 {
  count=10;
  clock[2]++;//秒//
  }
  else
  goto out;

  if(clock[2]==60)
  {
   clock[2]=0;
   clock[1]++;//分//
   }

  if(clock[1]==60)
  {
   clock[1]=0;
   clock[0]++;
   }
  
  if(clock[0]==24)//时//
  clock[0]=0;
  
  out:_nop_();
}


 void ascii_change(void)
 {
   num[5]=clock[2]-(clock[2]/10)*10+0x30;
   num[4]=clock[2]/10+0x30;
   num[3]=clock[1]-(clock[1]/10)*10+0x30;
   num[2]=clock[1]/10+0x30;
   num[1]=clock[0]-(clock[0]/10)*10+0x30;
   num[0]=clock[0]/10+0x30;
 }


 
  void delay()
{
  uchar i,j;
  for (i=250;i>0;i--)
  for (j=250;j>0;j--);

}

void wri_add(uchar com)
{
 uchar i,j,k;
 cs=0;
 cs=1;
 dat=0xf8;

 for(i=1;i<=8;i++)
 {
  sid=(bit)(dat&0x80);
  sclk=0;
  sclk=1;
  sclk=0;
  dat=dat<<1;
}
 dat=com;
 dat=dat&0xf0;
 for(j=1;j<=8;j++)
{
 sid=(bit)(dat&0x80);
  sclk=0;
  sclk=1;
  sclk=0;
  dat=dat<<1;
 }

 dat=com;
 dat=_cror_(dat,4); // This is the exchange of high and low four bits
 dat=dat&0xf0;

 for(k=1;k<=8;k++)
 {
  sid=(bit)(dat&0x80);
  sclk=0;
  sclk=1;
  sclk=0;
  dat=dat<<1;
  }
 
}


void wri_dat(uchar com1)
{
 uchar i,j,k;
 cs=0;
 cs=1;
 dat=0xfa;
 for(i=1;i<=8;i++)
 {
 sid=(bit)(dat&0x80);
 sclk=0;
 sclk=1;
 sclk=0;
 dat=dat<<1;
}

 dat=com1;
 dat=dat&0xf0;
 for(j=1;j<=8;j++)
{
 sid=(bit)(dat&0x80);
 sclk=0;
 sclk=1;
 sclk=0;
 dat=dat<<1;
 }

 dat=com1;
 dat=_cror_(dat,4); // This is the exchange of high and low four bits
 dat=dat&0xf0;

 for(k=1;k<=8;k++)
 {
  sid=(bit)(dat&0x80);
  sclk=0;
  sclk=1;
  sclk=0;
  dat=dat<<1;
  }
 }
         

 
void disp()
{
 uchar i,k=0;
 wri_add(0x80);

 for (i=1;i<=9;i++)
 wri_dat(clockname[i-1]);

 wri_add(0x90);

 for (i=1;i<=6;i++)
 {
 k++;
 if(k==3||k==5)
 wri_dat(clockname[8]);//Colon between times.
 wri_dat(num[i-1]);
 }
}


void shan(void)
{
 uchar i,k=0;
 wri_add(0x90);
 if(f==1)
 {
 num[0]=' ';
 num[1]=' ';
 }
 else
 goto next;
 for (i=1;i<=6;i++)
 {
 k++;
 if(k==3||k==5)
 wri_dat(clockname[8]);//Colon between time.
 wri_dat(num[i-1]);
 }
goto return1;

next: if(f==2)
 {
 num[2]=' ';
 num[3]=' ';
 }
 else
 goto next1;
 for (i=1;i<=6;i++)
 {
 k++;
 if(k==3||k==5)
 wri_dat(clockname[8]);//Colon between time.
 wri_dat(num[i-1]);
 }
goto return1;

next1: if(f==3)
 {
 num[4]=' ';
 num[5]=' ';
 }
 else
 goto return1;

 for (i=1;i<=6;i++)
 {
 k++;
 if(k==3||k==5)
 wri_dat(clockname[8]);//Colon between times.
 wri_dat(num[i-1]);
 }
 return1:_nop_();

 


 

void intr0() interrupt 0 using 2
{
flag=~flag;//Judge whether to flash//
TR0=~TR0;  //Flash off timing, otherwise turn on timing
f=1;

    

 void tkey(void)
{
 uchar judcekey;
 judcekey=P1&0x0f;
 if(judcekey==0x0f)
 goto return2;

 
  if (judcekey==0x0e)
  f++;
  if (f==4)
  f=1;
 
  if(judcekey==0x0d)
  {clock[f-1]++;}

  if (f==1)
  { if (clock[f-1]==24){
  clock[f-1]=0;}
   }
  else{  if (clock[f-1]==60)
   clock[f-1]=0;
   }

  
 if(judcekey==0x0b)
  {clock[f-1]--;}

  if (f==1)
  { if (clock[f-1]==0xff){
  clock[f-1]=23;}
   }
  else
   if (clock[f-1]==0xff)
   clock[f-1]=59;
  
 
return2:_nop_();

   


Reference address:12864 Chinese character LCD display--key electronic clock program

Previous article:Electronic clock developed by 51 single chip microcomputer + ds12c887 clock chip
Next article:Introduction to baud rate in 51 single chip microcomputer

Recommended ReadingLatest update time:2024-11-23 19:27

RT12864M LCD module MCU driver
 /*-----------RT12864M module-----------*/ /*------External crystal oscillator is 12MHz-------*/             /*--------Last modified 2011.02.26-------*/ #include "STC12C5620AD.h" #include "RT12864M.h" #include "delay.h" /**************************Custom character encoding****************************/ unsigned c
[Microcontroller]
51 MCU drives ds1302 program (12864 LCD display)
This is the main interface This is the main menu interface This is the sub-interface for setting time This is the setting date Setting the Backlight This is the status icon that appears on the main interface after the key tone and alarm are set.  
[Microcontroller]
51 MCU drives ds1302 program (12864 LCD display)
51 MCU serial communication Bad Apple video playback source program (LCD12864 display)
The program originated from a competition project of my team. The project file is a large project with a lot of content written by other team members. It is not easy for me to post it directly, so I had to capture a small module I wrote and put it up for everyone to share. This program can mainly realize the two func
[Microcontroller]
51 MCU serial communication Bad Apple video playback source program (LCD12864 display)
ARM Litian Electronics LPC2148 without font library 12864 displays multiple Chinese characters in one line (serial)
The 12864 small screen in the LPC2148 development board of Litian Electronics does not have a font library, and there is no so-called left and right screens, upper and lower screens, it is a whole screen. (It is produced by Beijing Jicui Electronic Equipment Co., Ltd., for details, see http://download.csdn.net/detai
[Microcontroller]
ARM Litian Electronics LPC2148 without font library 12864 displays multiple Chinese characters in one line (serial)
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号