The Application of AT89C51 Microcontroller in Wireless Data Transmission

Abstract: Introduce the composition of the wireless data transmission system, the working mode of the serial port of the AT89C51 microcontroller and the design and implementation of the software and hardware interface with the wireless digital radio.

In general digital acquisition systems, the captured field signals are converted into electrical signals through sensors, after sampling, quantization, and encoding by the analog-to-digital converter ADC, they are converted into digital signals, stored in data memory, or sent to the microprocessor Or wirelessly send the data to the receiver for processing. The wireless data transmission system is a kind of equipment that uses wireless means to send the collected data from the measuring station to the main control station.

1 System composition

The system composition is shown in Figure 1 and Figure 2.

The system consists of two parts: the measuring station and the main control station. The measuring station mainly completes the collection and storage of on-site signals, receives remote control commands and sends data. The main work of the master control station is to send remote control instructions, receive data information, perform data processing and data management, random display printing, etc.

2 Serial communication between AT89C51 and digital radio

Atmel's AT89C51 MCU is a low-power, high-performance 8-bit CMOS MCU with 4KB Flash ROM on-chip. The operating voltage range is 2.7 ~ 6V (actually used + 5V power supply), 8-bit data bus. It has a programmable full-duplex serial communication interface that can simultaneously transmit serially and receive persistently. Communicate with the outside world through the RXD pin (serial data receiver) and TXD pin (serial data transmitter).

2.1 Communication protocol and baud rate

The communication protocol between the digital radio station and the single-chip computer and the terminal main control machine is:

Communication interface-standard serial RS232 interface, 9-wire half-duplex mode;

Communication frame format-1 start bit, 8 data bits, 1 programmable data bit, 1 stop bit;

Baud rate-1200 baud.

The digital radio selects Motorola's GM series car radio, works in the VHF / UHF frequency band, can carry out wireless data transmission (9-wire standard serial RS232 interface), and can also conduct voice communication; adopts binary frequency shift keying (2FSK) modulation The demodulation method conforms to the CCITT.23 standard of the International Telegraph and Telephone Advisory Committee. When performing digital transmission in the voice band, it is recommended to use it when the data rate is not higher than 1200b / s. In actual use, the radio works in the frequency range of 220 ~ 240MHz, and the half-duplex mode (receiving and sending operations are performed, but cannot be performed at the same time) can meet the system requirements.

2.2 Working mode of AT89C51 serial port

The AT89C51 serial port can be set to four working modes, which can have 8-bit, 10-bit and 11-bit frame formats. In this system, the AT89C51 serial port works in mode 3, that is, the 11-bit asynchronous communication format of the pagoda frame: 1 start bit, 8 data bits (low bit first), 1 programmable data bit, 1 stop bit .

Before sending, the ninth data (TB8) is set by software as the parity bit, the data to be sent is written to SBUF, and the sending process is started. The serial port can automatically take out TB8, load it into the 9th data position, and send it out one by one. After sending, make TI = 1.

