Chapter 1 Design Purpose and Requirements
1. Purpose
Through programming and Protues simulation of the electronic clock system, we can further master the composition of the microcontroller, the application of P1, P0, P2, and P3 ports, the application of buzzers, the writing and application of timer interrupt programs, and review and apply the microcontroller courses learned previously; we can initially master the Protues simulation method and the method of writing programs with Keil software.
2.Topics and requirements
The title of this course design is: Design of electronic clock, and its specific requirements are:
(1) Able to display hours, minutes and seconds;
(2) Ability to switch between 12-hour and 24-hour formats;
(3) Ability to set time;
(4) Ability to set alarm clock;
The entire system needs to design a keyboard and display, and use the internal clock of the microcontroller to complete the timing design of the timer.
Chapter 2 Theoretical Foundations
1.AT89C52 chip
The pin diagram of the AT89C52 chip is shown in Figure 1.
Figure 1 AT89C52 chip pins
The main pin ports are introduced as follows:
(1) The first function of P0 port is to be used as a general I/O port. The second function is to provide the low 8-bit address and 8-bit bidirectional data in time-sharing when the CPU accesses the external memory.
(2) Port P1 is an 8-bit quasi-bidirectional I/O port. In the 51 sub-series, P1 can only be used as a general I/O port. In the 52 sub-series, the P1.0 and P1.1 pins also have a second function.
(3) Port P2 is an 8-bit quasi-bidirectional I/O port. Its second function is to serve as the high-bit address bus and output the high-bit address when the CPU accesses external memory.
(4) Port P3 is an 8-bit quasi-bidirectional I/O port. Its first function is to be used as a general I/O port, and its second function is to be used as an interrupt signal and a read/write control signal for external data storage.
(5) RES, reset signal high level is valid.
2. A brief introduction to Keil
Keil C51 is a 51 series compatible microcontroller C language software development system produced by Keil Software in the United States. Keil provides a complete development solution including C compiler, macro assembler, linker, library management and a powerful simulation debugger, and combines these parts through an integrated development environment (μVision). Here is a brief introduction to the establishment of Keil projects, taking the Keil μVision2 interface as an example.
(1) Create a project and select [New Project] under [Project] in the menu bar. The menu bar is shown in Figure 2.
Figure 2 Menu bar
(2) Select the path where you want to save the project and enter the project name. Take the creation of an electronic clock project as an example, as shown in Figure 3.
Figure 3 "Save New Project" dialog box
(3) Select the microcontroller to be used in the system as shown in Figure 4 (a), and select to add the startup file as shown in Figure 4 (b).
Figure 4 (a) “Select MCU” dialog box
Figure 4 (b) “Add Startup File” dialog box
(4) To create a file, select [New] under the [File] menu, and the interface shown in Figure 5 will appear.
Figure 5 New file interface
(5) Save the file as a "*.c" file and add the file to the created project. The saved file cross-section is shown in Figure 6, and the added file display interface is shown in Figure 7. Right-click SourceGroup to add.
Figure 6 Save file interface
Figure 7 Add file interface
3. A brief introduction to Protues
Proteus software is an EDA tool software published by Lab Center Electronics in the UK. It not only has the simulation functions of other EDA tool software, but also can simulate single-chip microcomputers and peripheral devices. It is currently a relatively good tool for simulating single-chip microcomputers and peripheral devices. It can simulate 51 series, AVR, PIC, ARM, and other commonly used mainstream single-chip microcomputers. After drawing the schematic diagram in PROTEUS, call in the compiled target code file: *.HEX, and you can see the simulated physical operation status and process in the schematic diagram of PROTEUS.
(1) The interface for generating *.HEX in Keil is shown in Figure 8.
Figure 8 Generate HEX file interface
(2) Load the HEX file in Protues and double-click the AT89C51 chip in the Protues interface. The interface shown is as shown in Figure 9.
Figure 9 Loading HEX file interface
Chapter 3 Design Principles and Solutions
1. System overall block diagram
This electronic clock is mainly composed of a single-chip microcomputer, a keyboard, a digital tube display interface circuit, a buzzer circuit and a reset circuit. The overall design scheme is shown in Figure 10:
Figure 10 Overall plan
2. Hardware circuit
2.1 Crystal Oscillator Circuit
The crystal oscillator circuit is shown in Figure 11.
Figure 11 Crystal oscillator circuit
2.2 Reset Circuit
The reset circuit is shown in Figure 12.
Figure 12 Reset circuit
2.3 Buzzer Circuit
The buzzer circuit is shown in Figure 13.
Figure 13 Buzzer circuit
2.4 Digital tube display circuit
The digital tube display circuit is shown in Figure 14.
Figure 14 Digital tube display circuit
2.5 Keyboard Circuit
The keyboard circuit is shown in Figure 15.
Figure 15 Keyboard circuit
2.6 Overall Circuit
The overall circuit diagram simulated in Protues is shown in Figure 16.
Figure 16 Overall circuit
3. Software system design
3.1 Usage of MCU
The use of microcontroller resources in designing an electronic clock is as follows:
Port P0 outputs the digital tube segment selection signal, and port P2 outputs the digital tube position selection signal; adjustment function selection key kgnxz: port P3.0, through which you can choose to adjust the clock or the alarm; adjust the second ksec: port P3.1, press once to increase the second by 1; adjust the minute kmin: port P3.2; press once to increase the minute by 1; adjust the hour khour: port P3.3, press once to increase the hour by 1; 12-hour and 24-hour conversion key kzh: port P3.4, the default is 24-hour system, press once to convert to 12-hour system. Details are as follows:
(1) Realize basic timekeeping and display of hours, minutes and seconds. The initial time 00-00-00 will be automatically displayed upon power-on.
(2) When the first elastic button is pressed for the first time, the time adjustment state is entered. When the second button is pressed, the seconds are adjusted by one. When the third button is pressed, the minutes are adjusted by one. When the fourth button is pressed, the hours are adjusted by one.
(3) When the first elastic button is pressed for the second time, the alarm clock enters the adjustment state (the initial value of the alarm clock is set to 01-00-30). When the second button is pressed, the seconds are adjusted by one. When the third button is pressed, the minutes are adjusted by one. When the fourth button is pressed, the hours are adjusted by one.
(4) When the first elastic button is pressed for the third time, the original time display state is entered.
(5) Press the fifth button to switch from 24-hour to 12-hour format.
(6) When the first elastic button is pressed for the fifth time, the display returns to normal time.
3.2 Modules of the software system
The software design of the clock system is mainly implemented using the following basic modules: main program, timer interrupt service program, keyboard scanning program module, clock display module, alarm display module, conversion module, delay module and buzzer module.
Main program: Set the initial value of the interrupt program and call the sub-function in various situations to ensure the sequential execution of the entire program.
Timing interrupt service routine: used for accurate operation of electronic clock.
Keyboard scanner module: used to determine the keys and call the corresponding program for display when the keys are pressed.
Clock display module: used to display the normal running time.
Alarm display module: used to display the set alarm time.
Conversion module: used to convert the default 24-hour system to a 12-hour system.
Delay module: The delay subroutine is called in the program to eliminate key jitter, digital tube shadow, etc.
Buzzer module: used to sound the alarm when the set alarm time is equal to the running time of the watch.
3.3 Software System Program Flowchart
The sequence flow chart of the main program is shown in Figure 17.
Figure 17 Main program sequence flow chart
The sequence flow diagram showing the program is shown in Figure 18.
Figure 18 shows the program sequence flow diagram
The sequential flow chart of the interrupt program is shown in Figure 19.
Figure 19 Interrupt program sequence flow
Chapter 4 Simulation Results and Analysis
1. Simulation results
The simulation result of power-on table is shown in Figure 20.
Figure 20 Simulation results after power-on
Press the kgnxz key once, and then adjust the hour, minute, and second buttons respectively so that the displayed time is 15-15-15. The simulation result is shown in Figure 21.
Figure 21 Adjusting the simulation results of hours, minutes and seconds
Press the kzh key to display the time as 03-15-19. The simulation result is shown in Figure 22.
Figure 22 Simulation results of converting 24-hour system to 12-hour system
Press the kgnxz key for the second time, and then adjust the hour, minute, and second buttons respectively to adjust the alarm setting time (the initial setting is 01-00-30). The simulation result is shown in Figure 23.
Figure 23 Alarm clock display simulation results
Adjust the alarm setting time to 03-20-30. The simulation result is shown in Figure 24.
Figure 24 Alarm adjustment display simulation results
When the kgnxz key is pressed for the third time, the running time is displayed, and the buzzer sounds when the set alarm time is reached. That is, during the buzzer sounding process, the P1.0 port will change from the original high level to the low level. The simulation result is shown in Figure 25.
Figure 25 Buzzer sound simulation diagram
2. Analysis of simulation results
Previous article:MCU external interrupt program (give P3.2 pin low level, LED will show the inverted state)
Next article:DHT11 and DS18B20 temperature and humidity control microcontroller program
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Battery Management System BMS Technical Data Transfer
- [Raspberry Pi Pico Review] LCD1602 4-bit mode display driver
- There are 10 digital tubes on a digital tube display board, which uses 1 74HC00D, 2 74HC04D and 10 74HC164D
- GigaDevice GD32VF103C-START Development Board Introduction
- 135 classic design examples of Verilog
- [Perf-V Evaluation] On-chip Temperature Collection
- What is the difference between WiFi 6 routers and WiFi 5 routers
- 100 Practical Tips for FPGA Design Experts (English Original).zip
- Huawei_Analog Circuit Design Volume 1
- Recruiting ADC/DAC application engineers, working location: Hangzhou