0 Introduction
With the development of computer technology, the monitoring of the use of various instruments is becoming more and more intelligent. In view of the shortcomings of the time recorder on the market, such as high cost, poor scalability, small storage capacity, and complex programming, this paper designs an intelligent time recorder by using AVR microcontroller as the core controller, high-brightness LCD as the display, and USB mobile hard disk as the storage device.
1 System hardware design
1.1 Overall composition of the system
The intelligent information recorder consists of a single-chip microcomputer, power supply, LCD display, keyboard input and USB module. The system composition block diagram is shown in Figure 1. The power supply in the system includes an external
power supply and a lithium battery. After powering on, the system main power supply supplies power to the circuit while charging the lithium battery. After powering off, the lithium battery supplies power to the USB to save the data. The main task of the LCD display part is to complete the query and display of the power on and off time, and to display the current system time when idle. The clock module uses the DSl302 chip, which is a trickle charging clock chip launched by DALLAS. It contains a real-time clock/calendar and 31 bytes of static RAM. It can communicate with the single-chip microcomputer through a simple serial interface. The real-time clock/calendar circuit can provide information on seconds, minutes, hours, days, weeks, months and years. The number of days per month and the number of days in leap years can be automatically adjusted. The USB module uses the USB disk read-write chip PB375A, which is a relatively simple USB disk read-write solution. It is not necessary to understand the complicated USB HOST underlying protocol and FAT file system (supports FATl2, FATl6 and FAT32 file systems) to use it. Instead, you only need to communicate with the MCU and the module through the SPI interface or UART, and execute a few simple commands to complete the functions of creating, reading, writing, and deleting files. It is very simple and convenient to use. In addition, for the microcontroller, it basically does not occupy the storage space of the microcontroller system, and only requires a few bytes of RAM and a few hundred bytes of code. Its serial port supports three baud rate options of 9600, 4800 and 2400 bit/s. Since it has a built-in 5 V to 3.3 V circuit, it can greatly simplify the design of peripheral circuits.
1.2 Hardware Circuit Design
This information recording instrument uses a high-performance, low-power processor ATmega64 as the central controller. Its operating voltage is 3.3 V and it has rich internal resources: including 53 programmable I/O ports, 7 external interrupts, 2 16-bit timers, 2 8-bit timers, 4 KB on-chip SRAM and 64 KB system programmable Flash memory. It also has a long erase and write life and can meet system requirements. ATmega64 and its peripheral interface circuit are shown in Figure 2.
The interrupt interface circuit of the instrument includes the power-on interrupt when the machine is turned on and the power-off interrupt when the machine is turned off. They are both composed of the optocoupler chip 6N137 and the NOT gate 74LVT04. Figure 3 shows the interrupt circuit. The power supply VC is connected to the input of the optocoupler after passing through 7805, and the output is connected to the INT0 of the microcontroller and the 1st pin of the NOT gate. The 2nd pin of the NOT gate is connected to INT1. Therefore, when the machine is turned on, the input terminal Vin+ of the optocoupler is high level and the output terminal Vo is low level, so a power-on interrupt (INT0) is generated; while when the machine is turned off, the input of the optocoupler is low level and the output is high level. Therefore, after passing through the 2nd pin of the NOT gate, the output is low level to generate a power-off interrupt (INT1).
The main function of the power switching circuit is to switch to the lithium battery to power the USB and save the data when the system is shut down. The power switching is shown in Figure 4. In the figure, when the external power is turned on, V is high to turn on the transistor Q2, and at the same time pull the base of Q1 to a low level to turn it on. The external power V passes through the diode D1 (VC) to power the microcontroller circuit and USB. Since the program sets POWER high at the beginning, Q2 is also turned on at this time. When the system is shut down, V becomes low and the transistor Q2 is turned off. However, since Q3 is turned on at this time, Q1 is still turned on, but the data is saved by the lithium battery at this time. At this time, the timer l of the microcontroller starts working, and after a delay of 10 s, the output of POWER is low, so that Q3 is turned off, and finally the base of Q1 becomes high, and the entire recorder is turned off.
2 System software design
The main tasks of the system software are USB reading and writing, LCD display, clock and keyboard programming. Serial communication is used between PB375A and the microcontroller. Among them, the microcontroller first
sends the command code and parameter information to PB375A, and PB375A performs the corresponding operation according to the command information, and then returns the operation status code to the microcontroller in interrupt mode. The communication format includes the start code (0x3A), operation code, data length and data packet. Its main operation codes are as follows:
Ox71: Detect whether the U disk is connected, and return 0 when connected;
0x64: Open an existing file, if the file does not exist, return Ox42:
0x65: Create a new file;
Ox7A: Determine the address of the read and write bytes;
0x7B: Return the read data in bytes.
Figure 5 shows the program flow chart of this system.
2.1 File creation and data writing
The command CMD_FileCreat can be used to create a new file. The file name should be in the format of 8+3 and must be uppercase letters or numbers.
Data writing can be achieved through the command CMD_ByteWrite.
The file can be closed through the command CMD_FileClose. Closing the file will automatically update the file length. In addition, it should be noted that only when the file is closed; the file is generated by default, otherwise no file is generated, and the following operations cannot be performed (for example, after creating a new file, if you start reading data without closing the file, the operation is invalid).
2.2 Append data to an existing file
The general commands for appending data to an existing file are as follows:
CMD_FileOpen: open the file;
CMD_ByteLocate: move the file pointer to the end (0xFFFFFFFF);
CMD_ByteWrite: write data;
CMD_FileClose: close the file.
2.3 Write data operation
When writing data, first read the value of the real-time clock DSl302 to determine whether the current time is the 1st of each month. If so, create a new vv-mm. TXT file is used to save the number of times the computer is turned on every day of a month, and then a new yy—mm—dd.TXT file is created to save the specific time of each power on and off. If it is November 1, 2009, first create 09-11.TXT and write 31 zeros, then read out its first number, if it is 0, create 09-11-01.TXT, write the power on time, then add 1 to the flag of the number of power ons, and then write the file 09-11.TXT. When the computer is turned on for the second time, the time is directly appended to the file. When creating the
file 09-11-01.TXT, save the current date and time. In this way, when the computer is turned off, the shutdown time will be appended to the file.
2.4 Query and display of date and time
When displaying the date and time to be queried, first open the date file for input, then read the data and store it in the display cache. In order to be able to read clearly on the computer, special characters such as space, carriage return, and line feed should be used when writing the specific time. Therefore, the data read by the microcontroller must be specially processed before being sent for display.
3 Conclusion
The information recording system scheme introduced in this paper is reasonably designed, easy to use, has a friendly human-machine interface and large data storage capacity, and can well realize the intelligent recording of time information. The intelligent information recorder designed using this scheme can meet the use requirements of various industrial occasions and has good promotion value.
Previous article:Microcontroller development solutions
Next article:Design and implementation of a vision-based intelligent tracking vehicle based on AVR microcontroller
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- Together wow: Smart soldering iron based on domestic chip, portable soldering iron system IronOS (FreeRTOS)
- How to add code to ardunio ide
- Blackboard with 24 touch keys, 9 customizable LEDs
- TI DLP Pico micro-projection technology makes smart speakers more powerful
- Is there any correlation between the firmware library (standard library) and these operating systems? Can't we write an operating system using library functions?
- 50 555 Circuits—Chinese Version
- Detailed explanation of PCB routing and signal integrity issues
- Drone leader DJI is hiring for automotive software positions. Job location: Shenzhen.
- Design and implementation of temperature controller based on single chip microcomputer and fuzzy control
- Review summary: ART-Pi is here: high-performance H7 chip, DIY tool