1 Hardware Structure
When 89C52 is used as an interface, the interface itself must occupy as few hardware resources as possible, and the connection lines between the interface and the main system should be as few as possible, so that less host pins can be occupied and more resources can be left for the system. In this design, serial communication is used between the host and the multi-function interface. There are four connection lines between the host and the multi-function interface: CE, CLK, DAT, and INTR. CE is used as the chip select signal input terminal. When this pin is low, the host can transmit data with the multi-function interface. CLK is the clock input terminal. When the host sends an instruction to the multi-function interface, the level of this pin rises to indicate that the data is valid. DAT is the serial data input/output terminal. INTR is the output terminal of the multi-function interface. When the data in the multi-function interface is ready, INTR sends a low level to the host to notify the host that the data is ready and can be read. This signal can be queried by the host and can also be used as an interrupt request signal sent to the host.
The P0, P1, and P2 ports of 89C52 are used as keyboard/display interfaces. Keyboard input and display output are performed using the program scanning method. Port P0 is used as the field port, port P1 is used as the column input port of the keyboard, and port P2 is used as the word port of the display and the row scan output port of the keyboard. Since the current of the word port of the display is large, port P2 needs to be driven by current. This multi-function interface can connect up to 8 LED displays and 1 8×8 chain disk matrix. Its hardware principle is shown in Figure 1.
P3.2, P3.3, P3.6, and P3.7 are used as CE, CLK, DAT, and INTR signals respectively; while P3.0 and P3.1 are used as asynchronous serial communication data lines RXD and TXD; P3.4 and P3.5 are OUT0/T0 and OUT1/T1 signal lines respectively. When the timer works in continuous pulse mode, this pin can output continuous pulses with programmable on-off ratio and frequency; when working in counter mode, this pin is used as an external count pulse input terminal to input count pulses.
Since the multi-function interface receives instructions using software, the time periods t1, t2, t3, t4, and t5 in the figure are relatively long, and the time period t1-t4 is required to be between 10μs and 1000μs. There are two types of instructions: write instructions and read instructions. In write instructions, whether it is the opcode or the operand, the data transmission direction is from the host to the multi-function interface; while for read instructions, the data direction of the opcode part is from the host to the multi-function interface, and the data direction of the operand part is from the multi-function interface to the host.
t5 is the time interval required between the opcode and the operand in the read instruction, and t5 should be in the range of 30μs to 1000μs. During the read operation, when the rising edge of the CLK clock arrives, the multi-function interface sends the data to the DAT pin.
3 Instruction encoding
The multi-function interface has a total of 13 instructions. The instruction length varies from 1 byte, 2 bytes, 3 bytes, and 4 bytes.
(1) Reset instruction
The machine code is 00H. When the multi-function interface receives the reset command, all characters are blanked, all timers are cleared, and the timing interrupt and serial interrupt are turned off. Its status is similar to the system power-on reset.
(2) Display data command
This command sends display data to the display buffer of the multi-function interface. This is a 2-byte command, and its command encoding is as follows:
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
0
|
0
|
0
|
1
|
0
|
0
|
0
|
0
|
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
dip
|
0
|
0
|
0
|
d3
|
d2
|
d1
|
d0
|
Where dip is the decimal point control bit, a2, a1, a0 are bit addresses, d3, d2, d1, d0 are characters to be displayed, and their formats are listed in Tables 1 and 2.
(3) Flashing command
This command controls the flashing properties of each digital tube. d7~d0 correspond to digital tubes 1~8 respectively, 1 is flashing, and 0 is not flashing.
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
0
|
0
|
0
|
1
|
0
|
0
|
0
|
0
|
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
d7
|
d6
|
d5
|
d4
|
d3
|
d2
|
d1
|
d0
|
(4) Circular left shift instruction
The instruction code is 11H. This instruction shifts all displays from left to right by 1 bit.
Table 1
a2
|
a1
|
a0
|
Display bit
|
0
|
0
|
0
|
1
|
0
|
0
|
1
|
2
|
0
|
1
|
0
|
3
|
0
|
1
|
1
|
4
|
1
|
0
|
0
|
5
|
1
|
0
|
1
|
6
|
1
|
1
|
0
|
7
|
1
|
1
|
1
|
8
|
Table 2
d3
|
d2
|
d1
|
d0
|
Display Characters
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
0
|
1
|
1
|
0
|
0
|
1
|
0
|
2
|
0
|
0
|
1
|
1
|
3
|
0
|
1
|
0
|
0
|
4
|
0
|
1
|
0
|
1
|
5
|
0
|
1
|
1
|
0
|
6
|
0
|
1
|
1
|
1
|
7
|
1
|
0
|
0
|
0
|
8
|
1
|
0
|
0
|
1
|
9
|
1
|
0
|
1
|
0
|
-
|
1
|
0
|
1
|
1
|
H
|
1
|
1
|
0
|
0
|
L
|
1
|
1
|
0
|
1
|
P
|
1
|
1
|
1
|
0
|
E
|
1
|
1
|
1
|
1
|
null
|
(5) Circular right shift instruction
The instruction code is 12H. This instruction shifts all displays from right to left by 1 bit.
(6) Read keyboard instruction
The instruction is a 2-byte instruction, and the operand is the key value read. The key values of each keyboard are shown in Figure 1. The instruction format is as follows:
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
0
|
0
|
0
|
1
|
0
|
0
|
1
|
1
|
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
d7
|
d6
|
d5
|
d4
|
d3
|
d2
|
d1
|
d0
|
(7) Continuous pulse output instruction
This instruction programs the timer. It makes OUT0/OUT1 output continuous pulses. The on-off ratio and frequency of the pulses can be set by programming. The instruction is 4, and the format is as follows:
Byte 1
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
0
|
0
|
0
|
1
|
0
|
0
|
1
|
1/0
|
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
M3
|
M2
|
M1
|
M0
|
N3
|
N2
|
N1
|
N0
|
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
f15
|
f14
|
f13
|
f12
|
f11
|
f10
|
f9
|
F8
|
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
f7
|
f6
|
f5
|
f4
|
f3
|
f2
|
f1
|
f0
|
Where M:N is the on-off ratio of the pulse, and the setting range of M or N is 1 to 10. f15 to f0 is the frequency setting, and its setting range is 1 to 9999Hz. It is set in BCD code. In the instruction opcode, D0 sets timer 0 or timer 1 to work.
(8) Timer mode instruction
This instruction is a 3-byte instruction. The opcode is 22H or 23H, where D0 determines whether to operate timer 0 or timer 1. The second and third bytes are the timing time.
(9) Counter mode instruction
This instruction is a 3-byte instruction. The opcode is 24H or 25H, where D0 determines whether to operate timer 0 or timer 1. The second and third bytes are the initial count value.
(10) Read counter instruction
It is a 3-byte instruction. The opcode is 26H or 27H, and the second and third bytes are the count values read from the counter. The D0 bit of the opcode determines whether to operate counter 0 or counter 1. This instruction reads the current count value of the 16-bit counter.
(11) Serial send command
This command initializes asynchronous serial communication. Its command format is as follows:
Byte 1
Byte 1
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
0
|
0
|
1
|
1
|
0
|
a2
|
a1
|
a0
|
Table 2 Bytes
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
b1
|
b0
|
d5
|
d4
|
d3
|
d2
|
d1
|
d0
|
Byte 3
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
d7
|
d6
|
d5
|
d4
|
d3
|
d2
|
d1
|
d0
|
Byte 4
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
d7
|
d6
|
d5
|
d4
|
d3
|
d2
|
d1
|
d0
|
Serial communication is carried out in batch transmission. Each instruction transmits one data frame. In the instruction, the first and second bytes are used to initialize the serial communication, and the data after the third byte are sent. b1 and b0 are used to determine odd parity, even parity or no parity. The operands d5, d4, d3, d2, d1, and d0 of the second byte are used to set the number of data in the frame. A maximum of 64 characters can be sent in one frame. a2, a1, and a0 set the baud rate of the serial communication. The baud rates are listed in Table 3.
Table 3
a2 a1 a0
|
Baud rate
|
0 0 0
|
110
|
0 0 1
|
150
|
0 1 0
|
300
|
0 1 1
|
600
|
1 0 0
|
1200
|
1 0 1
|
2400
|
1 1 0
|
4800
|
1 1 1
|
9600
|
(12) Serial receive command
The instruction format is as follows:
Byte 1
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
0
|
0
|
1
|
1
|
1
|
a2
|
a1
|
a0
|
Byte 2
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
b1
|
b0
|
d5
|
d4
|
d3
|
d2
|
d1
|
d0
|
Byte 3
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
d7
|
d6
|
d5
|
d4
|
d3
|
d2
|
d1
|
d0
|
Byte 4
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
d7
|
d6
|
d5
|
d4
|
d3
|
d2
|
d1
|
d0
|
The instruction encoding is similar to serial transmission, and the data after the third byte is the received data.
(13) Read status instruction
The instruction format is as follows:
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
0
|
1
|
0
|
0
|
0
|
0
|
0
|
0
|
D7
|
D6
|
D5
|
D4
|
D3
|
D2
|
D1
|
D0
|
0
|
0
|
0
|
d4
|
d3
|
d2
|
d1
|
d0
|
When keyboard input, counter return, etc. or serial communication is interrupted, the multi-function interface will send a negative pulse to INTR. After responding, the host should send a read status instruction to query the status flag to determine which status flag is active. Among them, d0 is the keyboard input flag, d1 is the counter 0 return to zero action. d2 is the counter 1 return to zero flag. d3 is the serial reception end flag, and d4 is the serial transmission end flag.
4. Software Design of Multi-Function Interface
In the main program, display scanning and keyboard scanning are performed. If there is keyboard input, the key number of the keyboard matrix is found. The key number is stored in the key value register, and the status flag is set. At the same time, the INTR negative pulse is sent to notify the host to get the key value.
The host operates the multi-function interface through instructions. The host must first set CE to 0. The falling edge sends an external interrupt to the multi-function interface through P3.2. In the interrupt service program, the multi-function interface performs instruction fetch and decoding operations, and transfers to the corresponding processing channel through the scattered transfer instruction. Then the interrupt returns. At this point, the process of instruction fetch-decoding-execution of an instruction is completed. The program returns to the main loop to continue display scanning and keyboard scanning.
The so-called instruction fetch operation is actually the process of communication between the multi-function interface and the host. Since software is used for communication, the widths of t1, t2, t3, t4, and t5 have a certain range.
After receiving the operation instruction from the host, the serial communication between the multi-function interface and the peripherals and the operation of the related timers are carried out in interrupt mode. At the end of the interrupt, the status flag is set and the INTR negative pulse is sent to the host. This negative pulse can be queried by the host or used as an interrupt request signal to the host. After completing the above work, return to the main program.
5 Application Examples
In the online supplement of this journal (http://www.elecfans.com), the host is given as AT
Previous article:Design of a Serial Data Acquisition/Transmission Module for Single Chip Microcomputer
Next article:Indoor formaldehyde testing system based on 51 single chip microcomputer
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- Tips for taming ADC
- MSP430 MCU Timer A Structure and Application Examples
- How should the chassis ground of a high-speed interface connector be designed?
- SX1278LORA Module FAQ
- What effect does it have if a transistor is connected in parallel behind the differential line and a 10 ohm resistor is connected in series?
- Analysis of the characteristics of nrf24l01 wireless module
- A classic analog circuit worth collecting
- LM3644 Application Guide for Industrial Scanning
- TI's DSP OS running problem
- RA2L1 MCU download program JLink Info: T-bit of XPSR is 0 but should be 1.