Application of 51 single chip microcomputer in wireless data transmission

Publisher:码梦创想Latest update time:2011-12-28 Keywords:AT89C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The general digital acquisition system converts the captured field signal into an electrical signal through a sensor, and after sampling, quantization and encoding by the analog/digital converter ADC, it becomes a digital signal, which is stored in a data storage device, or sent to a microprocessor, or sent to the receiving end for processing by wireless means. The wireless data transmission system is a set 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 field signals, receives remote control commands and sends data. The main work of the main control station is to send remote control commands, receive data information, perform data processing and data management, and randomly display and print.

2 Serial communication between AT89C51 and digital radio

Atmel's AT89C51 microcontroller is a low-power, high-performance 8-bit CMOS microcontroller with 4KB Flash ROM on-chip, an operating voltage range of 2.7 to 6V (actually uses +5V power supply), and an 8-bit data bus. It has a programmable full-duplex serial communication interface that can simultaneously transmit and receive serial data. It communicates with the outside world through the RXD pin (serial data receiving end) and the TXD pin (serial data transmitting end).

2.1 Communication Protocol and Baud Rate

The communication protocol between the digital radio and the microcontroller and terminal host 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 uses Motorola's GM series car radio, which works in the VHF/UHF frequency band. It can perform wireless data transmission (9-wire standard serial RS232 interface) and voice communication. It adopts binary frequency shift keying (2FSK) modulation and demodulation, which complies with the CCITT.23 standard of the International Telegraph and Telephone Consultative Committee. When performing digital transmission in the voice band, it is recommended to use a data rate of no more than 1200b/s. In actual use, the radio works in the frequency range of 220~240MHz, and the half-duplex mode (performing receiving and transmitting operations, but not at the same time) can meet the system requirements.

2.2 AT89C51 serial port working mode

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

Before sending, the software sets the 9th data bit (TB8) as the parity bit, writes the data to be sent into SBUF, and starts the sending process. The serial port can automatically take out TB8, load it into the position of the 9th data bit, and then send it out one by one. After sending, TI=1.

When receiving, set REN in SCON to 1 to allow reception. When a transition from "1" to "0" (start bit) is detected at the RXD (P3.0 end), start receiving 9 bits of data and send them to the shift register (9 bits). When RI=0 and SM2=0 or the received 9 bits of data are 1, the first 8 bits of data are sent to SBUF, the 9th bit of data is sent to RB8 in SCON, and RI is set to 1; otherwise, this reception is invalid and RI is not set.

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

Mode 3 baud rate = T1 overflow rate / n

When SMOD = 0, n = 32; when SMOD = 1, n = 16. The overflow rate of T1 depends on the counting rate of T1 (counting 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 reload the initial value). Assume that the initial value of TH1 and TL1 is X, then T1 will overflow once every "2 8-X" machine cycles. The initial value X is determined as follows:

X = 256-fosc × (SMOD + 1) / 384 × 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. The microcontroller serial port is connected to the digital radio RS232 data port. The radio is in the receiving state (PPT=0, receiving state; PPT=1, sending state), and the microcontroller P3.5 pin outputs a high level. The microcontroller uses TTL level, and the radio uses RS232 level. MAX232 completes the conversion between TTL level and RS232 level. Three optocouplers 6N137 are used to isolate the power supply between the microcontroller and the radio, enhancing the anti-interference performance of the system.

The single-chip microcomputer controls the radio's transceiver conversion, command reception and data transmission through the three-state buffer gate 74HC125 with control terminal and the NOT gate 74HC14. When receiving, P3.5=1, c2=1, 74HC125B is cut off; P3.5 is inverted and photoelectrically isolated by 74HC14, making the radio's PPT pin low level and setting it to the receiving state; at the same time, c1=0, 74HC125A is turned on, and the received command is input from the radio's RXD terminal, and sent to the single-chip microcomputer RXD pin after MAX232 level conversion, photoelectric isolation, and 74HC125A buffer gate. When transmitting, P3.5=0, and the radio's PPT pin is at a high level after being inverted and optically isolated by 74HC14, setting it to the transmitting state; at the same time, c1=1, 74HC125A is cut off, c2=0, 74HC125B is turned on, and the data is output from the TXD pin of the microcontroller, and is sent out through the TXD port of the radio after being buffered by 74HC125B, optically isolated, and converted by MAX232.

3 Communication Software Design

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

*The command sent by the master station contains a certain number of synchronization symbols 55H and a 3-byte password. The measuring station verifies the password after receiving 5 synchronization symbols in succession. After the verification is passed, the command byte is officially received; if it fails, the measuring station sends a signal to the master station to resend. If the verification fails three times, the command will be stopped. When the measuring station sends/the master station receives, the verification method is the same. After the verification is passed, the measuring station starts to send data.

*A command consists of 3 bytes, the second byte is equal to the first byte plus 35H, and the third byte is equal to the second byte plus 36H. If the received command does not meet this rule, the command will be resent, and the command will be stopped after three consecutive errors.

