1 Introduction
In many practical applications such as tunnel kiln temperature control systems and self-service lockers, we use the high-level C language of single-chip microcomputers to compile application programs to meet users' different requirements for various performance parameters. The following example introduces the advantages of C language in application design.
2 System Structure
The system consists of two parts: electrical and mechanical. The mechanical part consists of locker boxes and electric locks; the electrical part consists of a single-chip microcomputer, control relays, operation panel, and working status indicators. The system structure is shown in Figure 1.
3. System Function Programming
The system program consists of the following parts: main program, access program, monitoring management program, control output program, cabinet box sorting program, keyboard interrupt, clock timing interrupt and alarm program. The following mainly introduces the box sorting program, access program and password duplication prevention program. The software design adopts a modular structure design method, and all programs are written in the single-chip high-level C language.
The main program completes the initialization of each peripheral interface, then enters the keyboard sampling and display program, and the clock interrupt program completes the display scan update and sampling processing. The following is the box position number initialization subroutine.
The jICunnum [] variable in the above program is used to save the box position number of the box position. Initially, jicunnum[i]=i (i=1, 2, ..., 32), that is, all 32 boxes are set to 1, 2, ..., 32 respectively, so as to facilitate the box position status indication and the output control of the receiving relay to complete the locking control of the cabinet box position, because the opening of the box position electric control lock is operated according to the box position number corresponding to the box position. For example, the initial number corresponding to box position 5 is jicunnum[5]=5, and the others are similar.
When storing items, if there is an empty space in the box, the system will automatically generate a 12-digit password at random and save it. The password will also be printed out and the customer can carry it with him/her. The password random generation procedure is as follows:
void Take(){
1.qq:Mimac=ReadKey();
2.if(Mimac!=0x11){
3.if(Mimacount<numset){
4.Mimac--;Mimac=c&0x00f;
5.display[Mimacount]=Mimac;
6.Mimatemp*=10;
7.Mimatemp+=Mimac;
8.Mimacount++;goto qq;}
9.goto endt;}
10.for(j=0;j<count;j++){
11.if(jicun[j]=Mimatemp){
12.orinum=j;}}
13.endt:return();}
The third line rand() in the above program is a random number generation subroutine. Lines 2 to 4 in the program automatically generate a 12-digit password at random and save it in decimal form in the variable Mimanew.
In order to prevent the password generated this time from being repeated with the password generated on the same day, a discrimination procedure is set in the program. Lines 5 to 7 of the program compare the randomly generated 12-digit password with other passwords that have been generated before, where the jiold[] variable is used to store the password generated on the same day, and the totalcount variable is the number of passwords that have been generated.
If the comparison result is the same, it means that the newly generated password is repeated, the program returns, and a new 12-digit password is generated. If it is different, it means that the password is not repeated, and the new password is saved in the password variable j IC un[], and a new box is automatically opened, and the corresponding box position indicator is on. Lines 8 to 11 adjust the password count pointer (count) and the password count pointer (totalcount) generated on the day.
When the locker is full, that is, the count is greater than 32, the working status indicates that the locker is full, reminding subsequent customers not to continue operating in the locker.
When taking out items, enter the 12-digit password through the operation panel. The 12-digit password data is stored in the variable display[i] (i=1, 2, ..., 12) unit, and the display program displays the value in display[] on the digital tube . The control system compares the password entered this time with the 12-digit password originally stored in the variable jicun[]. If they are the same, open the door lock corresponding to the original storage position of the item and turn off the corresponding position occupancy indicator light; otherwise, do not perform any operation. The procedure for taking out items is as follows:
void Take(){
1.qq:Mimac=ReadKey();
2.if(Mimac!=0x11){
3.if(Mimacount<numset){
4.Mimac--;Mimac=c&0x00f;
5.display[Mimacount]=Mimac;
6.Mimatemp*=10;
7.Mimatemp+=Mimac;
8.Mimacount++;goto qq;}
9.goto endt;}
10.for(j=0;j<count;j++){
11.if(jicun[j]=Mimatemp){
12.orinum=j;}}
13.endt:return();}
The first line of the program ReadKey() is a keyboard key reading subroutine. Lines 2 to 9 wait for the 12-digit password to be entered on the operation panel and temporarily save the entered password in decimal form in the variable Mimatemp. The second line of the program is used to determine whether to exit the key. Lines 10 to 12 determine whether the entered 12-digit password is the same as the original password of a memory variable jicun[]. If they are the same, open the door lock of the box where the items were originally stored; otherwise, do not perform any operation. Line 3 Mimacount is used to calculate the position of the number of password inputs, line 4 Mimac is used to save a single digit of the password, and line 12 orinum is used to save the box number corresponding to the password. numset is the number of digits of the password initially set, here, numset=12.
To prevent malicious operations, when the password does not match, you can enter it repeatedly three times, and then set the prohibited operation flag, automatically lock and delay for a period of time (for example, 3 minutes), and then allow operations; reset the set prohibited operation flag in the clock timing interrupt program to resume normal operation.
As mentioned above, the jicunnum[] variable is used to store the bin number of the bin, and the initial state is jicunnum[i]=i (i=1, 2, ..., 32). However, after a period of operation, the original state of jicunnum[] has changed. If the 7th customer takes the item now, the memory of jicunnum[7] is no longer 7. In order to realize the bin status indication and receive the relay control output, it is necessary to ensure that the operation password is consistent with its bin number. After each item is taken out, the bin number variable must be reordered. The following is the bin sorting program.
void sort(){
1.count--;
2.tempnum=jicunnum[orinum];
3.for(i=orinum; i<count; i++){
4.jicun[i]=jicun[i+1];
5.jicunnum[i]=jicunnum[i+1]}
6.jicunnum[count]=tempnum;
7.return();}
The first line in the program is an operation to decrement the counter by 1, indicating that the item has been taken away and a slot has been vacated. The second line saves the slot number corresponding to the password. Lines 3 to 5 move the slot number (jicunnum[]) and the corresponding password (jicun[]) behind the empty slot forward one by one until all the slots i=count that have been stored have been moved forward one by one.
Line 6 of the program puts the bin number of the items that have been taken out into the last memory variable jicunnum[count].
After the slot sorting program re-sorts the items, the slot number of the 7th customer, jicunnum[7], now stores the slot number after the empty slot at that time. The variables count, orinum, and jicun[] in the program are defined the same as before.
During the process of storing or retrieving items, in order to let users know the working status of the system, such as: storing or retrieving items, whether the cabinet locations are full or empty, which locations are empty, etc., the working status indicator light reminds customers.
In order to facilitate operation and management, a monitoring management program is set up in the program. In case of special circumstances, when any box needs to be opened at any time, the system operator has the right to complete the operation. Different management authority passwords are set, and only system administrators can enter the operation; the operation process is the same as when taking out items.
References
[1] Xu Aijun, Peng Xiuhua. Single-chip high-level language C51 application design [M]. Beijing: Electronic Industry Press, 1999.
Previous article:A C language program for a tracking car
Next article:Taxi meter VHDL program
Recommended ReadingLatest update time:2024-11-16 13:48
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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
- 2.5V to 6V Input 1.5MHz 2A DC Step-Down Circuit
- 【CODING TALK】How would you implement a queue?
- How to input xy coordinates for hole location in pads packaging
- Strange behavior of Firefox browser
- Detailed explanation of ADC function in C8051F020 microcontroller
- Q and D values of capacitors
- [Nucleo G071 Review] PWM breathing light
- [EETalk] Why do smart homes not use ZigBee but are keen on Bluetooth and Wi-Fi?
- Selection of the discharge resistor of the X capacitor
- Help on ADN8834 burning out