Design of multifunctional electronic perpetual calendar based on 51 single chip microcomputer (LCD12864+DS1302+DS18B20)

Design of multifunctional electronic perpetual calendar based on 51 single chip microcomputer (LCD12864+DS1302+DS18B20)

With the development of electronic technology, human beings continue to research and continuously set new records. The perpetual calendar is no longer limited to appearing in book form. Perpetual calendars in the form of computer software or electronic products are called electronic perpetual calendars. Compared with the traditional perpetual calendar in the form of a book, the electronic perpetual calendar has been more and more widely used, and it has become a fashion to use an electronic clock as a time display. At present, there are countless various electronic clocks on the market, but most of them are only for time display, and their single functions cannot meet people's daily needs.

This design will make an electronic perpetual calendar with real-time temperature display and timing function based on single-chip microcomputer control. Traditional electronic calendars are mostly large in size, high in power consumption, and inaccurate in display. In order to reduce the volume, reduce the power consumption, and make it compact and sensitive, this design adds the clock chip DS1302, which can accurately record the time, and can set the timing time to realize the timing function. In addition, this design has the function of displaying real-time temperature. Traditional temperature sensor systems mostly use amplification, conditioning, and A/D conversion. The converted digital signals are sent to the computer for processing. The processing circuit is complex, the reliability is relatively poor, and the computer resources are relatively large. This design will use DS18B20 one-wire digital temperature sensor, which can directly convert the temperature signal into a digital signal and send it to the microprocessor. The circuit is simple, the cost is low, and the effect of simultaneous display of time and temperature is realized. Finally, the temperature and time will be displayed on the 12864 LCD. The test shows that the system has reached the functions required by the design, and all parts are working normally.

Article Directory


# Summary

This design will make an electronic perpetual calendar with real-time temperature display and timing function based on single-chip microcomputer control. Traditional electronic calendars are mostly large in size, high in power consumption, and inaccurate in display. In order to reduce the volume, reduce the power consumption, and make it compact and sensitive, this design adds the clock chip DS1302, which can accurately record the time, and can set the timing time to realize the timing function. In addition, this design has the function of displaying real-time temperature. Traditional temperature sensor systems mostly use amplification, conditioning, and A/D conversion. The converted digital signals are sent to the computer for processing. The processing circuit is complex, the reliability is relatively poor, and the computer resources are relatively large. This design will use DS18B20 one-wire digital temperature sensor, which can directly convert the temperature signal into a digital signal and send it to the microprocessor. The circuit is simple, the cost is low, and the effect of simultaneous display of time and temperature is realized. Finally, the temperature and time will be displayed on the 12864 LCD. The test shows that the system has reached the functions required by the design, and all parts are working normally.
Keywords: Clock temperature detection MCU temperature LCD12864 DS1302

1 Introduction

1.1 Development background of perpetual calendar

With the development of electronic technology, human beings continue to research and continuously set new records. The perpetual calendar is no longer limited to appearing in book form. Perpetual calendars in the form of computer software or electronic products are called electronic perpetual calendars. Compared with the traditional perpetual calendar in the form of a book, the electronic perpetual calendar has been more and more widely used, and it has become a fashion to use an electronic clock as a time display. At present, there are countless various electronic clocks on the market, but most of them are only for time display, and their single functions cannot meet people's daily needs.

1.2 Current status and development at home and abroad

With the rapid development of electronic technology, especially with the appearance of large-scale integrated circuits, it has brought fundamental changes to human life. Especially the application products of single-chip technology have entered thousands of households. The emergence of the electronic perpetual calendar brings many conveniences to people's lives.
The LCD used in the perpetual calendar has a wide range of applications, such as liquid crystal displays on watches, liquid crystal displays on instruments, or liquid crystal displays on computer notebooks. LCDs are all used. It is also common in general office equipment, such as fax machines, photocopiers, and some entertainment equipment and toys, and often see the footprint of LCD. Character type liquid crystal display module is a kind of dot matrix type liquid crystal display module specially used to display letters, numbers, symbols, etc. In the design of the display device, it is composed of several 5 7 or 5 11 dot matrix symbols. Each dot matrix character bit can display a character. There is a space between dot matrix character bits to play the role of character spacing and line spacing. Currently on the market, there are 16 characters 1 line, 16 characters 2 lines, 20 characters 2 lines, and 40 characters 2 lines. Although these LCDs display different numbers of characters, they all have the same input and output interface.
With the development of single-chip microcomputers, electronic perpetual calendars have shown a trend of miniaturization and enrichment of functions, and the price has been declining. Taking into account resource issues, the current design and design of perpetual calendars have adopted energy-saving design solutions. Perpetual calendars have a great impact on people's lives. It plays an important role, so the electronic perpetual calendar still has great development prospects.

2 Selection and demonstration of the basic scheme of the system

2.1 Selection scheme and demonstration of single-chip microcomputer chip

Solution 1:
Using 89C51 chip as the hardware core, 89C51 is a flashing programmable and erasable read-only memory with 4K bytes, using Flash ROM, 4KB ROM storage space inside, can work at 3V ultra-low voltage, and is compatible with MCS -51 series single-chip microcomputers are fully compatible with industry standard MCS-51 instruction set and output pins. Because the multifunctional 8-bit CPU and flash memory are combined in a single chip, 89C51 is a highly efficient microcontroller. 51 single-chip microcomputer provides a flexible and inexpensive solution for many embedded control systems, but it is used in circuit design. Since the middle time does not have in-line programming (ISP) technology, when debugging the circuit, when the program needs to be burned into the program due to the wrong modification of the program or the new function of the program, the chip may be removed and inserted for many times. The damage of this type of chip has been discontinued.
Solution 2:
Use AT89S52 single-chip microcomputer. AT89S52 single-chip microcomputer is a single-chip microcomputer produced by ATMEL. It is a new generation of 8051 single-chip microcomputer, and the instruction code is fully compatible with traditional 8051. The watchdog circuit is integrated inside. There is 8KB of program Flash memory inside AT89S52 microcontroller. Since the perpetual calendar programming file we designed is about 7KB, and the program Flash of the AT89S52 single-chip microcomputer is 8KB, there is no need for an external program memory.

