The schematic of the marquee experiment is implemented in assembly language. The program is as follows: ORG 0 000H LJP START / / transfer to the main program ORG 0040H START:MOV SP, #60H//Settings Stack pointer OV A, # 0 F EH / / send A 11111110 ROTATE = MOV P1, A// write P1 SJMP ROTATE / / loop DELAY: MOV RO, AH// Time subroutine (1 second) DELAY 1 : 40V R1 , 110 OH DELAY2 , DOV R2 , # OB 3H DJNZ R2, $ DJNZ R1, DELAY2 DJNZ RO , Dl; LAYI RET// subroutine return END The program is written in C51 language to realize the marquee experiment. The procedure is as follows: # include < r eg5 1 . h> Void main (void)//Main letter number (unsigned Int n; Uns igned Char code I edp 1 8 1 = ( Oxf e , Oxfd , Oxf b , Oxf 7 , Oxef, Oxdf, Oxbf, Ox7f}; / / definition Array Unsigned char LEDi ; While(1)//infinite loop { P1= ledp [leDIL; / / value sent P1 port For (n= 0 ; n< 4 0 0 0 0 ; n++ ) ; //delay Ledi++;//force (x 1 If ( ledi== 8 ) Ledi= 0 ; } ) Through this two programs that realize the same function, it can be found that programming the MCU application system program in assembly language must be familiar with the internal resources and memory structure of the MCU, and must remember the fixed format of the MCU instruction system and process the port data according to the actual address. The use of C51 language to write single-chip application program does not require understanding of the instruction system of the single-chip microcomputer, without considering the hardware characteristics and interface structure of the single-chip microcomputer, using natural language, using the method of approximating human thinking, improving the readability of the program, and Make the program structured, easy to port, and improve the efficiency of the development process. In addition, because the 51 series MCU resources are very limited, try to use unsigned and byte variables when using C51, try to use local variables, the compiler can automatically declare some local variables as register variables. The assembly code generated by the program written in C language compiled in KeilμVision3 simulation software is as follows: C : OXO 8 0 0 ESO 8 P10V A, OXO 8 C; OXO802 90084F MOV DPTR, Teach OxO84F C: OX 0805 93 MO vC A, @A+ DPTR C : OXO 8 0 6 F59 0 DOv Pl (Ox90 ( , A C: OxO808 900000 MOV DPTR, { 10xO 0 0 0 C : OXO 8 OB AF 82 MOV R7 , DPL (Ox82) C : OXO 8 OD AE 83 MO v R6 , DPH ( Ox83 ) C : Ox O8OF E4 CLR A C: OxO810 FC MOV R4, A C = Ox O8l1 FD I4OV R5 , A C : Ox0812 7B40 MOV R3 11 OX 4 0 C : OX 0814 7A9C MOV' R2 , Well Ox9C C : OX 0816 F9 MO v R1 , A C : OX 0817 F8 MOV RO , A C ; Ox0818 D3 SETB C C : Ox0819 12 082D LCALL (C : 082D) C : OXO 81C 4003 JC C : 0821 C = Ox O81E A3 INC DPTR C : Ox081 F 80EA SJMP C : 08 OB C:OxO821 0508 work NC OXO8 C : Ox O 82 3 E5 0 8 MOV A , Ox0 8 C= Ox0825 B408D8 CJNE A, 1} Ox O 8 , main ( C : 0 8 0 0 ) C : OX 0828 E4 CLR A C = Ox0 8 2 9 F5 0 8 MOV OXO 8 , A C : Ox082 B 80D3 SJMP main (C: 0800) C = Ox O 82D EB MOV A , R3 C : OX 082E 9F SUBB A, R7 C : Ox082 F FSF 0 MOV B (OXFO), A C : Ox0 83 1 EA MOV A, R2 C : Ox0832 9E SUBB A, R6 c: OX 0833 42F0 ORL B ( OXF 0 ) , A C : Ox083 5 E9 MOV A, R1 C : Ox083 6 9D SUBB A, R5 C: Ox0837 42F0 ORL B ( OXFO ​​) , A C : Ox0 83 9 EC DOV A , R4 C = Ox0 8 3A 64 8 0 XRL A , {} PO ( Ox80 ) C : OX 083C C8 XCH A, R0 C : Ox O 8 3 D 6 4 8 0 XRL A , { f PO ( Ox80 ) C : OX 0 83F 9 8 SUBB A, R0 C : Ox0840 45F0 ORL A, B ( OXFO ​​) C : OX 0842 22 RET C : Ox0 8 4 3 7 87F MO v R0 Well OX7F C : OX 0845 E4 CLR A C : Ox0846 F6 MOV 6; RO , A C = Ox0847 D8FD DJNZ RO , C 0846 C ; OX 0849 758108 MOV SP ( Ox8 1 ) , l10x0 8 C: OxO84C 020800 LJ site P main (C: 0800) C : OX 0 8 4F FE 10V R6 , A C : OXO 8 5 0 FD OV R5 , A C : OX 0851 FB MOV R3 , A C : OX 0852 F7 MOV OR I , A C : Ox O 8 53 EF MO v A , R7 C ; Ox0 85 4 DFBF DJNZ R7 , C : 0815 C : Ox O 8 5 6 7 F0 0 MOV R7 , Gan σxOO By comparing the assembler generated by the C51 program with the KeilμVi-sion3 software and the program written directly in assembly language, the C51 language has 54 instructions after compilation, and only 17 instructions are required to be written directly in assembly language. It can be seen that the code of the single-chip microcomputer directly written in assembly language is highly efficient. In addition, we can also observe the list generated after compiling the connection. MAP or. M51 file, in which the information assigned to the variable and the address of the code and the size of the generated code are detailed, we can understand whether the code is optimized, whether the variable allocation is reasonable, whether the stack overflows, etc. No matter whether it is assembly language or program written in C51 language, it is not a program directly run by MCU. Only the machine code program can run directly. For assembly language programs, it needs to be compiled into machine code program through assembly program. For C51 program, it needs to be compiled by compiler program. Into the machine code program. You can write a source program in a different programming language in an application, and finally generate an executable complete program through a compiler/connector. This programming method is called mixed programming and can be used when writing a microcontroller application. C51 and assembly language mixed programming, generally written in assembly language hardware-related programs, C51 to write the main program and data processing program. Medical Device Processing,Hardware Processing,Auto Parts Processing, CNC Machining ShenZhen Haofa Metal Precision Parts Technology Co., Ltd. , https://www.haofametals.com
The current development of single-chip application system program mainly uses assembly language and C51 language. It is written in assembly language to directly manipulate the hardware resources of the system. It can write efficient running code and the program runs fast. The use of C51 language can improve the readability and portability of the program, which is conducive to the upgrading of the product, greatly speeding up the development of the MCU application. Let's analyze the difference between the two languages ​​through a simple experiment, the marquee experiment. The schematic diagram of the marquee experiment realized by AT89C5l is shown in the xia diagram.