1. Circuit function and display content
This circuit is composed of AT89C51 connected to the display dot matrix module composed of 64 light-emitting diodes such as VD1-1 to VD8-8 through the P0 port and the P2 port. Through the corresponding row and column potential control, after power-on, the dot matrix module displays the words "OK", "ST", "JC" and "二" in turn, and the cycle repeats.
2. Circuit principle
The whole circuit is composed of AT89C51, display module and driving transistors VT1 to VT8, etc. The circuit principle is shown in Figure 1.
A total of 64 light-emitting diodes VD1-1 to VD8-8 in the dotted line of Figure 1 constitute a dot matrix module for displaying characters. This module is specially used for LED display screens. The model is TOM-2088BE-B, and this dot matrix module has 16 pins. The dot matrix layout on the front of the dot matrix module is shown in Figure 2, and the pin arrangement on the back is shown in Figure 3. In Figure 1, the serial numbers marked on the row and column lines connected to IC1 outside the dotted line are the module pin numbers. The entire display dot matrix is connected in the form of row and column control, with 8 row lines connected to the 8 I/O lines of the P0 port respectively, and 8 column lines connected to the 8 driving transistors controlled by the 8 port lines of the P2 port respectively. In this way, when we send a control word #80H to the P2 port, P2.7 is at a high potential, while P2.6 to P2.0 are all at a low potential. Therefore, the high potential of P2.7 turns on VT1 through R17, and the cathodes of the eight light-emitting diodes from VD1-1 to VD1-8 are all connected to the ground, which provides an enabling condition for the conduction of the first column of light-emitting diodes composed of VD1-1 to VD1-8. At this time, if we send the font data to the P0 port, the corresponding diodes will be lit, and the dot matrix pixels will be displayed. For example, if we send data #7EH to the P0 port, VD1-2 to VD1-7 will be lit. The figure presented in the leftmost column of the module is shown in the first column on the left in Figure 2. If we move the high potential of the P2 port to the right in turn, VT1 to VT8 will be turned on in turn, and the enabling condition will be converted from the first column to the eighth column in turn. When VT1 to VT8 are turned on, we send data #7EH, #42H, #7EH, #00H, #FFH, #28H, #44H, #82H to the P0 port in turn. The graphics displayed by the dot matrix module are shown in Figure 2, that is, the character "OK" is displayed, which realizes the display of characters. The process of VT1 to VT8 being turned on in turn, so that the diodes in the first to eighth columns can obtain the light-emitting enabling conditions in turn, is usually called scanning. Since the light-emitting diodes in the dot matrix module do not have afterglow, they will go out when the power is off. If this kind of scanning is not performed, either only one column of pixels can be displayed, or several columns or all columns will display the same pixels. Therefore, only by continuously sending the dot matrix data of characters or graphics through the P0 port, and then displaying each column in turn for a certain period of time under the control of the P2 port, can the module display the pixels of the entire graphic completely. Therefore, only when the system scans repeatedly can the dot matrix module display stable characters and graphics.
3. Use of on-chip RAM and character activity principle
Since the characters to be displayed in this system are active, the position order of all character data in the storage space needs to be constantly changed. Therefore, it is impossible to change the dot matrix data to be displayed by only storing it in the program storage area, because the program memory is a read-only memory and cannot be rewritten in the application system, while the RAM in the microcontroller is a readable and writable static memory with a very short access time, which is specially used to store data that needs to be frequently rewritten. Therefore, only by storing all the dot matrix codes of the active characters to be displayed in this system in the on-chip RAM, under the control of the program, according to the current display needs, corresponding changes are made, and then sent out through the P0 port, can the characters displayed in the dot matrix module be activated.
We have said that the AT89C51 chip has 128 bytes of RAM, and the address space is 00H to 7FH. Among them, 00H to 2FH have special functions, so we can store the font data of the characters to be displayed starting from 30H. As shown in Figure 4, the font data of "OK", "ST", "JC" and "二" are 56 bytes in total, and we store them in units 30H to 67H. In Figure 4, the bits with data "1" are colored, and the bits with data "0" are blank, and the corresponding relationship between the character graphics to be displayed and the font data is clearly shown. In the aforementioned scanning process, when scanning the first column, that is, sending the control word #80H to the P2 port, P2.7 is at a high potential, the CPU sends the content in the 67H unit in the RAM to the P0 port, so the meaning of the font data in 67H is expressed in the leftmost column of the LED dot matrix module with different light and dark points, completing the corresponding conversion of the font data and the image. After that, the high potential of P2.7 gradually moves to P2.0, and scans in sequence, and the CPU sends the contents in the RAM area 66H to 60H to the 2nd to 8th columns of the dot matrix module through the P0 port in sequence for display. At this point, a complete frame of graphic display is completed. Then, we can return to 67H to get the font data for the next frame scan. Since each bit of data from 67H to 60H corresponds to VD1-1 to VD8-8 in the dot matrix module, the 8 storage units from 67H to 60H are the character display buffer. In the entire data block from 30H to 67H in the RAM, only the data between 60H and 67H will be sent to the dot matrix module for display. If the display dot matrix is like a movie screen, the entire data block is the film. The interval from 30H to 67H is the lens of the movie projector. Only after all the data reaches this interval, that is, the display buffer, will the graphic information it represents be "projected" in the dot matrix module. Therefore, if you want to display the characters "ST", "JC", "No. 2" and so on after "OK", you can achieve it by moving the data from 5FH to 30H upward byte by byte. The specific process is, first send the content of 67H to 68H, empty the 67H unit, and then move the following bytes up one by one until 56 bytes are moved, and the content in 30H is moved to 31H. At this point, the entire data block is moved up by one address space, and the font "OK" in the dot matrix module is also moved to the left by one column, and the character begins to "activate". After the entire data block is moved up by one address space, the data moved to 68H must be moved to 30H again, because only in this way can the entire font data not be lost due to being overwritten in the subsequent movement, and the integrity and continuity of the data block can be guaranteed. In this way, the above data moving process is repeated continuously, and the entire data block will continuously pass through the display buffer composed of 60H to 67H, and all characters will scroll through the dot matrix module, thus realizing the mobile display of characters.
4. Program design and main instructions
The design idea of this example program is: after power-on, first send #00H to P0 and P2 ports, turn off the display to complete the initialization. Then load the font data of all characters and scan and display them. After continuous scanning for 0.5s, move the data block up one byte, and then return to the scanning program and data block moving program, and repeat. The continuous scanning time is set in the main program.
1. Loading font data and table lookup instructions
Using table lookup instructions to form a table lookup subroutine can make the procedure of loading font data from program memory to on-chip RAM shorter, and can make the font data stored in the program storage space centralized.
As can be seen from the above, all font data is 56 bytes. If the ordinary data transfer instruction MOV direct, #data is used, 3 bytes of program code are required to complete each byte of data. For example, to send the first column of font data #7EH of the "OK" font to the 67H space of the on-chip RAM, the instruction is MOV 67H, #7EH; the machine code is 75677EH. In this way, the program to transfer 56 bytes of font data requires 168 bytes of program code, which occupies a large space. However, using the table lookup instruction to complete the transfer of the above 56 bytes of font data, all program codes are completed with only 76 bytes, which is 92 bytes less than using the general data transfer instruction, which not only saves program storage space, but also makes program design simple.
The table lookup instruction MOVC A, @A + PC, the machine code is 83H. The execution result is to add the content in accumulator A to the value in program address register PC to get the unit address of the program storage space being searched (the address of the data table), and then send the content of the unit to accumulator A, where PC is used to store the address of the next instruction. For example, if we first store the immediate value #01H in the 69H unit of RAM, after executing the MOV A, 69H instruction at the address 0078H in the program memory, the value in accumulator A is #01H. If the starting address of the data table is 007CH, after executing the next MOVC A, @A + PC instruction, the word data #7EH in 007CH is sent to accumulator A. Because after executing the MOV A, 69H instruction at 0078H, the value in the CPU's program address register PC is #007AH, the CPU directly goes to 007AH to get the program code to identify the execution. Since the instruction placed in 007AH is a special variable address table lookup instruction, after execution, the value in PC will not only automatically increase by 1 to become #007BH, but also add the value in A to the value in PC to get an address pointing to the storage unit of the fetched data. Since the value in A is #01H, the CPU will fetch the immediate number #7EH from 007C and store it in A, and then execute the instruction at 007BH. The above is also the execution process of the table lookup subroutine. After returning to the main program from the table lookup subroutine, under the control of the main program, the font data in A is stored in 67H of the on-chip RAM. It is not difficult to understand from the above that we add 1 to the content in 69H after each fetch. In this way, by continuously calling the table lookup subroutine, the CPU will transfer all the font data in the font data table to the on-chip RAM byte by byte.
2. Scanning program and accumulator circular shift instruction
The scanning program enables the microcontroller to continuously change the high and low potentials of each port line of port P2 after sending data to port P0, so that VT1 to VT8 are turned on in sequence to complete the display of the entire character or graphic. The most convenient way is to use the accumulator circular shift instruction to achieve the potential change of each port line of port P2.
According to the scanning display process described above, it is extremely convenient to use the accumulator circular shift instruction to complete the high potential movement in port P2. Accumulator A is the most frequently used register with special functions in the microcontroller. The RR A instruction can circularly shift the content in A to the right. The instruction code is 03H. The result of executing this instruction is (An+1)→(An), (A0)→(A7). As shown in Figure 5. If the data loaded in A is #80H, that is, 1000 0000B, after executing RR A, the data in A is #40H, that is, 0100 0000B. All data are shifted to the right by one position, and the original lowest position is transferred to the highest position, and the only high potential is also shifted to the right by one position. Therefore, to make only one line of P2 port present high potential and move to the right circularly, first execute MOV A #80H, then execute MOV P2, A, send #80H to P2 port, then execute RR A to complete a cycle, and then execute MOV P2, A to send the control word after the cycle to P2 port. Load the immediate number #80H into A. After 8 times of the above operation process, P2 port will present high potential from P2.7 to P2.0 in sequence, completing the aforementioned scanning task.
3. Data block moving program and register indirect addressing data transfer instructions
The data block moving program can move the font data block in the on-chip RAM upward as a whole. When the main program continues to run, all font data will pass from 60H to 67H in the RAM, so that the characters displayed by the system are displayed in the dot matrix module in the form of a "pull curtain".
We first send immediate values #68H and #67H to R0 and R1 respectively, and then execute MOV A, @R1 and MOV @R0, A, which are two register indirect addressing data transfer instructions. The result is that the data in the storage unit with the content in R1 as the address is first sent to the accumulator A, and then the content in A is sent to the storage unit with the content in R0 as the address, which sends the font data in the on-chip RAM 67H to 68H. Then reduce the contents in R0 and R1 by 1, so that the content in R0 becomes #67H, and the content in R1 becomes #66H. Repeat the previous process and send the font data in 66H to 67H. By analogy, repeat the above process 56 times, and the font data in the on-chip RAM 30H will be sent to 31H. At this point, the entire font data block has moved up one address space. After that, MOV 30H, 68H must be executed to send the font data in 68H to 30H, so that the font data block can be connected from beginning to end.
4. Short transfer instruction
In order to realize continuous scrolling display, after completing the loading of font data, scanning display and data upshifting, the CPU needs to return to the scanning display to loop through the scanning and data block upshifting procedures, so a short transfer instruction SJMP (the machine code of the instruction is 80H) must be placed at the end of the data block shifting procedure. After executing this instruction, the program will transfer to the entry of the scanning program and start another scanning and data block upward operation. For example: SJMP 0051H, that is, the program will transfer to the address 0051H in the program memory and execute the program there. The transfer range of instruction SJMP rel is -128 to +127.
V. Other instructions involved in this article
Arithmetic operation instructions:
INC Rn: The execution result is to add 1 to the content of register Rn.
DEC Rn: The execution result is to subtract 1 from the content of register Rn.
VI. Program List
address |
Machine code |
instruction |
Notes |
|
0000 |
02003B |
AJMP |
003BH |
; Go to main program |
003B |
758000 |
MOV |
P 0 ,#00H |
;initialization |
003E |
75A000 |
MOV |
P2 , # 00H |
; Turn off display |
0041 |
7938 |
MOV |
R 1 , #38H |
; Import font data |
0043 |
7867 |
MOV |
R 0 ,#67H |
; Set the font storage starting address |
0045 |
756901 |
MOV |
69H, #01H |
; Send the starting address of the font data table |
0048 |
120078 |
LCALL |
0078H |
; Questionnaire subroutine |
004B |
F6 |
MOV |
@R 0 ,A |
; Fonts are sent to RAM |
004C |
18 |
DEC |
R 0 |
; |
004D |
0569 |
INC |
69H |
; |
004F |
D9F7 |
DJNZ |
R 1 |
; Unfinished, return |
0051 |
7D18 |
MOV |
R 5 , #18H |
; Set the scan time constant |
0053 |
7EFF |
MOV |
R 6 , #FFH |
; |
0055 |
7F08 |
MOV |
R 7 , #08H |
; Set the number of scan columns |
0057 |
7860 |
MOV |
R 0 ,#60H |
; Set the display buffer low address |
0059 |
7480 |
MOV |
A, #80H |
; Send column scan start control word |
005B |
8680 |
MOV |
P 0 ,@R 0 |
; Output font data to display screen |
005D |
F5A0 |
MOV |
P 2 ,A |
; Output column control word to the display screen |
005F |
08 |
INC |
R 0 |
; Prepare the next byte of the font |
0060 |
03 |
RR |
A |
; Prepare to scan the next column |
0061 |
DFF8 |
JZ JZ |
; Unfinished return |
|
0063 |
DEF0 |
DJNZ |
R 6 |
; |
0065 |
DDEC |
DJNZ |
R 5 |
; |
0067 |
7F38 |
MOV |
R 7 , #38H |
; Set the total number of bytes of font data moved |
0069 |
7868 |
MOV |
R 0 ,#68H |
; Set the block move temporary storage unit address |
006B |
7967 |
MOV |
R 1 , #67H |
; Set the moving block to the start address |
006D |
E7 |
MOV |
A, @R 1 |
; |
006E |
F6 |
MOV |
@R 0 ,A |
; Move up one address |
006F |
18 |
DEC |
R 0 |
; Go to the next byte |
0070 |
19 |
DEC |
R 1 |
; |
0071 |
DFFA |
DJNZ |
R 7 |
; If there are less than 56 bytes, continue to move |
0073 |
856830 |
MOV |
30H,68H |
; End to end |
0076 |
80D9 |
SJMP |
0051H |
; Jump to 0051H |
0078 |
E569 |
MOV |
A,69H |
; Get the lookup table increment value |
007A |
83 |
MOVC |
A,@A+PC |
; Get font data |
007B |
twenty two |
RET |
|
; Subroutine returns |
007C |
7E 42 |
7E 00 |
FF 28 44 |
82 Font Data Sheet |
00 00 |
4C 92 |
92 92 64 |
00 |
|
00 06 |
02 FE |
FE 02 06 |
00 |
|
00 00 |
04 85 |
FD 04 00 |
00 |
|
7C FE |
82 82 |
82 46 00 |
00 |
|
40 44 |
A4 A5 |
96 8C 84 |
80 |
|
00 20 |
24 24 |
24 24 24 |
20 |
Previous article:Using AT89C51 to realize self-setting time control
Next article:Understanding MCU from AT89C51
- Popular Resources
- Popular amplifiers
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!
- 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
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- The embedded operating systems I have come into contact with - rtx51, freertos, etc.
- Design of high-speed counter based on FPGA.pdf
- Problems encountered in learning C programming language
- 5G Common Terms and Abbreviations
- I found a very good introductory book on 51 single-chip microcomputers and recommend it to beginners. It is suitable for self-study by novices (Wang Yun)
- Application of Bypass Capacitors in High-Speed Circuit Environment
- Design of software and hardware C delay program for MSP430
- IC layout Seeking talents Seeking talents Seeking talents Seeking talents Coordinates: Shanghai, Shandong, Nanjing
- Optical module SFF-8472 problem solving
- Develop smart devices based on ESP32 to access the smart home ecosystem HomeAssistant