Design of infrared communication based on 51 single-chip serial port in multi-rate electric energy meter

Publisher:闪耀之星Latest update time:2011-11-04 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

0 Introduction

Multi-rate watt-hour meters are indispensable watt-hour metering products under the current electricity conservation and planned electricity consumption policies in my country. The communication interface of multi-rate watt-hour meters generally has both infrared interface and RS485 interface. Infrared communication has the advantages of being intuitive, easy to operate, and highly reliable. It is the most commonly used communication method in watt-hour meters and an effective means for realizing meter reading, programming, time calibration, data management, and other functions between watt-hour meters and handheld devices. The use of Xinmao single-chip microcomputer SSU7301 (51 series), infrared transmitting tube SE303 and infrared receiving tube PIC12043 of Japan Optoelectronics Corporation, as well as the serial port of the single-chip microcomputer and two timers/counters can effectively realize the infrared communication function.

1 Principle of infrared communication

Infrared communication is a communication transmission method that uses infrared waves with a wavelength of 900nm to 1000nm as the carrier of information. The transmitting device sends out binary signals after high-frequency modulation, and the receiving device demodulates the received infrared high-frequency signals into the original information. There are two modulation methods: pulse width modulation (by changing the pulse width modulation signal PWM) and pulse time modulation (by changing the time interval between pulse trains to modulate the signal PPM). This article uses PPM pulse time modulation.

2 Serial port infrared communication hardware design

The infrared transmitting and receiving circuits of the multi-rate electric energy meter mainly include the Xinmao single-chip microcomputer SSU7301, the infrared transmitting tube SE303 and the infrared receiving tube PIC12043 of Japan Optoelectronics Corporation, as well as the driving transistor 8550, resistors and capacitors. The infrared communication hardware schematic diagram is shown in Figure 1.

2.1 Infrared Transmitter Hardware Design

Infrared emission uses the serial data transmission port TXD (P3.1) of the single-chip microcomputer SSU7301 to control the driving transistor BG1 to transmit binary data "0" and "1" (data is sent from the serial transmission buffer SBUF), and uses the P3.4 port to control the driving transistor BG2 to perform high-frequency 38.4kHz modulation (the high-frequency driving signal is generated by the automatic reload mode of mode 2 of the timer/counter T0), thereby reliably realizing the infrared emission tube D1 to perform high-frequency infrared emission when transmitting data "0" and be cut off when data "1". The state relationship is shown in Table 1 and the waveform is shown in Figure 2.

2.2 Infrared receiving hardware design

Infrared reception uses the infrared receiving tube PIC12034 to receive a high-frequency signal and output a low level to determine the data "0", and if it does not receive a high-frequency signal, it outputs a high level to determine the data "1". After demodulation, the data is received serially through the serial data receiving port RXD (P3.0) of the single-chip microcomputer SSU7301 (the received data is stored in the serial port buffer SBUF). [page]

3 Infrared communication software design

DL/T645-1997 "Multifunctional Electric Energy Meter Communication" stipulates that the infrared carrier frequency of the electric energy meter is 38kHz±1kHz; the initial rate is 1200 bps; the byte format of the communication is 8-bit binary code D0~D7, and a start bit (0), an even parity bit P and a stop bit (1) are added during transmission, a total of 11 bits, and the low bit is transmitted first, followed by the high bit. The transmission sequence is shown in Figure 3. According to the above requirements, the infrared carrier frequency in this design is 38.4kHz, the baud rate is 1200bps, and the serial port uses mode 3 for 9-bit asynchronous communication, plus 1 start bit and 1 end bit, and the transmission of one byte of data is 11 bits.

3.1 Infrared carrier and timer/counter T0 settings

The infrared carrier frequency f2 is 38.4kHz. When C/T=0 and M1M0=10 in the timer/counter T0 mode controller TMOD, the timer/counter T0 of SSU7301 is set to mode 2. At this time, TL0 and TH0 are preset to an 8-bit timer/counter that can be automatically reloaded. After TL0 and TH0 are preset to the same initial value by software, when the TL0 count value increases by 1 and overflows, on the one hand, TF0 is set to 1 and an interrupt is requested; on the other hand, the overflow pulse generated automatically enters the data value of TH0 into TL0, and there is no need to re-initialize TL0 by software. The system's crystal oscillator f1 is 11.0592MHz, so the initial values ​​of TL0 and TH0 are calculated as follows:

