; https://www.electronicshub.org/8051-microcontroller-assembly-language-programming/ ; $DATE (03.12.2020) $TITLE (Example 2: Blinking LEDs ) $PAGELENGTH(56) $PAGEWIDTH(150) $DEBUG $XREF $NOLIST $MOD51 $LIST ; ORG 00H ; Assembly Starts from 0000H. ; Main Program START: MOV P1, #255 ; Move 11111111 to PORT1. LCALL WAIT ; Call WAIT MOV A, P1 ; Move P1 value to ACC CPL A ; Complement ACC MOV P1, #0 ; Move ACC value to P1 LCALL WAIT ; Call WAIT SJMP START ; Jump to START WAIT: PUSH ACC PUSH PSW MOV R2, #8 ; Load Register R2 with 10 (0x0A) WAIT3: MOV R3, #255 ; Load Register R3 with 10 (0xC8) WAIT2: MOV R4, #255 ; Load Register R4 with 10 (0xC8) WAIT1: DJNZ R4, WAIT1 ; Decrement R4 till it is 0. Stay there if not 0. DJNZ R3, WAIT2 ; Decrement R3 till it is 0. Jump to WAIT2 if not 0. DJNZ R2, WAIT3 ; Decrement R2 till it is 0. Jump to WAIT1 if not 0. POP PSW POP ACC RET ; Return to Main Program END ; End Assembly