After comprehensive comparison, the second option is finally selected, that is, AT89S52 is selected as the main controller.

2.2 Selection scheme and demonstration of display module

Solution 1:
LCD12864 liquid crystal is a dot matrix graphic liquid crystal display module with 8-bit parallel interface; its display resolution is 128 64. Utilizing the flexible interface mode and simple and convenient operation instructions of this module, a full Chinese human-computer interactive graphical interface can be formed. It can display 16 16 dot matrix Chinese characters, and can also complete graphic display. Low voltage and low power consumption are another notable feature. Compared with the same type of graphic dot matrix liquid crystal display module, the liquid crystal display solution composed of this module is much more concise regardless of the hardware circuit structure or the display program. The perpetual calendar requires the display of the year, month, day, hour, minute, second, day of the week, and lunar calendar. LCD12864 liquid crystal can complete the design requirements.
Scheme 2: The
system adopts LED display. LED applications can be divided into two categories: one is LED single tube applications, including backlight LEDs, infrared LEDs, etc.; the other is LED displays. At present, there is still a certain gap between China and the international in LED basic material manufacturing, but As far as LED displays are concerned, the level of design and production technology in China is basically in line with the international level. The LED display is a display device composed of light-emitting diodes arranged in an array. It adopts low-voltage scanning drive, and has the characteristics of low power consumption, long service life, low cost, high brightness, low failure, large viewing angle, and long visual distance. Using LED digital tube dynamic scanning. The price is more economical, but it can't display text, and the cost performance is not very high. The operation is slightly cumbersome compared to LCD display, so it is not used as a display.
After a comprehensive comparison, the final option is to choose LCD12864 LCD.

2.3 Selection scheme and demonstration of clock chip

Option 1:
Using single-chip timing. The single-chip microcomputer has a series of advantages such as high integration, strong function, high reliability, small size, low power consumption, convenient use, and low price. The application field of single-chip microcomputer has been rapidly developed from industrial control, communication, transportation, intelligent instrument, etc. to household Consumer products, office automation, automotive electronics, PC peripherals and network communications and other broad fields.
The single-chip timing counter is directly used to provide the second signal, the counted pulse is provided by the outside, and the timing pulse is provided by the external crystal oscillator. The period of timing plus 1 is a machine cycle; the timing time is related to the initial value and the crystal oscillator frequency. Use the program to count the year, month, day, week, hour, minute, and second. Adopt this kind of scheme to reduce the use of the chip, save the cost, but the complexity of the procedure is higher.
Scheme 2:
Adopt DS1302 clock chip. DS1302 is a high-performance, low-power, RAM-equipped real-time clock circuit introduced by DALLAS in the United States. It can time the year, month, day, week, hour, minute, and second, and has a leap year compensation function. The operating voltage is 2.5V 5.5V. It adopts dual power supply (main power supply and backup power supply), can set backup power supply charging mode, and provides the ability to trickle current charging to the back power supply. DS1302 is used for data recording, especially for the recording of certain data points with special significance. It can record the data and the time when the data appears at the same time, so it is widely used in measurement systems. A three-wire interface is used for synchronous communication with the CPU, and multiple bytes of clock signals or RAM data can be transmitted at a time in a burst mode. There is a 31 8 RAM register for temporarily storing data inside DS1302. Using DS1302 only needs to write out the driver program, call the program to read out the data in the register, and then output the perpetual calendar data after a simple transformation.
After comprehensive comparison, the second option is finally selected, that is, the DS1302 clock chip is used.

2.4 Selection and demonstration of temperature sensor

Option 1:
Use thermistor as the temperature sensor. Thermistor is a sensitive component that has been developed early, with many types and more mature development. The thermistor is composed of semiconductor ceramic materials, and the principle used is that temperature causes resistance to change. The main features of thermistors are: high sensitivity, the temperature coefficient of resistance is more than 10-100 times larger than metal; wide operating temperature range, normal temperature devices are suitable for -55 315 , high temperature devices are suitable for higher than 315 (Currently the highest can reach 2000 ) Low temperature device is suitable for -273 ~ 55 ; small size, can measure the temperature of voids, cavities and blood vessels in organisms that other thermometers cannot measure; easy to use, resistance value can be 0.1-100k Choose between arbitrarily; easy to process into complex shapes, mass production; good stability, strong overload capacity. Due to the unique performance of semiconductor thermistors, it can not only be used as measuring components (such as measuring temperature, flow, liquid level, etc.), but also as control components (such as thermal switches, current limiters) and circuit compensation in applications element. Thermistors are widely used in various fields such as household appliances, electric power industry, communications, military science, aerospace, etc., and their development prospects are extremely broad.
Use the thermistor as the sensor, use the thermistor and a corresponding resistance resistor to divide the voltage in series, use the characteristic that the thermistor resistance changes with temperature, collect the divided voltage values of the two resistance changes, and perform A/D conversion. This design scheme requires the use of an A/D conversion circuit, which increases the hardware cost and the temperature-sensing characteristic curve of the thermistor is not strictly linear, which will cause a large measurement error.
Option II:
Adopt DS18B20 temperature sensor. In applications with high precision and high reliability, the DS18B20 temperature sensor produced by DALLAS (Dallas) will take care of it. Ultra-small size, ultra-low hardware cancellation, strong anti-interference ability, high precision, and strong additional functions make DS18B20 more popular. For our ordinary electronic enthusiasts, the advantages of DS18B20 are our best choice for learning microcontroller technology and developing temperature-related small products. This is the world's first temperature sensor that supports the "one-wire bus" interface. DS18B20 digital thermometer provides 9-bit (binary) temperature reading, indicating the temperature of the device. Information is sent to DS18B20 or sent from DS18B20 through a single-wire interface, so only one wire connection is required from the single-chip microcomputer to DS18B20. It can convert the temperature into a number within 1 second (typical value).
After a comprehensive comparison, the final choice is the second option, that is, the DS18B20 temperature sensor is adopted.

