1. Experimental tasks
Let's use the table-fetching method to implement the advertising light, so that port P1 can make a single light change: move left 2 times, move right 2 times, and flash 2 times (delay time 0.2 seconds).
2. Circuit diagram
Figure 4.5.1
3. Hardware connection on the system board
Use an 8-core cable to connect P1.0-P1.7 in the "MCU System" area to the L1-L8 ports in the "Eight-way LED Indicator Module" area. The requirements are: P1.0 corresponds to L1, P1.1 corresponds to L2, ..., P1.7 corresponds to L8.
4. Programming content
When programming with a table, use the following instructions to complete
(1) Use the MOV DPTR, #DATA16 instruction to set the data pointer register to the beginning of the table.
(2) Using the instruction MOVC A, @A + DPTR, the program counter PC can be pointed to the data to be retrieved from the table based on the value of the accumulator plus the value of DPTR.
Therefore, as long as the control code is built into a table, and the MOVC function is used to perform the code retrieval operation, some complex control actions can be easily processed. The table retrieval process is shown in the figure below:
Program flowchart[page]
6. Assembly source program
ORG 0
START: MOV DPTR,#TABLE
LOOP: CLR A
MOVC A,@A+DPTR
CJNE A,#01H,LOOP1
JMP START
LOOP1: MOV P1,A
MOV R3,#20
LCALL DELAY
INC DPTR
JMP LOOP
DELAY: MOV R4,#20
D1: MOV R5,#248
DJNZ R5,$
DJNZ R4,D1
DJNZ R3,DELAY
RET
TABLE: DB 0FEH,0FDH,0FBH,0F7H
DB 0EFH,0DFH,0BFH,07FH
DB 0FEH,0FDH,0FBH,0F7H
DB 0EFH,0DFH,0BFH,07FH
DB 07FH,0BFH,0DFH,0EFH
DB 0F7H,0FBH,0FDH,0FEH
DB 07FH,0BFH,0DFH,0EFH
DB 0F7H,0FBH,0FDH,0FEH
DB 00H, 0FFH,00H, 0FFH
DB 01H
END
7. C language source program
#include
unsigned char code table[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f,
0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f,
0x7f,0xbf,0xdf,0xef,
0xf7,0xfb,0xfd,0xfe,
0x7f,0xbf,0xdf,0xef,
0xf7,0xfb,0xfd,0xfe,
0x00,0xff,0x00,0xff,
0x01};
unsigned char i;
void delay(void)
{
unsigned char m,n,s;
for(m=20;m>0;m--)
for(n=20;n>0;n--)
for(s=248;s>0;s--);
}
void main(void)
{
while(1)
{
if(table[i]!=0x01)
{
P1=table[i];
i++;
delay();
}
else
{
i=0;
}
}
}
The above is the full source code of the advertising light design
Previous article:Single chip microcomputer IO parallel port directly drives LED display technology
Next article:Using software delay to realize 00-59 seconds single chip computer timing
- Popular Resources
- Popular amplifiers
- Practical Development of Automotive FlexRay Bus System (Written by Wu Baoxin, Guo Yonghong, Cao Yi, Zhao Dongyang, etc.)
- Pattern-Oriented Software Architecture Volume 4 A Pattern Language for Distributed Computing
- Flash transfer protocol details
- Unix Basics Getting Started Manual If you are not afraid of reading the original text, just download it and have a look
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
- LM46002AQ
- [TI millimeter wave radar evaluation]_1_AWR1843BOOST unboxing
- A brief introduction to FPGA
- CrumpS2 ESP32-S2 Development Board
- TI full range of component libraries (component library, package library, 3D library) collection
- Share some resources about PID control, take them away quickly!
- Parameter calculation help for a zero-crossing detection circuit
- [Voice and vision module based on ESP32S3] Hardware design, debugging and progress-1
- 『Anxinke Bluetooth Development Board PB-02-Kit』-1: Try "pb-download"
- msp430F548A cannot execute program after power off and then on