DIY 1602 clock with adjustable display

Publisher:qiuxubiaoLatest update time:2012-08-31 Source: 51heiKeywords:Clock Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#define uint unsigned int
#define uchar unsigned char

sbit key0 = P3^0; //Time adjustment minute and second switching
sbit key1 = P3^1; //time addition
sbit key2 = P3^2; //time subtraction
sbit lcdrw = P2^5; //Read and write operation selection, 1 for reading and 0 for writing
sbit rs = P2^6; //register selection, 1 data 0 instruction
sbit lcden = P2^7; //enable signal
uchar code table[] = {" 2010-10-22 FRI"};
uchar code table1[] = {"    00:00:00"};
uchar count,shi,fen,miao,s1num;

void delay(uint z)
{
 uint x,y;
 for(x = z;x > 0;x --)
  for(y = 110;y > 0;y --);
}

void write_com(uchar com) //write instruction
{
 rs = 0;
 lcden = 0;
 P0 = with;
 delay(5);
 lcden = 1;
 delay(5);
 lcden = 0; 
}

void write_date(uchar date) //write data
{
 rs = 1;
 lcden = 0;
 P0 = date;
 delay(5);
 lcden = 1;
 delay(5);
 lcden = 0;
}

void init()
{
 flying number;
 lcdrw = 0;
 lcden = 0;
 write_com(0x38);
 write_com(0x0c);
 write_com(0x06);
 write_com(0x01);//clear

 write_com(0x80); //LCD first line address
 for(num = 0;num < 15;num ++)
 {
  write_date(table[num]);
  delay(5); 
 }
 write_com(0x80+0x40); //LCD second line address
 for(num = 0;num < 12;num ++)
 {
  write_date(table1[num]);
  delay(5);
 }

 TMOD = 0x01;
 TH0 = (65536-50000)/256;
 TL0 = (65536-50000)%256;
 EA = 1; // Enable interrupt
 ET0 = 1; //Timer 0 interrupt
 TR0 = 1; //Start the timer
}

void write_sfm(uchar add,uchar date)
{
 flying shi,ge;
 shi = date/10;
 ge = date%10;
 write_com(0x80+0x40+add);
 write_date(0x30+shi);
 write_date(0x30+ge);
}

void keyscan()
{
 if(key0 == 0)
 {
  delay(5);
  if(key0 == 0)
  {
   s1num ++;
   while(!key0);
   if(s1num == 1)
   {
    TR0 = 0;
    write_com(0x80+0x40+10);
    write_com(0x0f);
   }

   if(s1num == 2)
   {
    write_com(0x80+0x40+7);
   }

   if(s1num == 3)
   {
    write_com(0x80+0x40+4);
   }

   if(s1num == 4)
   {
    s1num = 0;
    write_com(0x0c); //No flash mark
    TR0 = 1;
   }
  }
 }

 if(s1num != 0)
  {
   if(key1 == 0)
   {
    delay(5);
    if(key1 == 0)
    {
     while(!key1);
     if(s1num == 1)
     {
      miao ++;
      if(miao == 60)
      miao = 0;
      write_sfm(10,miao);
      write_com(0x80+0x40+10);
 
     }

     if(s1num == 2)
     {
      fen ++;
      if(fen == 60)
      fen = 0;
      write_sfm(7,fen);
      write_com(0x80+0x40+7); 
     }

     if(s1num == 3)
     {
      it ++;
      if(shi == 24)
      it = 0;
      write_sfm(4,shi);
      write_com(0x80+0x40+4); 
     }
    }
   }

   if(key2 == 0)
   {
    delay(5);
    if(key2 == 0)
    {
     while(!key2);
     if(s1num == 1)
     {
       if(miao == 0)
       {
        miao = 60;
        write_sfm(10,miao);
        write_com(0x80+0x40+10);
       }
       miao --;
       write_sfm(10,miao);
       write_com(0x80+0x40+10);
      
     }

     if(s1num == 2)
     {
      if(fen == 0)
       {
        fen = 60;
        write_sfm(7,fen);
        write_com(0x80+0x40+7);
       }
       fen --;
       write_sfm(7,fen);
       write_com(0x80+0x40+7); 
     }

     if(s1num == 3)
     {
        if(shi == 0)
       {
        it = 24;
        write_sfm(4,shi);
        write_com(0x80+0x40+4);
       }
       he --;
       write_sfm(4,shi);
       write_com(0x80+0x40+4);
     }
    }
   }

  } 
}