2.5 The final scheme of circuit design is determined

Finally, the microcontroller AT89S52 is selected as the main controller; LCD12864 LCD is selected as the display module. This module can display letters, numbers, symbols, Chinese characters and graphics, and has the function of drawing and text screen mixed display, which can realize the design of "year", " The display requirements of the five words "month", "day", "indoor temperature" and "degree"; choose to use the DS1302 clock chip to make the program realize the display of year, month, day, week, hour, minute, and second. The DS18B20 temperature sensor can be used to measure the temperature accurately, and only one IO is needed to communicate with the single-chip microcomputer, which is convenient for connection.

3 System hardware circuit design

3.1 System function module division and overall circuit diagram

According to the system function requirements, the block diagram of the hardware structure required by the system can be roughly drawn as shown in Figure 3-1-1:

Figure 3-1-1 System function module diagram

The main control module adopts the cost-effective AT89S52 single-chip microcomputer chip, and the program is programmed in it, and the temperature measurement module can be controlled by the operation of the program to measure temperature; the temperature measurement module is mainly composed of DS18B20, and it is in contact with the measured object The temperature data of the measured object can be obtained, and the measured temperature and the real-time calendar measured by the clock chip will be displayed in digital form through the liquid crystal display of the display module; the microcontroller calls the program and reads the DS1302 internal registers to obtain the perpetual calendar Time data can be output on the LCD after program processing; the keyboard circuit can adjust the real-time calendar; the buzzer can be used as a sound reminder in the alarm clock timing.
The overall circuit diagram of the work is shown in Figure 3-1-2

Figure 3-1-2 Overall circuit diagram

3.2 Functional analysis of each unit module and module circuit design

3.2.1 Clock module

The working principle of DS1302 and the interface of single chip microcomputer:
DS1302 is a real-time clock chip of American DALLAS company. The main feature is that it adopts serial data transmission, can provide programmable charging function for power failure protection power, and can turn off the charging function. Use 32.768Hz crystal oscillator. It can time the year, month, day, week, hour, minute, and second, and has multiple functions such as leap year compensation. DS1302 is used for data recording, especially for the recording of certain data points with special significance, which can realize the simultaneous recording of data and the time when the data appears. This recording is of great significance to the analysis of the results of the long-term continuous measurement and control system and the search for the causes of abnormal data. In this design, its actual circuit diagram is shown in Figure 3-2:

Figure 3-2 The connection between DS1302 and single-chip microcomputer
DS1302 requires an external 32.768K crystal oscillator, pin 1 is connected to the main power supply VCC (5V) power supply, pin 8 is connected to the backup battery (3V), when the main power supply is powered off, the backup power supply is DS1302 provides power to keep the data in DS1302 from being lost, which is exactly the necessary characteristic of the clock chip.

3.2.2 Temperature module

Traditional temperature sensor systems mostly use amplification, conditioning, and A/D conversion. The converted digital signal is sent to the computer for processing. The processing circuit is complex, the reliability is relatively poor, and it takes up a lot of computer resources. The temperature measurement module of this design uses first-line The DS18B20 digital temperature sensor can directly convert the temperature signal into a digital signal and send it to the microprocessor. The circuit is simple and the cost is low. The circuit schematic diagram is shown in Figure 3-3:

Figure 3-3 DS18B20 temperature module
It can be seen from the figure that the one-wire bus of the temperature sensor is connected to the main control chip STC12C5A6S2 of this design through port 2 and the port number is DS18B20 to realize mutual communication. The temperature measuring element in the design uses the DS18B20 temperature measuring element, which is a temperature sensor produced by DALLAS (Dallas). Ultra-small size, ultra-low hardware cancellation, strong anti-interference ability, high precision, and strong additional functions make DS18B20 very popular. This is the world's first temperature sensor that supports the "one-wire bus" interface. DS18B20 digital thermometer provides 9-bit (binary) temperature reading, indicating the temperature of the device. Information is sent to DS18B20 or sent from DS18B20 through a single-wire interface, so only one wire connection is required from the single-chip microcomputer to DS18B20. It can convert the temperature into a number within 1 second (typical value).

3.2.3 Display module

The display module of this design mainly adopts LCD12864 liquid crystal display, and its circuit schematic diagram is as follows:

Figure 3-5 LCD12864 module
LCD12864 liquid crystal display is connected to the I/O port P3 of the main control chip AT89S52 through the data port, namely ports 7 to 14, to realize the transmission of data and instructions, and then through the control ports RS, RW, EN, which are ports 4 6 are connected with the main control chip P1.5, P1.6, P1.7 port to realize the control of data and instruction transmission. The display module adopts 12864 liquid crystal display to realize the direct display of temperature and time, which is clear and clear.

3.2.4 Independent keyboard module

The keyboard is the interface between people and the perpetual calendar to realize information interaction. In this design, we use 3 independent keyboards. The circuit principle is as shown in Figure 3-9:

Figure 3-9 Independent keyboard
When the key is pressed, the port connected to the main control chip is reduced to low level, and when the key is released, it also rises to high level. The button uses the Tack Switch button switch, which has an automatic recovery (bounce) function. When we press the button, the contact is turned on (or cut off), and when the button is released, the contact returns to cut off (or on). According to the size distinction, the Tack Swith used in electronic circuits or microcomputers can be divided into 8mm, 10mm, 12mm, etc. Although the Tack Switch has 4 pins, in fact, there is only a pair of a contacts inside, that is, two of the pins are internally connected, and the other two pins are also connected internally. The 3 buttons realize functions such as power-on mode selection, date adjustment, etc. The introduction of independent buttons makes the design of humanity, intelligence, and powerful.

