1. Experimental task
Use the table to make port P1 change a single light: 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
Connect P1.0-P1.7 in the "MCU system" area to the L1-L8 ports in the "Eight-way LED indicator module" area with an 8-core cable. The requirements are: P1.0 corresponds to L1, P1.1 corresponds to L2, ..., P1.7 corresponds to L8.
4. Program design content
When using a table for programming, the following instructions must be used to complete
(1). Use the MOV DPTR, #DATA16 instruction to make the data pointer register point to the beginning of the table.
(2). Use the MOVC A, @A + DPTR instruction to add the value of the accumulator to the value of the DPTR, so that the program counter PC can point to the data to be retrieved from the table.
Therefore, as long as the control code is built into a table and MOVC A, @A + DPTR 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:
5. Program flow chart
Figure 4.5.2
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
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;
}
}
}
Previous article:Types of MCU Development Systems
Next article:Testing technology and the development of military aircraft maintenance system
Recommended ReadingLatest update time:2024-11-16 21:38
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- STC32G Series MCU Technical Reference Manual
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
- What the heck is uC/OS? What is it for?
- Can I still use the 300M annual card provided by Essence NB-IoT Development Board EC-01F-Kit after the evaluation is over?
- EEWORLD University Hall----PI KOL: Design a reliable switching power supply from scratch
- TI - MCU - MSP430 User Guide 6 -> CS Clock System
- Allegro--bundle setting problem
- STM32MP1(1)--CM4 MDK debugging project sharing
- What should I do if I don’t want to go to work on the first day of work in the new year? What are your good ideas?
- ? A general question. How does this varactor diode represent?
- How to use wire connectors?
- 7.5KW motor hard start problem?