1) Design task: Design an electronic clock that can display the current year, month, day, hour, minute and second and has an alarm function.
2) Index requirements
(1) It can realize the conversion between 12-hour system and 24-hour system.
(2) Year, month, day, hour and minute can be set individually. The item will flash during setting.
(3) Timing accuracy error: ≤1 second/day.
(4) Liquid crystal display.
(5) It can realize the alarm clock function.
(6) Power supply: 1 AA dry cell battery (1.5V).
1. Protues simulation diagram (adding temperature display function):
2. Protues simulation diagram (12-24 base conversion):
3. Program source code (add temperature display function):
Because the annotations are very complete, I will not explain them here.
/***********************************************************************************
================================================================================
【Platform】STC89C51 platform
【Written by】Sumjess
【E-mail】1371129880@qq.com
【Software version】V2.0
【Last updated】September 6, 2018
[For more information, please refer to the following address]
【Website】
Sumejss blog https://blog.csdn.net/qq_38351824
Electronics Enthusiasts http://bbs.elecfans.com/zhuti_mcu_1.html
China Electronics Network http://bbs.21ic.com/icfilter-typeid-11-214.html
---------------------------------------------------------------------------------
【dev.env.】MDK4.14 and above
【Target】STC89C51
First revision: 2019/05/23
Second revision: 2018/05/24
Third revision: 2018/05/26
================================================================================
************************************************************************************/
#include #define uchar unsigned char //unsigned character macro definition variable range 0~255 #define uint unsigned int //Unsigned integer macro definition variable range 0~65535 #include "E2PROM52_Sumjess.h" #include "Dateconversion_Sumjess.h" #include "intrins.h" bit flag_200ms; bit flag_100ms; sbit beep = P1^4; //Buzzer definition bit flag_beep_en; uint clock_value; //used as an alarm clock sbit dq = P2^0; //18b20 IO port definition uint temperature ; //temperature variable uchar flag_nl; //Lunar calendar and solar calendar display flag uchar menu_1,menu_2; uchar key_time, flag_value; //Used as an intermediate variable for continuous addition bit key_500ms; uchar n_nian,n_yue,n_ri; //Lunar calendar display function #include "DS1302_Sumjess.h" #include "LCD1602_Sumjess.h" /******************Save the data to the eeprom inside the microcontroller******************/ void write_eeprom() { SectorErase(0x2000); byte_write(0x2000, fen1); byte_write(0x2001, shi1); byte_write(0x2002, open1); byte_write(0x2058, a_a); } /******************Read the data from the eeprom inside the microcontroller*****************/ void read_eeprom() { fen1 = byte_read(0x2000); shi1 = byte_read(0x2001); open1 = byte_read(0x2002); a_a = byte_read(0x2058); } /**************Power on self-test eeprom initialization*****************/ void init_eeprom() { read_eeprom(); //Read first if(a_a != 1) //New MCU initial MCU internal eeprom { fen1 = 3; shi1 = 8; open1 = 1; a_a = 1; write_eeprom(); //Save data } } /***************************18b20 initialization function********************************/ void init_18b20() { bit q; dq = 1; //Put the bus high delay_uint(1); //15us dq = 0; // give reset pulse delay_uint(80); //750us dq = 1; //Put the bus high and wait delay_uint(10); //110us q = dq; //Read 18b20 initialization signal delay_uint(20); //200us dq = 1; //Pull the bus high to release the bus } /*************Write the data in 18b20***************/ void write_18b20(uchar dat) { uchar i; for(i=0;i<8;i++) { //Write data starts from low bit dq = 0; // Pull the bus low to start the write time interval dq = dat & 0x01; //Write data to the 18b20 bus delay_uint(5); // 60us dq = 1; //Release the bus dat >>= 1; } } /****************Read the data in 18b20****************/ uchar read_18b20() { uchar i,value; for(i=0;i<8;i++) { dq = 0; //Put the bus low to start the read time interval value >>= 1; //Read data starting from low bit dq = 1; //Release the bus if(dq == 1) //Start reading and writing data value |= 0x80; delay_uint(5); //60us Reading a time gap requires at least 60us } return value; //Return data } /****************The temperature value read is a decimal***************/ uint read_temp() { uint value; uchar low; //If the interrupt is too frequent when reading the temperature, the interrupt should be turned off, otherwise it will affect the timing of 18b20 init_18b20(); //Initialize 18b20 write_18b20(0xcc); //Skip 64-bit ROM write_18b20(0x44); //Start a temperature conversion command delay_uint(50); //500us init_18b20(); //Initialize 18b20 write_18b20(0xcc); //Skip 64-bit ROM write_18b20(0xbe); //Issue a command to read the temporary register EA = 0; low = read_18b20(); //Read temperature low byte value = read_18b20(); //Read temperature high byte EA = 1; value <<= 8; //Shift the high bit of the temperature left by 8 bits value |= low; //Put the low bit of the temperature read into the low eight bits of value value *= 0.625; //Convert to decimal temperature value return value; //Return the read temperature with decimals } ----Due to the length of the page, only a part of it is shown. Please download and watch it yourself. The program is very complete----- -----Follow the official account to download for free----- 4. Program source code (12-24 hexadecimal conversion): Because the annotations are very complete, I will not explain them here. /*********************************************************************************** ================================================================================ 【Platform】STC89C51 platform 【Written by】Sumjess 【E-mail】1371129880@qq.com 【Software version】V2.0 【Last updated】September 6, 2018 [For more information, please refer to the following address] 【Website】 Sumejss blog https://blog.csdn.net/qq_38351824 Electronics Enthusiasts http://bbs.elecfans.com/zhuti_mcu_1.html China Electronics Network http://bbs.21ic.com/icfilter-typeid-11-214.html --------------------------------------------------------------------------------- 【dev.env.】MDK4.14 and above 【Target】STC89C51 First revision: 2019/05/23 Second revision: 2018/05/24 Third revision: 2018/05/26 ================================================================================ ************************************************************************************/ #include #define uchar unsigned char //unsigned character macro definition variable range 0~255 #define uint unsigned int //Unsigned integer macro definition variable range 0~65535 #include "E2PROM52_Sumjess.h" #include "Dateconversion_Sumjess.h" #include "intrins.h" bit flag_200ms; bit flag_100ms; sbit beep = P1^4; //Buzzer definition bit flag_beep_en; uint clock_value; //used as an alarm clock uchar flag_nl, flag_n2; //Lunar calendar and solar calendar display flag uchar menu_1,menu_2; uchar key_time, flag_value; //Used as an intermediate variable for continuous addition bit key_500ms; uchar n_nian,n_yue,n_ri; //Lunar calendar display function #include "DS1302_Sumjess.h" #include "LCD1602_Sumjess.h" /******************Save the data to the eeprom inside the microcontroller******************/ void write_eeprom() { SectorErase(0x2000); byte_write(0x2000, fen1); byte_write(0x2001, shi1); byte_write(0x2002, open1); byte_write(0x2058, a_a); } /******************Read the data from the eeprom inside the microcontroller*****************/ void read_eeprom() { fen1 = byte_read(0x2000); shi1 = byte_read(0x2001); open1 = byte_read(0x2002); a_a = byte_read(0x2058); } /**************Power on self-test eeprom initialization*****************/ void init_eeprom() { read_eeprom(); //Read first if(a_a != 1) //New MCU initial MCU internal eeprom { fen1 = 3; shi1 = 8; open1 = 1; a_a = 1; write_eeprom(); //Save data } } /******************1ms delay function***********************/ void delay_1ms(uint q) { uint i,j; for(i=0;i } /******************Write week function***********************/ void write_week(uchar hang,uchar add,uchar week) // write week function { if(hang==1) write_com(0x80+add); else write_com(0x80+0x40+add); switch(week) { case 1:write_data('M'); //When the week number is 1, display write_data('O'); write_data('N'); break; case 2:write_data('T'); //Display when the week data is 2 write_data('U'); write_data('E'); break; case 3:write_data('W'); //Display when the week data is 3 write_data('E'); write_data('D'); break; case 4:write_data('T'); //The week data is 4 and is displayed write_data('H'); write_data('U'); break; case 5:write_data('F'); //Display when the week data is 5 write_data('R'); write_data('I'); break; case 6:write_data('S'); //Display when the week data is 6 write_data('T'); write_data('A'); break; case 7:write_data('S'); //Display when the week data is 7 write_data('U'); write_data('N'); break; } } /****************Clock display****************/ void init_1602_ds1302() { if(flag_n2 == 0) //display 24 { write_sfm2_ds1302(1,1,shi); //Display write_sfm2_ds1302(1,4,fen); //Display points write_sfm2_ds1302(1,7,miao); //Display seconds write_week(2,12,week); } else { if(shi==0x20) shi=0x08; else if(shi==0x13) shi=0x01; else if(shi==0x14) shi=0x02; else if(shi==0x15) shi=0x03; else if(shi==0x16) shi=0x04; else if(shi==0x17) shi=0x05; else if(shi==0x18) shi=0x06; else if(shi==0x19) shi=0x07; else if(shi==0x21) shi=0x09; else if(shi==0x22) shi=0x10; else if(shi==0x23) shi=0x11; write_sfm2_ds1302(1,1,shi); //Display write_sfm2_ds1302(1,4,fen); //Display points write_sfm2_ds1302(1,7,miao); //Display seconds write_week(2,12,week); } if(flag_nl == 0) //Display the Gregorian calendar { write_sfm2_ds1302(2,2,nian); //Display year write_sfm2_ds1302(2,5,yue); //Display month for(j=0;j<120;j++);
Previous article:Course Design Question 2: 7-person majority voting machine
Next article:Course Design Question 1: Eight-person buzzer
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- The semiconductor industry after the epidemic
- Which boost solution is better? For example, considering efficiency, reliability, controllability, etc.
- How to use AD603 op amp
- 【GD32F310G-START】OLED HELLO EEWORLD——Hardware I2C
- Recommend several cost-effective mobile phones
- The ripple rate R of the inductor in the switching power supply is generally recommended to be around 0.4 as the best value? Then I started to ask?
- The embedded operating systems I have come into contact with - rtx51, freertos, etc.
- Design of high-speed counter based on FPGA.pdf
- Problems encountered in learning C programming language
- 5G Common Terms and Abbreviations