f2=38.4kHz, so T=1/f2=1/38.4k≈26×10-6=26 μs
, so the period of high-frequency modulation reversal TC=T/2=26/2=13μs

That is, the initial value of timer/counter T0 is TL0=TH0=28-(TC×f1)/12=256-(13×10-6×11.0592×106)/12=256-11.9808≈244=0F4H.
In the interrupt service program of timer/counter T0, only two instructions are needed to realize high-frequency modulation, namely CPL P3.4 and RETI.

3.2 Serial Port and Timer/Counter T1 Baud Rate Generator Settings

The serial port uses mode 3 as a 9-bit asynchronous communication mode with a baud rate of 1200bps. The operation mode selection bits SM0 and SM1 of the serial port control register SCON are set to mode 3. When C/T=0 and M1M0=10 in the timer/counter T1 mode controller TMOD, the timer/counter T1 of SSU7301 is set to mode 2 as a baud rate generator, and its baud rate is expressed as:

Baud rate = (overflow rate of T1) / nWhen
SMOD = 0, n = 32; when SMOD = 1, n = 16, (SMOD = 0 in this design) then
Baud rate = (overflow rate of T1) × 2SMOD / 32
Overflow rate of T1 = (f1/12) / (28-initial value of T1)
So: Baud rate = (overflow rate of T1) × 2SMOD / 32
= [(f1/12) / (28-initial value of T1)] × 2SMOD / 32
So: Timer/counter T1 initial value
TL1 = TH1 = 28-(f1×2SMOD)/(12×32×baud rate)
= 256-(11.0592×106)/(12×32×1200)
= 256-24=232=0E8H

3.3 Programming

According to the setting of the above two parameters, the assembly language program design of 51 series single chip microcomputer SSU7301 is as follows:
The following is the parameter setting program
MOV TMOD, #22H ;Timer/counter T0 mode 2 automatic reload mode is used for PWM38.4KHZ modulation
, timer/counter T1 mode 2 automatic reload mode is used for serial port communication baud rate generator
MOV TH1,#0E8H ;When the baud rate is 1200, the timer/counter T1 automatically reloads the initial value
MOV TL1,#0E8H
MOV TH0,#0F4H ;When 38.4KHz high frequency modulation, the timer/counter T0 automatically reloads the initial value
MOV TL0,#0F4H
SETB ET0 ; Timer/counter T0 overflow interrupt enable bit
SETB TR1 ; Timer/counter T1 start timing control bit
SETB TR0 ; Timer/counter T0 start timing control bit
MOV PCON,#00H ;SMOD is 0, non-multiplication mode
MOV SCON,#0D0H ;Serial port is set to mode 3, allowing reception
SETB ES ;Serial port allows interrupt
SETB EA ;Open the general interrupt enable bit
; The following is the timer/counter T0 interrupt overflow service program
ORG 000BH; Timer/counter T0 interrupt entry address
T0SERVE:CPL P3.4 ; Timer/counter T0 timing inversion P3.4 port for high frequency modulation
RETI ; Interrupt return
; The following is the serial port interrupt service program, taking the reception of a byte of data as an example, and multiple bytes are analogous
ORG 0023H; Serial port interrupt entry address
SENDSERVE:NOP
NOP
MOV A,SBUF ; Send the data in the receive buffer to register A
... ; Perform data processing and other functional operations
RETI ; Interrupt return
; The following is the serial port sending program, taking the sending of a byte of data as an example, and multiple bytes are analogous
COMSEND: MOV A,#DATAH ; Send data to register A
MOV C,P ;Send the even parity bit generated by the data in A to the carry flag
MOV TB8,C ;Send the even parity bit to the 9th data to be sent
MOV SBUF,A ;Send data to the send buffer
JNB TI,$ ;Wait for the end of sending in query mode
CLR TI ;Clear the send interrupt flag
... ;Continue sending or other function operations
RET Subroutine returns

4 Conclusion

The biggest feature of this design is that the pulse oscillator is omitted, and only the serial port and two timers/counters of the single-chip microcomputer on the multi-rate electric energy meter are used, which not only makes the multi-rate electric energy meter simpler in hardware design and lower in cost, but also makes the software more convenient and reliable. At the same time, this infrared communication method can also be applied to the application field of single-chip microcomputers with serial ports and timers/counters.

Reference address:Design of infrared communication based on 51 single-chip serial port in multi-rate electric energy meter

Previous article:Design of intelligent infusion control system based on single chip microcomputer
Next article:Inkjet Printer Control Technology Based on 51 Single Chip Microcomputer

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号