3.2.5 Buzzer module

The buzzer module is another design highlight that reflects the human-computer interaction in this design. The circuit schematic diagram is as follows

Figure 3-10 Buzzer module In
this design, we use an active buzzer. Because the working current of the buzzer is generally large, so that the I/O port of the single-chip microcomputer cannot be directly driven, so an amplifying circuit is used. To drive, we use a transistor to amplify the current and drive the buzzer. This module only needs to use the PWM wave input by the BELL (connected to the MCU P2.7) to make the buzzer separate the sound. This perpetual calendar we designed can Used as a sound reminder signal in the alarm timer.

4 System software design

4.1 Flow chart of perpetual calendar software system

Figure 4-1 System software flow chart
When the power is turned on and the program starts to run, the program in the microcontroller will start to initialize the DS18B20 in order to reach a communication agreement with the microcontroller chip. After the initialization is completed, because the system has only one temperature measurement element, the single-chip microcomputer will issue a skip RAM instruction to it, and then it can send an operation instruction to start the temperature measurement program. After the temperature measurement process is completed, a temperature conversion instruction will be issued, thereby The temperature can be converted into a digital mode for display and reading; meanwhile, DS1302 will read the hour, minute, second, week, and year, month, and day registers and then display real-time time, week, and date through the LCD; keys in the keyboard circuit can adjust the real-time calendar clock.

4.2 The program part of the perpetual calendar software system

DS1302 program code

/* * DS1302 clock chip */ # include "DS1302.h" //include header file /* * Write a byte */ void write_ds1302_byte (uint8 dat) { uint8 i; for (i = 0 ; i< 8 ; i++) //loop 8 times {SDA = dat & 0x01 ; SCK = 1 ; //SCK port is set dat >>= 1 ; SCK = 0 ; //SCK port is set to 0 } } /* * Read a byte */ uint8 read_ds1302_byte ( void ) { uint8 i, dat = 0 ; for (i = 0 ; i< 8 ; i++) //loop 8 times { dat >>= 1 ; if (SDA) dat |= 0x80 ; SCK = 1 ; //SCK port is set to 1 SCK = 0 ; //SCK port is set to 0 } return dat; } void reset_ds1302 ( void ) { RST = 0 ; //RST port is set to 0 SCK = 0 ; //SCK port is set to 0 RST = 1 ; //RST port is set to 1 } /* * Clear write protection */ void clear_ds1302_WP ( void ) { reset_ds1302(); RST = 1 ; //RST port is set write_ds1302_byte( 0x8E ); write_ds1302_byte( 0 ); SDA = 0 ; //SDA port is set to 0 RST = 0 ; //RST port is set to 0 } /* * Set write protection */ void set_ds1302_WP ( void ) { reset_ds1302(); //Reset 1302 RST = 1 ; //RST port is set to 1 write_ds1302_byte( 0x8E ); write_ds1302_byte( 0x80 ); SDA = 0 ; //SDA port is set to 0 RST = 0 ; //RST port is set to 0 } /* * Set clock data (seconds, minutes, hour, day, month, anniversary) */ void set_time (uint8 *timedata) { uint8 i, tmp, tmps[ 7 ]; for (i = 0 ; i< 7 ; i++) //Convert to BCD format { tmp = timedata[i]/10 ; tmps[i] = timedata[i]% 10 ; tmps[i] = tmps[i] + tmp* 16 ; } clear_ds1302_WP(); //Cancel write protection reset_ds1302(); //Reset chip RST = 1 ; //RST port is set to 1 write_ds1302_byte(DS1302_W_ADDR); for (i = 0 ; i< 7 ; i++) //loop 7 times { write_ds1302_byte(tmps[i]); delay( 10 ); //delay } write_ds1302_byte( 0 ); SDA = 0 ; //SDA port is set to 0 RST = 0 ; //RST port is set to 0 set_ds1302_WP(); //Set write protection } /* * Read clock data (second, minute, hour, day, month, anniversary) */ void read_time (uint8 *timedata) { uint8 i, tmp; clear_ds1302_WP(); //Cancel write protection reset_ds1302(); //Reset chip RST = 1 ; //ST port is set to 1 write_ds1302_byte(DS1302_R_ADDR); for (i = 0 ; i< 7 ; i++) //loop 7 times { timedata[i] = read_ds1302_byte(); delay( 10 ); //delay } SDA = 0 ; //SDA port is set to 0 RST = 0 ; //RST port is set to 0 set_ds1302_WP(); //Set write protection for (i = 0 ; i< 7 ; i++) //loop 7 times { tmp = timedata[i]; timedata[i] = (tmp/16 % 10 )* 10 ; timedata[i] += (tmp% 16 ); } } Copy code

LCD12864 program code