void main()
{
 heat();
 while(1)
 {
  keyscan();
  
 // while(1);
 }
}

void timer0() interrupt 1
{
 TH0 = (65536-50000)/256;
 TL0 = (65536-50000)%256;
 count ++;
 if(count == 20)
  {
   count = 0;
   miao ++;
   if(miao == 60)
   {
    miao = 0;
    fen ++;
    if(fen == 60)
    {
     fen = 0;
     it ++;
     if(shi ==24)
     {
      it = 0;
     }
     write_sfm(4,shi);
    }
    write_sfm(7,fen);
   }
   write_sfm(10,miao);
  } 
}
Keywords:Clock Reference address:DIY 1602 clock with adjustable display

Previous article:Infrared tax calculator based on single chip microcomputer
Next article:Infineon MCU XC866-2FR infrared receiving program (state machine)

Recommended ReadingLatest update time:2024-11-16 17:56

Automatic calibration and adjustment of calendar clock in single chip microcomputer system
1. Overview In various detection and control systems, it is necessary to use a calendar clock to control time or record the time when an event occurs. Such as power grid detection systems, street light control systems, etc. However, the defects of the calendar clock often running fast or slow are inevitable. Aft
[Microcontroller]
Automatic calibration and adjustment of calendar clock in single chip microcomputer system
C51 driver for 1602LCD module
I have a 1602 LCD, ks0066 driver chip, with LED backlight. I wrote a driver with reference to some information on the website. After writing it, I found that it is basically the same as the code circulating on the Internet. /*========================================                           1602lcd module driver ==
[Microcontroller]
C51 driver for 1602LCD module
tiny4412 clock test
The 4412 clock system was analyzed above. This article will simply test it, referring to Teacher Wei Dongshan's Linux Application Complete Development Manual 4412 (Part 1) First experiment: Samsung's BL1 will initialize ARMCLK to 400MHz. We turn off APLL and let ARMCLK work at 24MHz to see if the LED flashes slowl
[Microcontroller]
tiny4412 clock test
Oscillation cycle, clock cycle, machine cycle, instruction cycle in PIC
Clock cycle:         Clock cycle (CPU main frequency) == oscillation period, defined as the reciprocal of the clock pulse (the clock cycle is the reciprocal of the external crystal oscillator of the microcontroller, for example, the clock cycle of a 12M crystal oscillator is 1/12us), and is the most basic and smalle
[Microcontroller]
LCD1602 expert use detailed explanation
We have finally finished some basic application methods of AVR MEGA16 microcontroller. At this time, everyone should have a relatively superficial but vivid understanding of the use of some internal resources of AVR, such as timers, ADC, and the most important IO ports. In this section, we will look at another major t
[Microcontroller]
LCD1602 expert use detailed explanation
(Time) DS1302 clock chip driver
The driver of DS1302 is written separately from the application. Here is the code for the driver of DS1302:     DS1302.H Code #ifndef _DS1302_H_ #define _DS1302_H_ #include #include "TYPEDEF.H" // Macro definition whether it is a leap year #define LEAP_YEAR_NO 0 //Non-leap year #define LEAP_YEAR_YES 1 //Leap year
[Microcontroller]
AT89C51+DS1302+DS18B20 six-digit digital tube display clock program
#include #define uchar unsigned char #define uint unsigned int #include"DS1302.h" #include"DS18B20.h" #define sec 0x80 #define min 0x82 #define hou 0x84 #define read 0x01 unsigned char hour,minute,second,id=0,timecount,re_disp=0,p,n0,n1; bit flag; #define leddata P0 //Define the segment selection of the digital tube s
[Microcontroller]
Optimization Method of Soft Clock Design in MCS-51 Single Chip Microcomputer
0 Introduction With the popularization of microcomputer applications, microcomputer measurement and control systems with MCS-51 single-chip microcomputer as the core can be seen everywhere. To meet user requirements, these systems usually have the function of digital display clock. Since MCS-51 contains two ti
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号