* Every time the master station sends a command, the measuring station sends back a response signal, which contains the original command sample.

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

Initialization procedure:

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

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

SETB TR0 ; Start T0

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

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

Receiving and Verification Procedures:

NUM EQU 2BH; The synchronization symbol value 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, 20-byte synchronization character

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

SETB P3.5; Set the radio receiving status

SETB REN ; Allow serial port to receive

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

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

A3: CLR RI; clear the receive interrupt flag

MOV A, SBUF; read serial port data

CJNE A, #55H, A1; not a synchronous symbol, transfer to A1

INC NUM; the number of synchronization symbols received plus 1

MOV A, NUM; Get the number of synchronization characters received

CJNE A, #5, A2; if you do not receive 5 consecutive 55H, you can switch to A2

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

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

MOV A, NUM

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

MOV TEMP, A ; save password

JB RI, A6; after receiving a byte, the serial port transfers to A6

A6: CLR RI; clear the receive interrupt flag

MOV A, SBUF; read serial port data

CJNE A, TEMP, A4; if the password does not match, transfer to A4

INC NUM; the number of passwords received plus 1

MOV A, NUM; Get 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 the radio transmission status

MOV B, #23

MOV DPTR, #ROM-CH

B1:CLR A

MOVC A, @A+DPTR; look up the table to send the synchronization symbol and password, a total of 24 bytes

INC DPTR

LCALL SEND-CH ; call the send single byte subroutine

DJNZ B, B1

CLR A

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

B2: CJNE R4, #0, B3

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

B3: MOVX A, @DPTR; get 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 wireless data transmission system was built, it has been used for more than two years. The operation results show that the system works stably and reliably. The use of relatively complete software and hardware design and anti-interference measures ensures the safety and reliability of the system. The measurement station transmits the collected field signals to the main control station in a timely manner, which improves the real-time performance of data processing. The software and hardware design of the single-chip microcomputer and digital radio interface has strong applicability and can be widely used in wireless data transmission equipment.

Keywords:AT89C51 Reference address:Application of 51 single chip microcomputer in wireless data transmission

Previous article:Communication software design of 51 compatible carrier communication microcontroller PL3105
Next article:Interface Design between 51 Single Chip Microcomputer and Serial AD Converter TLC0834

Recommended ReadingLatest update time:2024-11-16 21:28

AT89C51\52 programming principles
The programming principles of AT89C51 and AT89C52 are exactly the same. Both have a reprogrammable Flash ROM inside. The ROM capacity of AT89C51 is 4KB, while that of AT89C52 is 8KB. We take AT89C52 as an example to illustrate its programming principle: A: From the capacity of its ROM, we know that it needs 13 add
[Microcontroller]
Design of computer key peripheral circuit based on AT89C51RC
The computer key of the microcomputer anti-misoperation locking system is used to receive the operation ticket issued by the five-prevention host during the operation process, and then unlock the electric code lock and mechanical code lock in turn according to the content of the operation ticket, that is, to monitor
[Microcontroller]
Design of computer key peripheral circuit based on AT89C51RC
AT89C51 MCU Minimum System
            MCU Minimum System             As shown in Figure 2, the 89C51 is connected to a crystal oscillator and two capacitors through pins 18 and 19 to form an oscillation circuit, which can provide clock frequency for the microcontroller. Pin 9 forms a simple reset circuit through a 10kΩ resistor and a 10μF
[Microcontroller]
AT89C51 MCU Minimum System
Design and simulation of a simple 00-99 counter
  1 System Description   This system uses the AT89C51 microcontroller to make a manual counter. A touch switch K1 and K2 are connected to the P3.2 pin and P3.3 pin of the AT89C51 microcontroller as the manual counting button. A two-digit green common cathode digital tube (7SEG-COM-CAT-GRN) is connected to the P0.0 -
[Microcontroller]
Design and simulation of a simple 00-99 counter
About the application of AT89C51 system clock interrupt
Powerful clock interrupt In microcontroller programming, setting a good clock interrupt will enable one CPU to play the role of two CPUs, greatly facilitate and simplify program preparation, and improve the efficiency and operability of the system. We can put some routine programs that need to be executed regularly in
[Microcontroller]
Experiment of playing music with single chip microcomputer
Using a single-chip microcomputer to play music is probably one of the issues that single-chip microcomputer enthusiasts are interested in. Here we use the experimental board provided by the website to do this experiment, and understand the basic principles of single-chip microcomputers playing music, and related sourc
[Microcontroller]
Experiment of playing music with single chip microcomputer
Introduction to AT89C51 Microcontroller
AT89C51 is a low-voltage, high-performance CMOS 8-bit microprocessor with 4K bytes of flash programmable and erasable read-only memory (FPEROM), commonly known as a single-chip microcomputer. The device is manufactured using ATMEL's high-density non-volatile memory manufacturing technology and is compatible with the
[Microcontroller]
Introduction to AT89C51 Microcontroller
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号