Design of electronic locker based on 51 microcontroller

Publisher:学海飘香Latest update time:2023-06-26 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Small RTOS has small RAM requirements and is very suitable for systems with relatively few resources such as microcontrollers. RTOS has multi-tasking, strong real-time performance, and a scalable kernel, making it easier to design, expand, and maintain real-time applications. The introduction of RTOS ideas has changed the traditional microcontroller software design method, making it no longer a single-thread structure. By dividing the application program into several independent tasks, RTOS greatly simplifies the application design process. This article briefly analyzes the design ideas of Small RTOS and the application of the message queue communication mechanism based on the software design of electronic lockers based on microcontrollers.


1. Basic principles of Small RTOS51

Small RTOS51 is a very small kernel that is fully integrated in the KEIL C51 compiler. It only takes up less program storage space and can run in a 51 microcontroller system without external data memory. The kernel is responsible for the initialization and opening of the system, scheduling other tasks, and reasonably allocating CPU time between different tasks according to the priority of each task. The kernel can generally provide functions such as task scheduling and interrupt services. Corresponding a program to a task, each separate and independently executed part of the task is called a thread. All event-driven and time-driven are reflected in setting the corresponding task identification and thread identification. When the hardware environment is certain, based on these indicators, by arranging the interrupt response method in the system and adjusting the task scheduling algorithm, the method of setting environment variables is used, so that after the interrupt exits, you can return to any one of the multiple setting entries for execution, which is effective It effectively solves the key problem of flexible switching of foreground and background task threads. The user tasks of Small RTOS 51 have running state, ready state, waiting and suspending, and interrupt service routines. At any moment, the status of the task is one of these four states. In order to save memory, the OS cannot dynamically create and delete tasks. After using the function OSSTART() to start the multi-tasking environment, the OS creates all tasks, sets them to the ready state, and starts running the highest priority task. Only when all tasks with a higher priority than it are transferred to wait. Only ready tasks can enter the running state. The scheduler considers the highest priority task in the "task ready list" as the next task to be executed.


The task calls the os_wait function to suspend the current task and wait for one or several interval (K_IVL), timeout (K_TMO), and signal (K_SIG) events. If the event you are waiting for has occurred, continue to execute the current task; if the event you are waiting for has not occurred, set the corresponding wait flag, suspend the task, and switch to the task switching program section to switch to the next task.


Small RTOS51 assigns the initial value to the register by executing the function init (), calls the function OSStart () to initialize the stack of each task and execute the first task. The reason for selecting the first task for execution is the priority level of the task. Task scheduling is completed during the selection process.


1.1 Communication between tasks

The communication between tasks uses the message queue, which goes through three steps: creating the message queue OSQCreate(), sending the message OSQPost() to the message queue, and getting the message OSQPend(). When calling the OSQPost () function to send a message, if there is already a task waiting for the message, it will immediately switch to the task waiting for the message. If the message queue is full, the message cannot be delivered and an error message will be returned. If the message queue is not full and there are no other tasks waiting for the message, it is queued. It is worth noting that when the queue is full, this function does not suspend the current task, so the task calling this function should determine the return condition. If the message is full, the current task should be suspended. When receiving a message, if the message queue is empty, the task of fetching the message will be suspended until there is a message in the message queue.


2. Application examples

2.1 Hardware platform

Taking electronic lockers used in large supermarkets and bookstores as an example, the system block diagram is as follows

Design of electronic locker based on 51 microcontroller

The maximum number of cargo storage boxes that can be controlled by this electronic locker is 32, with 16 boxes on the left and right respectively. Only 16 control channels are shown in the above figure. The control chip uses an AT89C55 microcontroller, equipped with a real-time clock module, a barcode reader, a liquid crystal display module, and a thermal printer. It is designed as three PCB boards.


1 Main control board, performs human-computer interaction for user's bag storage and bag retrieval, saves the bag storage password, displays the user's password input during the bag retrieval process and the status of all 32 bag storage boxes.

2. The door control panel consists of three parts. The first part detects items in the box and includes 16 channels of infrared detection input and 16 channels of infrared emission control drive. The second part is 16-way relay control, and the box opening control consists of 16 small DC motors to form the door opening control of 16 boxes. The third part is door status detection, which detects the opening/closing of 16 doors.

3 Bar code printing and voice prompts for access packages. The entire system is coordinated by 4 microcontrollers. The main control microcontroller manages the operations of package deposit users and records their historical parameters. Then it issues instructions to the slave microcontrollers, allocates empty boxes and prints out the package deposits. Article, to the user.


2.1 Software design

The electronic package locker mainly includes modules such as button processing, display processing, and communication processing, which are handled by interrupt processing, barcode reading and serial port communication. Therefore, the tasks can be divided into four tasks: key display, data reception, command processing, and data transmission.


Take the main control microcontroller 1 as an example to explain the main design idea of ​​receiving the user's password input when pressing the package, key value processing, password display and box status display, and sending unboxing commands.