When receiving, set REN in SCON to 1 to allow reception. When RXD is detected (P3.0 terminal has a "1" to "0" transition (start bit), it starts to receive 9-bit data and sends it to the shift register (9 bits). When RI = 0 and SM2 are satisfied When = 0 or the received 9-bit data is 1, the first 8-bit data is sent to SBUF, and the 9-bit data is sent to RB8 in SCON, and RI is set to 1; otherwise, this time the reception is invalid and RI is not set.

The baud rate of serial port mode 3 is determined by the overflow rate of timer T1 and the value of SMOD at the same time:

Mode 3 Baud rate = T1 overflow rate / n

When SMOD = 0, n = 32; when SMOD = 1, n = 16. The T1 overflow rate depends on the T1 count rate (count rate = fosc / 12) and the initial value preset by TI.

Timer T1 is used as a baud rate generator and works in mode 2 (automatically reloads the initial value). Set the initial value of TH1 and TL1 timing count to X, then every "28-X" machine cycles, T1 will overflow. The initial value X is determined as follows:

X = 256-fosc & TImes; (SMOD + 1) / 384 & TImes; BTL

In this system, SMOD = 0, wave rate BTL = 1200, crystal oscillator fosc = 6MHz, so the initial value X = F3H.

2.3 Hardware connection between AT89C51 and digital radio

The hardware connection between AT89C51 and digital radio is shown in Figure 3.

The system uses asynchronous serial communication to transmit measurement data. Use the one-chip computer serial port to connect with the digital radio RS232 data port. The normal state of the radio is the receiving state (PPT = 0, receiving state; PPT = 1, sending state), and the P3.5 pin of the single-chip microcomputer outputs a high level. The one-chip computer uses TTL level, the radio station uses RS232 level, MAX232 finishes the conversion between TTL level and RS232 level. Three pieces of photoelectric coupler 6N137 realize the power isolation between the single chip and the radio, and enhance the anti-interference performance of the system.

The single chip microcomputer controls the transceiver of the radio station through the three-state buffer gate 74HC125 and the non-gate 74HC14 with the control terminal, as well as the command reception and data transmission. When receiving, P3.5 = 1, c2 = 1, 74HC125B is cut off; P3.5 is reversed and photoelectrically isolated by 74HC14 to make the PPT pin of the radio low, and set it to the receiving state; meanwhile c1 = 0, 74HC125A leads The command received is input by the RXD terminal of the radio station, and is sent to the RXD pin of the single chip through the MAX232 level conversion, photoelectric isolation, 74HC125A buffer gate. When transmitting, P3.5 = 0, after 74HC14 reverse phase, photoelectric isolation, make the radio PPT pin high, set it to the transmitting state; meanwhile c1 = 1, 74HC125A cut off, c2 = 0, 74HC125B turn on, data It is output by the TXD pin of the single chip microcomputer, after 74HC125B buffer gate, photoelectric isolation, MAX232 level conversion, the data is sent out through the TXD port of the radio.

3 Communication software design

Communication software is essential, and if there is a problem, the entire system will be paralyzed. It is very important to adopt error control and fault tolerance technology.

* The command sent by the master control station contains a certain number of synchronization characters 55H and a 3-byte password. The measuring station conducts password verification after receiving 5 synchronization symbols in succession. After the verification is passed, the command byte is formally received; if it fails, the measuring station sends a signal to the main control station for retransmission. After three verifications, the command is stopped. When the measuring station sends / receives from the master station, the verification method is the same. After the verification is passed, the measuring station starts to send data.

* An instruction consists of 3 bytes, the second byte equals the first byte plus 35H, and the third byte equals the second byte plus 36H. If the received command does not comply with this rule, the command will be reissued, and it will be stopped when three consecutive errors occur.

* Each time the master control station sends a command, the measuring station sends back a response signal. The response signal contains the original command sample.

The basic communication program between the serial port of the microcontroller and the radio is given below.

Initialization procedure:

BTL EQU 2FH; baud rate is placed in the 2FH unit of internal RAM

MOV TMOD, # 21H; T0 mode 1, 16-bit counter, T1 mode 2, for serial port

SETB TR0; start T0

MOV BTL, # 0F3H; the baud rate is set to 1200

MOV SCON, # 0C0H; serial port mode 3, 9-bit data, reception prohibited

Reception and verification procedures:

NUM EQU 2BH; the value of the sync character is stored in the 2BH unit of the internal RAM

TEMP EQU 2CH

ROM-CH: DB 55H, 55H, 55H, 55H, 55H, 55H, 55H, 55H, 55H, 55H

DB 55H, 55H, 55H, 55H, 55H, 55H, 55H, 55H, 55H, 55H; 20-byte sync

MIM DB 'WSC': 3-byte password "WSC"

SETB P3.5; set radio receiving status

SETB REN; allows serial port reception

A1: MOV NUM, # 0; record the number of consecutive to 55H

A2: JB RI, A2; serial port has data to A3

A3: CLR RI; clear receive interrupt flag

MOV A, SBUF; read serial data

CJNE A, # 55H, A1; not sync to A1

INC NUM; add 1 to the number of sync characters received

MOV A, NUM; take the number of sync characters received

CJNE A, # 5, A2; 5 consecutive 55H to A2 not received enough

A4: MOV NUM, # 0; password verification, record the number of bytes received password

A5: MOV DPTR, #MIM; first address of password character

MOV A, NUM

MOVC A, @ A + DPTR; look up the table and get the password

MOV TEMP, A; save password

JB RI, A6; after the serial port receives one byte, it will be transferred to A6

…

A6: CLR RI; clear receive interrupt flag

MOV A, SBUF; read serial data

CJNE A, TEMP, A4; do not match the password to A4

INC NUM; add 1 to the number of passwords received

MOV A, NUM; take the number of password bytes received

CJNE A, # 3, A5; if the password is not received, transfer to A5

Sending procedure:

CLR P3.5; set radio transmission status

MOV B, # 23

MOV DPTR, # ROM-CH

B1: CLR A

MOVC A, @ A + DPTR; look-up table to send sync and password total 24 bytes

INC DPTR

LCALL SEND-CH; transfer single byte subprogram

DJNZ B, B1

…

CLR A

MOV DPTR, # 7000H; the first address of the external RAM data, send the data in the external RAM to the radio

B2: CJNE R4, # 0, B3

CJNE R3, # 0, B3; R4R3 = number of bytes sent

B3: MOVX A, @DPTR; fetch data

INC DPTR

LCALL SEND-CH

CJNE R3, # 0, B4

CJNE R4, # 0, B5

B4: DEC R3

LJMP B2

DEC R3

DEC R4

LJMP B2

…

SEND-CH: SETB TB8

MOV SBUF, A

DB 0, 0, 0, 0, 0, 0, 0, 0

JNB TI, $; delay 4μs

CLR TI

RET

Conclusion

After the completion of the wireless data transmission system, it has been used for more than two years. The operation results show that the system works stably and reliably. Due to the use of more complete hardware and software design and anti-jamming measures, to ensure the safety and reliability of the system. The measuring station transmits the collected field signals to the main control station in time, which improves the real-time nature of data processing. The software and hardware design of the interface between the single chip microcomputer and the digital radio station has strong applicability, and can be widely used in wireless data transmission equipment.

 Using Imported monocrystalline silicon solar panels which are common in aerospace fields such as space stations and satellite. The coversatio rate is as high as 21%. It has unique advantages in photoelectric conversion efficiency and speed and has a long service life of 5 ed e conversion rate
Using lithium iron phosphate battery, green and environmental protective, free of heavy metals, with charge/discharge hardware and software double protection technology. good high temperature technology, t can support large current discharge, life can be cycled more than 2000 times.

Solar lighting

Solar lighting

ZHEJIANG HUACAI OPTIC-TECHNOLOGY CO LTD , https://www.win3safety.com