Computers are the symbol of today's information age. Realizing remote real-time automatic control through computers is a trend of future development. There are usually many lighting devices in large shopping malls, restaurants, stadiums and entertainment venues. In the past, switch control and circuit breaker control often required staff to frequently visit the site for operation, or to pull a long 220V wire to the control room, which had poor real-time and safety. In order to enable staff in the control room to perform real-time and effective status control and status query on remote lighting equipment scattered in various rooms, the author developed a remote lighting control box system based on a single-chip microcomputer. The system is controlled by a PC host computer to control multiple remote lighting control boxes. The system transmits commands serially through the RS-485 bus, with a transmission distance of up to 1.2km, and enhances the formulation of serial communication protocols to reduce noise interference. One lighting control box can control 16 street lights. The SST89C58 single-chip microcomputer is selected in the lighting control box. Its convenient IAP function can download Hex files online and debug without using the programmer multiple times.
1 System structure and function
The structure of the remote light control box system is shown in Figure 1, where the PC host is placed in the control room and each light box is placed near the lighting equipment. The PC host sends control instructions and transmits the instructions serially to each remote light control box through the RS-485 bus, so that the switch can be controlled in real time in the control room and the status of each light can be queried. The RS-485 bus is selected from the aspects of transmission distance and cost performance. RS-485 is a balanced line that can realize long-distance and multi-node control. The focus of this design is the light control box. The following will take a light control box as an example to introduce the software and hardware design of the system.
2 Hardware Design
2.1 Main components
The design system uses the SST89C58 microcontroller with IAP (In-Application Programming) function launched by Silicon Storage Technology. It is fully compatible with the standard 8052 microcontroller in terms of instruction system, hardware structure and on-chip resources. At the same time, the capacity of the internal program storage Flash is increased to 36KB. Six special function registers related to Flash programming and two special function registers related to watchdog reset are added. The IAP function of SST89C58 is written using a general program [1], and Keil's μVision simulation software is used for programming simulation. The generated Hex file is directly downloaded from the PC to the microcontroller through the RS-232 serial port for operation and debugging. It is very convenient to use and shortens the development cycle. The ULN2803A device is a monolithic integrated high-voltage, high-current Darlington transistor array produced by TI. The array consists of 8 NPN Darlington transistors. Its characteristics are high current gain, strong load capacity (output current can reach 500mA), and high operating voltage (withstand voltage up to 50V). The selected device is X5045, which is a 4K SPI electrically erasable memory used to store the slave station number after power failure. Maxim's MAX485 is a universal half-duplex transceiver with a transmission speed of 9.6Kb/s and a transmission distance of up to 1.2km. It can realize serial asynchronous communication between the host computer and the microcontroller.
2.2 System Core Hardware
远程灯控箱系统的核心硬件图如图2所示,以SST89C58型单片机为核心,用P0口和P2口进行信号控制,注意P0口要加上拉电阻器。通过2个ULN2803进行电流放大,可驱动16路继电器。由于片内带有共阴极箝位二极管,可适应感性负载,故输出端可省去大量二极管。SST89C58驱动16路继电器,可控制16路灯信号。若要增加控制信号,可增加8255型器件扩展并行接口。用X5045保存RS-485网络从机站号。SST89C58单片机的P1.2引脚用来模拟X5045的时钟输入信号SCK,CS=0时,串行输出SO在时钟信号下降沿有效,串行输入SI在上升沿有效(WP=1)。具体操作还需要写入状态字。串口部分选用MAX485。其中,RE与DE接在一起由单片机的RD(P3.7)控制。拉低为接收有效,拉高为发送有效。该系统还具有上电自动复位和通电指示功能。设计PCB时应注意合理布线,对单片机电源进行滤波整流,并远离干扰源。
3 System Software Design
Using C language compiler to develop single-chip microcomputer has outstanding features such as easy use, high programming efficiency and easy simulation and debugging. There are many versions of C51. The software of this system is developed with Keil C51 compiler of Keil Software Company of Germany. This compiler is based on Windows platform integrated development environment, which can edit, compile and debug assembly language programs and C51 programs. It can also simulate I/O ports, timers/counters, serial ports and interrupts and other functional components unique to single-chip microcomputers. The software design of this system consists of main program, interrupt program, serial receiving subroutine, serial sending subroutine, X5045 read and write subroutine and several function realization subroutines. Among them, X5045 read and write subroutine needs to operate the clock accurately, which is written in assembly language, and the others are written in C language.
3.1 Main program design
In the main program, first initialize SST89C58 and X5045, and then wait for new commands. When NewData=1, it means that a valid command frame has been received, otherwise continue to wait. Then determine whether it is the local address. If so, determine the control command, otherwise continue to wait. The host computer sends the specified string, which represents commands such as turning on the light, turning off the light, querying, and setting. Through string comparison, the command instruction is determined and jumps to the corresponding entry subroutine; after the operation is successful, the subroutine is sent through the serial port to return the corresponding prompt. The specific process is shown in Figure 3. In this system, the human-computer interaction interface of the host computer is developed by C++Builder. Due to space limitations, it is omitted here.
3.2 Serial port interrupt program design
In order to enhance anti-interference and effectively distinguish noise from data for easy operation, the serial port interrupt program strengthens the formulation of the communication protocol [2]. The specific implementation method is to add a start flag and an end flag. Noise appears in the form of random bytes. Through testing and experiments, it is found that noise is not easy to occur when 0x00 is followed by 0xFF in this system. Therefore, the start flag is set to 0x000xFF, and the end flag is the carriage return and line feed 0x0D0x0A. If the command frame is received successfully, NewData=1 is set to indicate that the new command is valid. Considering error correction, the data is in short packet mode. Delay is used in the middle to ensure the reliability of the start bit. The serial port interrupt program flow is shown in Figure 4. Part of the program list is as follows.
//Serial connection function
INT8U ReUART(INT8U*ch)
{INTl6U delay=6000;
while(--delay) //delay
{if(RI), /Serial receive interrupt flag
{RI=0; //Receive interrupt flag software reset
、 *ch=SBU F=//Read data buffer
return 1; } // Return l if successful
}
return(0); //Return 0 if reception fails
)
//Serial interrupt handler
void UART_Inter(void)interrupt 4
{INT8U ii;
INT8U temp,templ;
ReUART(&temp,); //First receive 2 bytes continuously
ReUART(&templ);
//Start mark
if((temp==0x00)&&(templ==0xFF))
//Continuously receive a command frame
{for(ii=0;ii<12;ii++)
{if(ReUART(&buff[ii])==0)
goto Inter._end;}//Jump out of interrupt
if((buf[10]==0x0D)&&(buf[ll]==0x0A)), / end mark
NewData=l; //New command flag is valid
}
Inter_end:; //interrupt exit
}
4 Conclusion
The remote light control box system based on SST89C58 can realize a PC host computer to control up to 256 light control boxes, with a maximum transmission distance of 1.2km. Each light control box can control 16 street lights. It realizes the functions of centralized management and decentralized control. The system improves anti-interference through software and hardware, and has good scalability, simple structure, low investment, and practical application shows that it has strong practicality.
Previous article:Using Serial Port and Parallel Port to Implement Online Programming of 51 Single Chip Microcomputer
Next article:Implementing Chinese Input Method Using C51 Single Chip Microcomputer
Recommended ReadingLatest update time:2024-11-16 18:00
- 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
- [RISC-V MCU CH32V103 Review] + Hardware SPI drive OLED display DHT11 temperature and humidity
- Multi-channel LED driver
- Which formaldehyde sensor is good? Which model? If you have used it, please share and discuss.
- X-NUCLEO-IKS01A3 sensor test based on STM32F401RE development board 4 LIS2MDL magnetometer test
- Issues that need attention when initializing SPI of TI C2000 series 280049 chip
- Oh my god! As an electronic engineer, you are still using Baidu to search for information?
- TMS570 battery balance management system solution
- Celebrating Programmers Day
- Battery level detection for low power devices
- CAN IAP Example