After the main program initializes the system, it calls the function OSStart() to set up the multi-tasking environment, establishes a task stack for each task, and sequentially establishes 4 tasks, waiting for the corresponding task to wake up. Users only need to define the function they want to implement as a task, declare the task function name and its priority in cONfig.h, and write their own code segments. There is no need for up and down calls in traditional programming. relationship, the system will automatically run the code. The transplantation of Small RTOS51 mainly involves configuring three files: OS_CPU.H, OS_CFG.H and CONFIG.H. The OS_CFG.H file is mainly used for operating system reduction and clock configuration.


Define 4 tasks in the CONFIG.H file

#ifndef…. .

…………

#endif


Due to space limitations, the procedures for sending data to microcontrollers 2 and 3 and receiving data from microcontroller 2 are omitted.


4 Conclusion

The use of real-time multi-tasking operating systems makes programming more efficient, maintenance and modifications more convenient, so it is currently widely used, especially in embedded systems. In the application field of low-end 51 microcontrollers, it is also of practical significance to use the idea of ​​​​real-time multi-tasking operating system and use the Small RTOS multi-tasking platform for system application design and improvement.


The innovation of this article is to apply the idea of ​​Small RTOS multi-tasking in the software design of a specific electronic locker system controlled by a single-chip microcomputer, and introduce the programming method of task communication based on message queues.


Reference address:Design of electronic locker based on 51 microcontroller

Previous article:What are the advantages and disadvantages of the microcontroller at89s52 compared with other microcontrollers?
Next article:Why is the 51 crystal oscillator 11.0592?

Recommended ReadingLatest update time:2024-11-16 09:27

Using Changxin memory chips, China's first Chinese-made DDR4 memory module is mass-produced
Recently, the first Chinese-made DDR4 memory stick, the Guangwei Yi PRO DDR4 memory stick, went into mass production in Pingshan, Shenzhen. According to official news from Jiahe Jinwei, the Guangwei Yi PRO DDR4 memory stick uses the independently produced Changxin memory chip and is manufactured by Shenzhen Jiahe Ji
[Mobile phone portable]
SK Hynix announces the development of a memory PIM with computing capabilities
SK Hynix announced that it has developed "PIM" (processing-in-memory), a next-generation memory semiconductor technology with computing capabilities. At the same time, SK Hynix has also developed a sample of the first product based on PIM technology, "GDDR6-AiM". Compared with traditional DRAM, GDDR6-AiM
[Embedded]
The fusion of multi-level storage and analog in-memory computing solves AI edge problems
Machine learning and deep learning have become an integral part of our lives. Artificial intelligence (AI) applications using natural language processing (NLP), image classification, and object detection are deeply embedded in many of the devices we use. Most AI applications are well served by cloud engines, such as g
[Internet of Things]
The fusion of multi-level storage and analog in-memory computing solves AI edge problems
Huawei launches mobile phone memory upgrade service for all four series
Huawei Mall announced the launch of a mobile phone memory upgrade service, with prices starting at 389 yuan. The "memory" Huawei refers to is not the memory for running apps, but what we often call the body storage. That is, by replacing the storage chip with a larger memory, the problem of insufficient mobile phone
[Mobile phone portable]
Huawei launches mobile phone memory upgrade service for all four series
Infineon Technologies Expands Data Logging Memory Portfolio with Industry’s First 1Mbit Automotive-Qualified Serial EXCELON™ F-RAM Memory
Infineon Technologies Expands Data Logging Memory Portfolio with Industry’s First 1Mbit Automotive-Qualified Serial EXCELON™ F-RAM Memory and New 4Mbit F-RAM Memory The continuous development of the automotive event data recording system (EDR) market is driving the demand for dedicated data recording
[Embedded]
Infineon Technologies Expands Data Logging Memory Portfolio with Industry’s First 1Mbit Automotive-Qualified Serial EXCELON™ F-RAM Memory
Micron helps Xiaomi 13 be the first to be equipped with LPDDR5X memory, creating a new experience for the next generation of smartphones
Micron’s most advanced mobile memory products are now in mass production and shipping for Xiaomi’s latest flagship smartphone Shanghai, China, December 12, 2022—Micron Technology Inc., a leading supplier of memory and storage solutions, today announced that its LPDDR5X mobile memory continues to g
[Mobile phone portable]
Micron helps Xiaomi 13 be the first to be equipped with LPDDR5X memory, creating a new experience for the next generation of smartphones
MCU on-chip memory burning (ROM programming)
The microcontroller application system consists of hardware and software. The carrier of the software is the program memory of the hardware. The program memory uses a read-only memory. This memory can still save the program after the power is turned off. After the system is powered on, the CPU can take out these instr
[Microcontroller]
MCU on-chip memory burning (ROM programming)
Samsung Electronics sets up new laboratory in Silicon Valley to develop next-generation 3D DRAM memory
Samsung Electronics said it has opened a new R&D research laboratory in Silicon Valley, USA, to focus on the development of next-generation 3D DRAM chips. The laboratory, operated by Device Solutions America (DSA) in Silicon Valley, oversees Samsung's semiconductor production in the United States and is committed to
[Semiconductor design/manufacturing]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号