51 microcontroller project (11) - multifunctional perpetual calendar based on 51 microcontroller

The perpetual calendar made this time can display the year, month, day, hour, minute and second, and is displayed on the LCD1602 (scrolling display on the first line). It can also measure temperature and humidity, which is also displayed on the LCD1602 (displayed on the second line). It has an alarm clock function. When the alarm time is up, the alarm will sound. The alarm time can be adjusted by pressing the button (the code and simulation files are placed at the end)

The simulation diagram is as follows:

Temperature and humidity detection uses the DHT11 sensor.

DHT11 is a digital temperature and humidity sensor commonly used to measure temperature and humidity in the environment. It contains a temperature sensor and a humidity sensor and outputs the measurement results via a single-wire digital signal. DHT11 is easy to use and low cost, so it is widely used in many projects based on development platforms such as Arduino. To use the DHT11, you need to connect it with a corresponding controller (such as an Arduino) and use the appropriate library functions to read the sensor's values.

To drive the DHT11 sensor, you need to first connect it with the 51 microcontroller, and then write the corresponding program to read the sensor data. The following is the basic driving process:

1. Connect the hardware:
   - Connect the VCC pin of DHT11 to the 5V power pin of the 51 microcontroller.
   - Connect the GND pin of DHT11 to the ground pin of 51 microcontroller.
   - Connect the DHT11 DATA pin to an I/O pin of the 51 microcontroller (for example, P1.0).
   - Add a pull-up resistor (4.7kΩ-10kΩ) to pull up the DATA pin to 5V.

2. Write the driver:
   - Set the DATA pin to output mode and pull it low for a few milliseconds as a start signal.
   - Set the DATA pin high and switch to input mode after a delay of 20-40 microseconds.
   - Wait for the response signal from DHT11, i.e. it pulls the DATA pin low for 80 microseconds and then high for 80 microseconds.
   - Next, DHT11 will provide 40 digital bits (5 bytes) of data, and the high duration between each bit represents 0 or 1.
   - Measure the length of time during the high level of each bit, determine whether the bit is 0 or 1 based on the high level duration, and store the value of the bit.

3. Parse the data:
   - Convert the received 5-byte data into temperature and humidity values. The first two bytes are humidity data, the third and fourth bytes are temperature data, and the last byte is checksum.
   - By simply reading and calculating the data, you can convert it to commonly used temperature units (such as Celsius or Fahrenheit) and humidity values ​​in percent.
   
This is a basic DHT11 driver process, there may be some slight changes in actual operation. You can refer to the data sheet of DHT11 and the programming guide of 51 microcontroller for specific implementation.

The date is recorded using the timer function of the 51 microcontroller.

In the 51 microcontroller, to start the timer, you need to perform the following steps:

1. Determine the timer number to use: 51 microcontrollers usually have multiple timers to choose from. You need to decide which timer you want to use, such as Timer0, Timer1, etc.

2. Configure the timer mode and working mode:
   - Select the timer working mode: the timer can work in different modes, such as timer mode, counter mode, etc. Choose the appropriate working mode based on your needs.
   - Configure the timer working mode: The timer can work in different modes, such as timing mode, timing/counting mode, etc. Choose the right way of working based on your needs.

3. Set the timer count value: According to your needs, set the timer's initial count value, that is, the value at which the timer starts counting.

4. Enable timer interrupt (optional): If you want to trigger an interrupt when the timer reaches the count value, you can set the corresponding interrupt enable bit to 1 to enable the timer interrupt.

5. Start the timer: Set the timer enable bit to 1 to start the timer.

The specific operation methods and code implementation may vary depending on the chip model and development environment. You can refer to the data sheet of the microcontroller and the user guide of the development tool for detailed timer configuration and control register settings.

With the continuous advancement of technology, the traditional 51 microcontroller has gradually been replaced by more advanced processors and microcontrollers in some application fields. However, for specific requirements such as low power consumption, low cost, and real-time applications, the 51 microcontroller still has certain development prospects.

The following are some development prospects of 51 microcontroller in the field of perpetual calendar applications:

1. Low cost and simplicity: As an affordable and easy-to-use microcontroller, the 51 microcontroller is still a suitable choice for some simple perpetual calendar applications. Especially for some low-cost consumer electronics products, the 51 microcontroller can provide sufficient performance and functionality.

2. Real-time application: The 51 single-chip microcomputer has strong real-time processing capabilities. For time-related tasks, such as the realization of clock, timer and alarm clock functions, as well as date calculation and display, the 51 single-chip microcomputer has high accuracy and stability. performance and can meet the requirements of real-time applications.

3. Education and learning: Due to the popularity and relatively simple use of 51 microcontrollers, it is still widely used in the fields of education and learning. In learning embedded systems, microcontroller programming and other related courses, the 51 microcontroller is used as a platform for learning and practice.

4. Applications in specific fields: In some specific application fields, such as home appliance control, electronic games, automation equipment, etc., due to the low power consumption and low cost of the 51 microcontroller, there are still opportunities for its application.

Nonetheless, with the continuous advancement of technology and the market's demand for higher performance and higher efficiency, the 51 microcontroller may be limited in other areas. Therefore, when selecting a technology solution, application requirements, technology trends, and other available processor and microcontroller options need to be considered.

Related code and simulation:

Multifunctional perpetual calendar resource based on 51 microcontroller-CSDN library icon-default.png?t=N7T8https://download.csdn.net/download/guangali/88319501

Guess you like

Origin blog.csdn.net/guangali/article/details/132910129