STC12C2052 single chip LED dot matrix electronic clock production

Publisher:EnchantedMelodyLatest update time:2017-09-02 Source: elecfansKeywords:STC12C2052 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Design Purpose

In daily life, we see electronic clocks made of digital tubes, but LED dot matrix clocks are rare. Although dot matrix clocks have their own shortcomings, such as insufficient hardware utilization and high prices, the font of dot matrix clocks can be easily changed. As long as the program in the microcontroller is changed, the displayed font can be changed at will. The friendly font often gives people a refreshing feeling, unlike the font of ordinary LED digital tubes, which is so dull. This may be the most important feature of LED dot matrix clocks.

2. Solution

1. The structure and function of LED dot matrix electronic clock:

    1) 24-hour timekeeping.

    2) 4-digit time display, using four Φ3mm 8×8 LED dot matrices.

3) The clock is generated by the popular DS1302 real-time clock chip, which has high clock accuracy and can maintain time for one month after power failure.

4) Adopt STC12C2052 single chip microcomputer, which is convenient for hardware expansion. 24MHz crystal, high operating frequency, and the displayed numbers do not flicker!

5) The transformer is used for power supply, which is convenient for the placement of the clock. The transformer power supply voltage is 9V, and after being stabilized by the 7805 on the PCB mainboard, it outputs a stable 5V voltage with less loss.

6) Electronic button time adjustment.

7) Double-sided PCB design, the circuit is compact and powerful.

8) Red and green LEDs are available (Note: only monochrome screens are available).

9) The dot matrix screen is plugged into the PCB (optional). The default dot matrix screen is soldered to the motherboard.

10) Each unit circuit has a filter circuit, and the overall circuit works stably.

2. Main components of LED dot matrix electronic clock

Four Φ3mm 8×8 LED dot matrices, one STC12C2052 microcontroller, one DS1302 real-time clock chip, one LM7805 voltage regulator chip, one 24MHz crystal oscillator, one 9V power supply transformer, four adjustment button switches, and several other resistors, capacitors, diodes, transistors, etc.

3. Performance comparison of main components of LED dot matrix electronic clock

    1) About DS1302 clock chip:

The programming and time accuracy of the clock using the DS1302 real-time clock chip are incomparable to the clock generated directly by the single-chip microcomputer. DS1302 is a high-performance, low-power, RAM-based real-time clock chip launched by DALLAS, USA. It can count the year, month, day, weekday, hour, minute, and second, and has a leap year compensation function. The working voltage is as wide as 2.5 to 5.5V. It uses a three-wire interface to communicate synchronously with the CPU, and can use burst mode to transmit multiple bytes of clock signals or RAM data at a time. There is a 31×8 RAM register inside the DS1302 for temporary storage of data. DS1302 is an upgraded product of DS1202, which is compatible with DS1202, but adds dual power pins for main power supply/back power supply, and provides the ability to charge the back power supply with trickle current.

2) Backup power supply:

Backup power supply B1 can be a battery or supercapacitor (more than 100,000uF). Although DS1302 consumes very little power after the main power is off, if you want to keep the clock normal for a long time, it is best to use a small rechargeable battery. You can use the 3.6V rechargeable battery on the motherboard of an old computer. If the power outage time is short (a few hours or a few days), you can use a common electrolytic capacitor with less leakage instead. 100uF can ensure 1 hour of normal running time. 

3. Design

1. Electronic circuit:

    Double-sided PCB design, compact and powerful circuit

2. Program design:

  Main procedures

#include "STC12C2052AD.H"

extern void Read_Time(unsigned char ucCurtime[]);

extern void  Set_Time(unsigned char *pSecDa);

extern void Set_Charge(void);

 

sbit HC138A = P3^2;

sbit HC138B = P3^3;

sbit HC138C = P3^4;

sbit HC138EN = P3^5;

 

sbit HC595SER=P1^6;

sbit HC595RCLK=P1^5;

sbit HC595SRCLK=P1^4;

 

sbit KEY1=P1^7;

sbit KEY2=P3^7;

 

//sbit KEY1 =

//sbit KEY2 =

 

unsigned char MSecond;

unsigned char Second,Minute,Hour;

unsigned char c1,c2,c3,c4,c5;

unsigned char Time[8];

unsigned char KeyState;

unsigned char Key1On;

unsigned char Key2On;

 

unsigned char code ZF[]=

{

       0x00,0x06,0x09,0x09,0x09,0x09,0x09,0x06,

       0x00,0x02,0x06,0x02,0x02,0x02,0x02,0x07,

       0x00,0x06,0x09,0x01,0x02,0x04,0x08,0x0f,

       0x00,0x06,0x09,0x01,0x06,0x01,0x09,0x06,

       0x00,0x02,0x06,0x0a,0x0a,0x0f,0x02,0x02,

       0x00,0x0f,0x08,0x0e,0x09,0x01,0x09,0x06,

       0x00,0x06,0x09,0x08,0x0e,0x09,0x09,0x06,

       0x00,0x0f,0x01,0x01,0x02,0x04,0x04,0x04,

       0x00,0x06,0x09,0x09,0x06,0x09,0x09,0x06,

       0x00,0x06,0x09,0x09,0x07,0x01,0x09,0x06,

       0x00,0x00,0x06,0x06,0x00,0x06,0x06,0x00,

       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

};

 

void Delay(unsigned int time)

