1. Experimental task
: Use the table method to make the 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 schematic 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 the 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 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:
5. Program flowchart
Figure 4.5.2
6. 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;
}
}
}
Previous article:The circuit design and program analysis of advertisement light left shift based on 51 single chip microcomputer
Next article:Design Principle and Analysis of Alarm Based on 51 Single Chip Microcomputer
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- Studying Things to Gain Knowledge 06 Part 2 Van de Graaff Generator
- Do you know the UWB Promotion Organization? How do they introduce UWB?
- [ESP32-S2-Kaluga-1 Review] QR code implementation and simple trial experience
- RS485 interface electromagnetic compatibility design scheme
- TI-PMLK boost experiment board for TI's TPS55340 and LM5122
- Push-pull circuit
- Network communication---WiFi
- NSA Network Topology
- i.MX6ULL Embedded Linux Development 3-Kernel Porting
- [RISC-V MCU CH32V103 Review] + Use of TIM timer