/* * LCD128*64 */ # include "LCD.h" # include "word.h" # define Page_Add 0xb8 # define Col_Add 0x40 # define Disp_On 0x3f # define Disp_Off 0x3e # define Start_Line 0xc0 /* * 12864 sentenced busy */ void chekbusy12864 ( void ) { uint8 dat; RS = 0 ; //Command mode RW = 1 ; //Read data do { P3 = 0 ; E = 1 ; //E port is set to 1 _nop_(); //Delay 1us dat = P3 & 0x80 ; E = 0 ; //E port is set to 0 } while (dat != 0 ); } /* * 12864 chip selection * i: 0 is the left screen, 1 is the right screen, 2 is the dual screen */ void choose12864 (uint8 i) { switch (i) { case 0 : CS1 = 0 ; CS2 = 1 ; break ; //chip select left screen case 1 : CS1 = 1 ; CS2 = 0 ; break ; //chip select right screen //case 2: CS1 = 0; CS2 = 0 ; break; default : break ; //Exit } } /* * Write command */ void cmd_w12864 (uint8 cmd) { chekbusy12864(); RS = 0 ; //RS port is set to 0 RW = 0 ; //RW port is set to 0 _nop_(); //Delay 1us E = 1 ; //E port is set to 1 _nop_(); //Delay 1us P3 = cmd; _nop_(); //Delay 1us E = 0 ; //E port is set to 0 } /* * Write data */ void dat_w12864 (uint8 dat) { chekbusy12864(); RS = 1 ; //RS port is set to 1 RW = 0 ; //RW port is set to 0 _nop_(); //delay 1us E = 1 ; //E port is set to 1 _nop_(); //delay 1us P3 = dat; _nop_(); //Delay 1us E = 0 ; //E port is set to 0 } /* * Clear screen */ void clear12864 ( void ) { uint8 page,row; choose12864( 0 ); for (page = 0 ; page< 8 ; page++) { cmd_w12864( 0xb8 +page); cmd_w12864( 0x40 ); for (row = 0 ; row< 64 ; row++) { dat_w12864( 0x00 ); //write data 0 } } choose12864( 1 ); for (page = 0 ; page< 8 ; page++) { cmd_w12864( 0xb8 +page); cmd_w12864( 0x40 ); for (row = 0 ; row< 64 ; row++) { dat_w12864( 0x00 ); //write data 0 } } } /* * LCD initialization */ void LCD_init ( void ) { chekbusy12864(); cmd_w12864( 0xc0 ); //display from line 0 cmd_w12864( 0x3f ); //LCD displays the contents of RAM clear12864(); } /* * 8x16 character display */ void play8 (uint8 x, uint8 y, uint8 *addr) { uint8 i; if (x> 63 ) { choose12864( 1 ); x = x -64 ; } else { choose12864( 0 ); } cmd_w12864( 0x40 |x); cmd_w12864( 0xb8 |(y++)); if ((y & 0x80 ) == 0 ) for (i = 0 ;i< 8 ;i++) dat_w12864(*addr++); else for (i = 0 ;i< 8 ;i++) dat_w12864 ( 0xFF - * addr ++); cmd_w12864( 0x40 |x); cmd_w12864( 0xb8 |y); if ((y & 0x80 ) == 0 ) for (i = 0 ;i< 8 ;i++) dat_w12864(*addr++); else for (i = 0 ;i< 8 ;i++) dat_w12864 ( 0xFF - * addr ++); } /* * 16x16 display */ void play16 (uint8 x, uint8 y, uint8 *addr) { uint8 i; if (x> 63 ) { choose12864( 1 ); x = x -64 ; } else { choose12864( 0 ); } cmd_w12864( 0x40 |x); cmd_w12864( 0xb8 |(y++)); if ((y & 0x80 ) == 0 ) for (i = 0 ; i< 16 ; i++) dat_w12864(*addr++); else for (i = 0 ; i< 16 ; i++) dat_w12864 ( 0xFF - * addr ++); cmd_w12864( 0x40 |x); cmd_w12864( 0xb8 |y); if ((y & 0x80 ) == 0 ) for (i = 0 ; i< 16 ; i++) dat_w12864(*addr++); else for (i = 0 ; i< 16 ; i++) dat_w12864 ( 0xFF - * addr ++); } /* * 16*32 character display */ void play32 (uint8 x, uint8 y, uint8 num) { uint8 i, j, *addr; addr = Num + num* 64 ; if (x> 63 ) { choose12864( 1 ); x = x -64 ; } else { choose12864( 0 ); } for (j = 0 ; j< 4 ; j++) { cmd_w12864( 0x40 |x); cmd_w12864( 0xb8 |(y++)); if ((y & 0x80 ) == 0 ) for (i = 0 ; i< 16 ; i++) dat_w12864(*addr++); else for (i = 0 ; i<16 ; i++) dat_w12864( 0xFF - * addr ++); } } /* * 8x16 digital display */ void play8_num (uint8 x, uint8 y, uint8 num) { play8(x, y, &S_num[ 16 *(num/10 % 10 )]); play8(x + 8 , y, &S_num[ 16 *(num% 10 )]); } /* * 16x32BCD digital display */ void play32_num (uint8 x, uint8 y, uint8 num) { play32(x, y, num/10 % 10 ); play32(x + 16 , y, num% 10 ); } void play_week (uint8 x, uint8 y, uint8 num) { switch (num) { case 1 : play16(x + 32 , y, zhou_yi); break ; case 2 : play16(x + 32 , y, zhou_er); break ; case 3 : play16(x+ 32 , y, zhou_san); break ; case 4 : play16( x + 32 , y, zhou_si); break ; case 5 : play16(x+ 32 , y, zhou_wu); break ; case 6 : play16(x+ 32 , y, zhou_liu); break ; case 7 : play16(x+32 , y, zhou_qi); break ; default : break ; } } //************************************************ ************************/ //Function: LCD_Delay() //Description: Delay t ms function //Parameters: t //Return: None //Remark: 11.0592MHZ t=0 Delay time is about 13us //Version: 2011/01/01 First version //********************** **************************************************/ void LCD_Delay_us ( unsigned int t) { while (t--); } //************************************************ ************************/ //Function: LCD_Delay() //Description: Delay t ms function //Parameters: t //Return: None //Remark: 11.0592MHZ t=1 Delay time is about 1ms //Version: 2011/01/01 First version //********************** **************************************************/ void LCD_Delay_ms ( unsigned int t) { unsigned int i,j; for (i = 0 ;i<t;i++) for (j = 0 ;j< 113 ;j++) ; } Copy code