{

       unsigned int i;

       for (i=0;i

}

 

void write595(unsigned char dd)

{

       unsigned char i;

       for (i=0;i<8;i++)

       {

              HC595SER=dd&0x01;

              dd=dd/2;

              HC595SRCLK=1;

              HC595SRCLK=0;

       }

}

 

void main (void)

{

       unsigned char i;

       unsigned char z1,z2,z3;

 

 

       EA=1; // Allow CPU interrupts

       ET0=1; //Timer 0 interrupt is enabled

       TMOD=0x01; //Set timer 0 to mode 1

       TH0=0xB7;

       TL0=0xFF; //Set the time value to 20 000 μs (20 ms)

       TR0=1; //Start timing

// EA=0;    

       P1M0=0;

       P1M1=0;

      

       Set_Charge();

 

       for(i=0;i<8;i++) Time[i]=1;

 

       Set_Time(Time);

       KeyState=0;

       Key1On=0;

       Key2On=0;

 

       Read_Time(Time);

//     Second=0;

//     Minute=25;

//     Hour=22;

 

       Second=Time[0];

       Minute=Time[1];

       Hour=Time[2];

 

       c1=Minute;

       c2=Minute/16;

       c3=10;

       c4=Hour;

       c5=Hour/16;

 

       while(1)

       {

//            c1=Minute;

//            c2=Minute/10;//http://www.5imcu.net/

//            c4=Hour;

//            c5=Hour/10;

              if (KEY1==0)

              {

                     if (Key1On==0) Key1On=1;

                     else if (Key1On==1)

                     {

                            Key1On=2;

                            KeyState++;

                            if (KeyState>2)

                            {

                                   KeyState=0;

                                   Read_Time(Time);

                                   Time[1]=Minute;

                                   Time[2]=Hour;

                                   Set_Time(Time);

                            }

                     }

              }

              else Key1On=0;

 

              if (KEY2==0)

              {

                     if (Key2On==0) Key2On=1;

                     else if (Key2On==1)

                     {

                            Key2On=2;

                            if (KeyState==1)

                            {

                                   Minute++;

                                   if (Minute>9) Minute=Minute+6;

                                   if (Minute>0x59) Minute=0;

                            }

                            else if (KeyState==2)

                            {

                                   Hour++;

                                   if (Hour>9) Hour=Hour+6;

                                   if (Hour>0x23) Hour=0;

                            }

                     }

              }

              else Key2On=0;

 

      

             

              if (KeyState==0)

              {

                     Read_Time(Time);

 

                     if (Second!=Time[0])

                     {

                            c3=10;

                            MSecond=0;

                     }

                     Second=Time[0];

 

                     Minute=Time[1];

                     Hour=Time[2];

 

                     c4=Hour;

                     c5=Hour/16;

                     c1=Minute;

                     c2=Minute/16;

              }

              else

              {

                     c4=Hour;

                     c5=Hour/16;

                     c1=Minute;

                     c2=Minute/16;

              }

 

              for (i=0;i<8;i++)

              {

                     HC138EN=1;

      

                     HC595SER=0;

                     HC595RCLK=0;

                     HC595SRCLK=0;  

 

//                   write595(0xff);

//                   write595(0x35);//http://www.5imcu.net/

                    

                     z1=0xff;

                     z2=0xff;

                     z3=0xff;

 

                     if (KeyState!=2)

                     {

                            z3=z3-(ZF[8*c1+i]<<1);

                            z3=z3-(ZF[8*c2+i]<<6);

 

                            z2=z2-(ZF[8*c2+i]>>2);

                     }

                    

                     z2=z2-(ZF[8*c3+i]<<2);

                    

                     if (KeyState!=1)

                     {

                            z2=z2-(ZF[8*c4+i]<<6);

 

                            z1=z1-(ZF[8*c4+i]>>2);

                            z1=z1-(ZF[8*c5+i]<<3);

                     }

                     write595(z1);

                     write595(z2);

                     write595(z3);

 

                     HC595RCLK=1;

                     HC595RCLK=0;

                     HC595SER=0;

                     HC595SRCLK=0;

 

                     HC138A=i&0x01;

                     HC138B=i&0x02;

                     HC138C=i&0x04;

 

                     HC138EN=0;

                     Delay(300);

              }

       }

}

 

void Time0Interrupt(void) interrupt 1 using 1

{

       TH0=0xB7; //20 ms breakpoint (1)

       TL0=0xFF; //Set time value

       MSecond=MSecond+1;

       if (MSecond==15)

       {

              c3=11;

       }

}

4. Installation and debugging

Adjustment method of LED dot matrix electronic clock:

There are four adjustment buttons on the clock circuit board, namely: S1, S2, S3, S4. The adjustment method is:

K1: hours increase;

K2: Minutes increase;

K3: reset to zero in seconds;

K4: Switch the seconds display.

5. Experimental Test

1. Front view of dot matrix clock

   2. When using for the first time, after power is turned on, the clock is not running by default. To initialize the settings, press the K4 button to switch the seconds display, which will display 80 seconds; then press K3 to reset the seconds, the clock starts running, and seconds begin to accumulate.

   

6. Experimental Summary

The working process of the system is to use the STC12C2052 single-chip computer to read the clock chip DS1302, and display the time through four Φ3mm 8×8 LED dot matrices.

Through this design, I have deepened my understanding and application of the principles of single-chip microcomputers, consolidated the knowledge I learned in textbooks, and truly achieved the goal of applying what I have learned.


Keywords:STC12C2052 Reference address:STC12C2052 single chip LED dot matrix electronic clock production

Previous article:Digital tube clock made of light-emitting diode driven by single chip microcomputer
Next article:STC89C52RC MCU Ultrasonic Distance Measurement Program

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号