2976 views|0 replies

1379

Posts

0

Resources
The OP
 

Remote Lighting Control Box System Based on SST89C58 Single Chip Microcomputer [Copy link]

Abstract: With the purpose of remote control of lighting equipment in large places, this paper introduces the software and hardware design of the remote lighting control box system based on the SST89C58 single-chip microcomputer. The system communicates with the PC host computer through the RS-485 bus to achieve long-distance and multi-node control.

Keywords: MCU; IAP; remote control; communication protocol: SST89C58

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: X5045 is a 4K SPI electrically erasable memory, which is used to save the slave station number after power failure. Maxim's MAX485 is a universal half-duplex transceiver. When the transmission speed is 9.6Kb/s, the transmission distance can reach 1.2km. It can realize serial asynchronous communication between the host computer and the single-chip microcomputer.

Figure 2 2.2 System core hardware

The core hardware diagram of the remote light control box system is shown in Figure 2. The SST89C58 microcontroller is used as the core, and the P0 and P2 ports are used for signal control. Note that a pull-up resistor should be added to the P0 port. Through two ULN2803s for current amplification, 16 relays can be driven. Since the chip has a common cathode clamping diode, it can adapt to inductive loads, so a large number of diodes can be omitted at the output end. SST89C58 drives 16 relays and can control 16 light signals. If you want to increase the control signal, you can add an 8255 device to expand the parallel interface. Use X5045 to save the RS-485 network slave station number. The P1.2 pin of the SST89C58 microcontroller is used to simulate the clock input signal SCK of the X5045. When CS=0, the serial output SO is valid at the falling edge of the clock signal, and the serial input SI is valid at the rising edge (WP=1). The specific operation also requires writing the status word. The serial port part uses MAX485. Among them, RE and DE are connected together and controlled by RD (P3.7) of the microcontroller. Pulling low means receiving is effective, and pulling high means sending is effective. The system also has the function of automatic reset and power-on indication. When designing PCB, attention should be paid to reasonable wiring, filtering and rectifying the microcontroller power supply, and keeping away from interference sources.

3 System Software Design

The use of C language compiler to develop single-chip microcomputers has the outstanding features of easy use, high programming efficiency and easy simulation and debugging. There are many versions of C51. The software of this system is developed using the Keil C51 compiler of Keil Software Company of Germany. This compiler is based on the Windows platform integrated development environment. It 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 function is very powerful. The software design of this system consists of the main program, interrupt program, serial receiving subroutine, serial sending subroutine, X5045 read and write subroutine and several function realization subroutines. Among them, the X5045 read and write subroutine needs to perform precise operations on the clock and is written in assembly language, while 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.

This post is from MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list