Main interface frame display and setting page

/* * Main interface frame */ void main_frame ( void ) { play32( 80 , 2 , 10 ); //display the number play32( 32 , 2 , 10 ); //display the number play16( 17 , 0 , hanzi_nian); //display the slash play16( 49 , 0 , hanzi_yue); //Display slash play16( 80 , 0 , hanzi_ri); //Display slash play16( 0 , 6 ,hanzi_si); play16( 16 , 6 ,hanzi_nei); play16( 32 , 6 ,hanzi_wen); play16( 48 , 6 ,hanzi_du); play16( 112 , 6 ,hanzi_du); //display degree } /* * Main interface */ void main_show (bit refresh) { //uint8 lunar[2]; if (refresh) read_time((uint8 *)&time); //read time function//time if (refresh || (time.sec != tmp_time.sec)) //second update { tmp_time.sec = time.sec; //Read second data play8_num( 96 , 6 ,zhengshu); //Temperature display play32_num( 96 , 2 , time.sec); //Display seconds } if (refresh) main_frame(); //Refresh the interface if (refresh || (time.min != tmp_time.min)) //Sub-update { if (!refresh) flag = 0 ; tmp_time.min = time.min; //Read the minutes play32_num( 48 , 2 , time.min); //Display the minutes } if (refresh || (time.hour != tmp_time.hour)) //time update { if ((!refresh)&&(Clock_flag)) alarm_sound(); tmp_time.hour = time.hour; //when reading play32_num( 0 , 2 , time.hour); //when displaying } if (refresh || (time.day != tmp_time.day)) //day update { tmp_time.day = time.day; //Read the day play8_num( 64 , 0 , time.day); //Display the day //Lunar calendar turn_lunar_calendar(&time, lunar); play_lunar_calendar( 0 , 6 , lunar[ 0 ], lunar[ 1 ]); } if (refresh || (time.week != tmp_time.week)) //Weekly update { tmp_time.week = time.week; //Read the week play_week( 140 , 0 , time.week); //Display the week } if (refresh || (time.mon != tmp_time.mon)) //monthly update { tmp_time.mon = time.mon; //Read the month play8_num( 32 , 0 , time.mon); //Display month //Lunar calendar turn_lunar_calendar(&time, lunar); //Convert lunar year play_lunar_calendar( 0 , 6 , lunar) [ 0 ], lunar[ 1 ]); //Display the lunar year } if (refresh || (time.year != tmp_time.year)) //year update { tmp_time.year = time.year; //Read the year data play8_num( 0 , 0 , time.year); //Display the year //Lunar calendar turn_lunar_calendar(&time, lunar); //Convert the lunar calendar year play_lunar_calendar( 0 , 6 , lunar[ 0 ], lunar[ 1 ]); //Display the lunar year } } /* * Host interface settings */ void main_set ( void ) { int8 key_val, state = 1 ; //variable play32_num( 96 , 2 | 0x80 , time.sec); //display seconds while ( 1 ) {key_val = scan_key(); //Keyboard scan if (key_val == 1 ) //Set { if (state >= 7 ) state = 0 ; else state++; //position state plus 1 set_time((uint8 *)&time); //set time main_show( 1 ); //display the main interface switch (state) { case 0 : set_time((uint8 *)&time); break ; //Set time case 1 : play32_num( 96 , 2 | 0x80 , time.sec); break ; //Display seconds case 2 : play32_num( 48 , 2 | 0x80 , time.min); break ; //display case 3 : play32_num( 0 , 2 | 0x80 , time.hour); break ; //display case 4 : play_week( 140 , 0 | 0x80 , time.week); break ; //Display week case 5 : play8_num( 64 , 0 | 0x80 , time.day); break ; //Display day case 6 : play8_num( 32 , 0 | 0x80 , time. mon); break ; //display month case 7 : play8_num( 0 , 0 | 0x80 , time.year); break ; //display year default : break ; //exit the loop } } else if (key_val> 1 ) //Key value is greater than 1 { if (key_val == 4 ) { state = 0 ; clear12864(); //Clear the screen main_show( 1 ); //Main interface } if (state == 1 )//position 1 set seconds { if (key_val == 3 ) //Add press? time.sec++; //second plus 1 else if (key_val == 2 ) time.sec--; //seconds minus 1 if (time.sec >= 60 ) time.sec = 0 ; else if (time.sec < 0 ) time.sec = 59 ; play32_num( 96 , 2 | 0x80 , time.sec); //Display seconds } else if (state == 2 ) //position 2 setting points { if (key_val == 3 ) //Add press? time.min++; //Add 1 else if (key_val == 2 ) time.min--; //Subtract 1 if (time.min >= 60 ) time.min = 0 ; else if (time.min < 0 ) time.min = 59 ; play32_num( 48 , 2 | 0x80 , time.min); //Display minutes } else if (state == 3 ) //When position 3 is set { if (key_val == 3 ) //Add press? time.hour++; //add 1 else if (key_val == 2 ) time.hour--; //Subtract 1 if (time.hour >= 24 ) time.hour = 0 ; else if (time.hour < 0 ) time.hour = 23 ; play32_num( 0 , 2 | 0x80 , time.hour); //When displaying } else if (state == 4 ) //position 4 set week { if (key_val == 3 ) //Add press? time.week++; //Add 1 else if (key_val == 2 ) time.week--; //Subtract 1 if (time.week >= 8 ) time.week = 1 ; else if (time.week < 1 ) time.week = 7 ; play_week( 140 , 0 | 0x80 , time.week); //Display week } else if (state == 5 ) //position 5 setting day { if (key_val == 3 ) //Add press? time.day++; //add 1 else if (key_val == 2 ) time.day--; //minus 1 if (time.day >= 32 ) time.day = 1 ; else if (time.day < 1 ) time.day = 31 ; play8_num( 64 , 0 | 0x80 , time.day); //Display day } else if (state == 6 ) //position 6 set month { if (key_val == 3 ) //Add press? time.mon++; //add 1 else if (key_val == 2 ) time.mon--; //Subtract 1 if (time.mon >= 13 ) time.mon = 1 ; else if (time.mon < 1 ) time.mon = 12 ; play8_num( 32 , 0 | 0x80 , time.mon); //Display month } else if (state == 7 ) //Set the year at position 7 { if (key_val == 3 ) //Add press? time.year++; //add 1 else if (key_val == 2 ) time.year--; //Subtract 1 if (time.year >= 100 ) time.year = 0 ; //0 year else if (time.year < 0 ) time.year = 99 ; //99 years play8_num( 0 , 0 | 0x80 , time.year); //display year } else { break ; //Exit the loop } } if (state == 0 ) break ; //Exit the loop } } Copy code

Alarm clock interface display

/* * Alarm clock interface display */ void alarm_show ( void ) { int8 key_val, state = 1 ; uint32 t = 0 ; play16( 16 , 0 , nao); //display alarm play16( 32 , 0 , zhong); //clock play16( 48 , 0 , hanzi_she); play16( 64 , 0 , hanzi_ding); play16( 80 , 0 , hanzi_ye); play16( 96 , 0 , hanzi_mian); play16( 0 , 2 , nao); //display alarm play16( 16 , 2 , zhong); //clock play16( 32 , 2 , maohao); //colon: if (Alarm_flag) play16( 48 , 2 , kai); //open else play16( 48 , 2 , guan); //close play8_num( 80 , 2 , alarm.hour); //hour play8( 96 , 2 , maohao1); //Colon play8_num( 104 , 2 , alarm.min); //Divided play16( 0 , 4 , zheng); //Display the whole play16( 16 , 4 , dian); //Display point play16( 32 , 4, bao); //Display the report play16( 48 , 4 , shi); //When displaying play16( 64 , 4 , maohao); //Display the colon play16( 0 , 6 , hanzi_she); //Display the whole play16( 16 , 6 , hanzi_ding); //Display point play16( 32 , 6 , hanzi_wen); //Display report play16( 48 , 6 , hanzi_du); //When displaying play16( 64 , 6 , maohao); //Display colon play8_num ( 80 , 6,shedingwendu); play16( 96 , 6 , hanzi_du); //display degree if (Clock_flag) play16( 80 , 4 , kai); //display on else play16( 80 , 4 , guan); //display off for (t = 0 ; t< 30000 ; t++) { key_val = scan_key(); //Key value obtained by keyboard scan if (key_val> 1 ) //Judgment data break ; if (key_val == 4 ) //Judgment data { clear12864(); //Clear the screen main_show( 1 ); //Main interface } else if (key_val == 1 ) //Judgment data { if (Alarm_flag) play16( 48 , 2 | 0x80 , kai); //show on else play16( 48 , 2 | 0x80 , guan); //off while ( 1 ) { key_val = scan_key(); //Keyboard scan to get the key value if (key_val == 1 ) //Complete the setting { if (state >= 5 ) //Judgment data state = 0 ; else state++; if (Alarm_flag) play16( 48 , 2 , kai); //display on else play16( 48 , 2 , guan); //display off play8_num( 80 , 2 , alarm.hour); //display when alarming play8_num( 104 , 2 , alarm .min); //Alarm clock minute display if (Clock_flag) play16( 80 , 4 , kai); //display on else play16( 80 , 4 , guan); //display off switch (state) //Judgment data { case 1 : if (Alarm_flag) //Judgment data play16( 48 , 2 | 0x80 , kai); //Display on else play16( 48 , 2 | 0x80 , guan); //Display off break ; case 2 : play8_num( 104 , 2 | 0x80 , alarm.min); //The alarm minute display break ; case 3 : play8_num( 80 , 2 | 0x80 , alarm.hour); //display break when alarming ; case 4 : if (Clock_flag) //judgment data play16( 80 , 4 | 0x80 , kai); //display on else play16( 80 , 4 | 0x80 , guan); //show off break ; case 5 : play8_num( 80 , 6 | 0x80 , shedingwendu); default : break ; } } else if (key_val> 1 ) //Judgment data { if (state == 1 ) //Judgment data { Alarm_flag = ~Alarm_flag; if (Alarm_flag) play16( 48 , 2 | 0x80 , kai); //display on else play16( 48 , 2 | 0x80 , guan); //display off } else if (state == 2 ) //Judgment data { if (key_val == 3 ) //Judgment data alarm.min++; //Add 1 else if (key_val == 2 ) alarm.min--; //Decrease 1 if (alarm.min >= 60 ) //Judgment data alarm.min = 0 ; else if (alarm.min < 0 ) //Judgment data alarm.min = 59 ; play8_num( 104 , 2 | 0x80 , alarm.min); //Alarm minute display } else if (state == 3 ) //Judgment data { if (key_val == 3 ) //Judgment data alarm.hour++; //Add 1 else if (key_val == 2 ) alarm.hour--; //Subtract 1 if (alarm.hour >= 24 ) //Judging data alarm.hour = 0 ; else if (alarm.hour < 0 ) //Judging data alarm.hour = 23 ; play8_num( 80 , 2 | 0x80 , alarm.hour); //display at alarm } else if (state == 4 ) //Judgment data { Clock_flag = ~Clock_flag; if (Clock_flag) //Judgment data play16( 80 , 4 | 0x80 , kai); //Display on else play16( 80 , 4 | 0x80 , guan); //Display off } else if (state == 5 ) //Judgment data { if (key_val == 3 ) //Judging data shedingwendu++; //Add 1 else if (key_val == 2 ) shedingwendu--; //Decrease 1 if (shedingwendu >= 99 ) //Judging data shedingwendu = 99 ; else if (shedingwendu < 0 ) //Judging data shedingwendu = 99 ; play8_num( 80 , 6 | 0x80 , shedingwendu); } else { break ; //Exit } } if (state == 0 ) //exit with 0 status break ; //exit with 0 status } if (state == 0 ) //exit with 0 status break ; //exit with 0 status } } } Copy code

Main function

void main () { uint8 key_val; read_18B20(); //Initial DS18B20 Delay_nms( 1000 ); //Delay 1S, wait for 18B20 to work normally LCD_init(); //Initialize the LCD clear12864(); //Clear the screen information(); delayms( 3000 ); LCD_init(); //Initialize LCD clear12864(); //Clear the screen main_frame(); //Display the main interface frame main_show( 1 ); //Refresh once read_18B20(); //Read temperature play8_num( 96 , 6 , zhengshu); //Display temperature while ( 1 ) { key_val = scan_key(); if (key_val == 1 ) //K1? { main_set(); //Set the main interface } else if (key_val == 3 ) //K3? { clear12864(); //Clear the screen alarm_show(); //Alarm screen clear12864(); //Clear the screen main_show( 1 ); //Main interface } else { read_time((uint8 *)&time); //Read time main_show( 0 ); //Display the main interface if ((time.sec% 2 )== 0 ){read_18B20();} //Collect once every 2S } /*********************Alarm clock*********************/ if (Alarm_flag) //If the alarm flag has the following { if ((flag == 0 ) && (alarm.hour == time.hour) && (alarm.min == time.min)) //Determine whether the condition is satisfied { flag = 1 ; clear12864(); //Clear the screen alarm_show(); //Alarm clock PlayMusic(); //Play music PlayMusic(); //Play music clear12864(); //Clear the screen main_show( 1 ); //Display the main interface } } if (zhengshu>shedingwendu) { BEEP = ~BEEP; } } } Copy code

5 Test results

On the basis of hardware circuit welding and software programming completed separately, the combination and debugging of software and hardware are carried out. Download the completed program on the computer to the microcontroller chip by downloading. During debugging, problems in the software are found, and the problems are solved in time to ensure that the system can work normally and meet the design requirements. Through repeated debugging and experiments, it can be proved that the system can well complete the basic requirements required by the design. That is, the perpetual calendar can be displayed correctly.
When completing the software system, I used a 12M crystal oscillator at the beginning, and all the components were normal. Later, I changed the 11.0592M crystal oscillator and the temperature was abnormal. After careful investigation, I found out that it was because the DS18B20 was reading data. , The time requirement is very accurate, and the error of reading data is caused by the difference of the crystal oscillator. After this debugging, I have a clearer understanding of the importance of timing to the components. In the design, because of the alarm timing function, we hope that the alarm time we set will not be lost due to the power failure of the system. Taking into account that the DS1302 has a lithium battery as a power source, internal data will not be lost due to the power failure of the main system. So we put the timing of the alarm clock in the spare registers in the DS1302. Flexible techniques like these require us to carefully read the component data sheet to obtain useful information for ourselves.
After testing, this work has completed all the requirements of the design. After designing the perpetual calendar, I learned a lot and realized the importance of learning basic knowledge. When designing a complete system, we must consider the combination of hardware and software. Sometimes the hardware is insufficient, we can use software programs To make up for it, thereby saving hardware costs, and modularizing when designing software programs can improve the readability of the programs.

Thanks

As the paper is about to be completed, I would like to thank my supervisor for his enthusiastic care and careful guidance. During the whole process of my graduation project, the teacher used her best to help me, teach me, follow the teacher to do the graduation project, I learned a lot of things, these have a significant impact on my future work and life. She is not only our academic mentor, but also a good friend in life. She guided us tirelessly with the enthusiasm of an educator. As an educator, we not only learned solid professional knowledge, but also learned the principles of life. Her tireless, meticulous teaching and rigorous academic and meticulous work style made me never forget. Here, I would like to express my sincere thanks to her. I wish the teacher good health, peaches and plums all over the world.
At the same time, during my three years of university life, I also received support and help from many teachers, classmates, and friends. I would also like to express my gratitude to you. It is because of you that made my university life more colorful. Thank you.

references

[1] Li Qunfang, Xiao Kan. Principle, Interface and Application of Single Chip Microcomputer. Beijing: Tsinghua University Press, 2007
[2] Tan Haoqiang. C language programming. Beijing: Tsinghua University Press, 2006
[3] Zhang Yihe, Wang Min Nan, Xu Hongchang, etc. Examples of 51 single-chip computers. Beijing: People's Posts and Telecommunications Press, 2008
[4] Liu Kun, Song Ge , Zhao Hongbo , etc. 51 Single-chip C language application technology development technology encyclopedia. Beijing: People's Posts and Telecommunications Press, 2008
[5 ] Bai Yanmin. A detailed explanation of 51 single-chip microcomputer typical system development examples. Beijing: Electronics Industry Press, 2009
[6] Zhou Lina. Protel99SE circuit design technology. Beijing: China Railway Publishing House, 2009
[7] Wang Weiqing, Cheng Guogang . Single-chip Keil C 51 Application development technology. Beijing: People s Posts and Telecommunications Press, 2007
[8] Jiang Zhihong. 51 Single Chip Microcomputer Technology and Application System Development Case Selection. Beijing: Tsinghua University Press, 2009
[9] Muhammad Ali Mazidi, Janice Gillispie, Rolin Mckinlay. The 8051 Microcontroller and Embedded Systems: Using Assembly and C, 2.Edition. Pearson Education, 2006
[10] U. Tietze Ch. Schenk. Electronic Circuits. Handbook for Design and Application, Berlin, New York: Springer-Verlag, 2005

Creating is not easy, sharing requires courage!
You can give me something you like
like
?
Welcome to leave a message in the comment area~