51 single chip microcomputer learning parallel port experiment, water lamp, double flash lamp

Article catalog

1, Experimental purpose

Master 51 assembly language design and debugging methods Master the operation steps of protues software platform and experimental box

2, Experiment contents and steps

The 8KB RAM chip 6264 is extended outside the single chip microcomputer, and its address range is 0000H~1FFFH. Transfer the 15 data stored from 500H in the on-chip program storage space to the unit starting from 100h in the external RAM. Please write a program to implement, view and give the content of the relevant address space.

1. Figure 1-1 circuit analysis: (1) P0 port is time-sharing multiplexed into data line and address line; 74LS373 address latch, whose enable end LE is controlled by ALE (address latch control signal); the Q end of 74LS373 is connected to the address end of external RAM6264. When accessing the external storage unit, ALE signal is valid and locks the address value in 74LS373. (2) The MOVX instruction to access the external storage unit is a dual machine cycle instruction. In the first machine cycle, the address of the external storage unit is output from ports P0 and P2, and the ALE signal is valid to lock the address; in the second machine cycle, the ALE signal is cancelled, so that port P0 is dedicated to transmitting data and sending read / write signals at the same time.

2. Programming tips: (1) The data defined in the program is stored in the internal program storage space ROM. ORG 500H TAB: DB 11h,22h,33h,,,,0AAH,0BBH,,,0FFh (2) ROM instruction for reading program storage space: MOVC A,@A+DPTR (3) Read external storage RAM instruction: MOVX a, @ R0; P2 stores the upper 8 bits of the address (to assign a value to P2), and R0 stores the lower 8 bits of the address MOVX a, @ DPTR; 16 bit address stored in DPTR Read internal memory RAM instruction: MOV R1,60H MOV @R1,A

      ORG   0000H
      JMP   Start
      ORG   0100H
Start:	
      MOV DPTR,#TAB 		; The data pointer points to the first address of the definition byte
      MOV P2,#01H 		; P2.0 is high level
      MOV R0,#0 			; Number of transmitted data in R0
      
L0:
      MOV A,#0 			; Initial value 0 in accumulator A
      MOVC A,@A+DPTR	;Read internal program storage space ROM instructions
      MOVX @R0,A		;accumulator A The content in the is given to the outside RAM
      INC DPTR		;Data pointer plus 1
      INC R0		;Number of statistics plus 1
      CJNE R0,#10H,L0 		; If it is not equal, the transfer is not equal to 16. Go to l0 to continue saving the data to the external RAM
      
      ORG 500h		;inside ROM From 500 H Beginning
      
TAB:  DB 11H,22H,33H,44H,55H,66H,77H,88H,99H,0AAH,0BBH,0CCH,0DDH,0EEH,0FFH	;Definition byte

      END

The simulation results are as follows:

P1 port is used to control the LED lamp, which is displayed in the form of the following water lamp: 1. LED light shows single direction water flow from left to right (or from right to left) (only one light is on) and repeats round trip.

      ORG  0000H
      JMP  Start
      ORG  0100H
START:	
      MOV R0,#08H; set cycle 8 times
      MOV A,#0FEH; forward flow lamp a=1111 1110
LOOP1:  
      MOV P1,A        ;Turn on the first light p1=a=1111 1110(Common anode, low level on)
      LCALL DELAY     ;delayed
      RL A            ;A Move left one bit 1111 1101
      DJNZ R0,LOOP1   ;If minus 1 is not 0, the cycle is skipped
      LJMP START      ;Long jump command after lighting 8 lights in turn LJMP->reach START  It starts to cycle again  
DELAY:		      ;Delay subroutine
      MOV R7,#0FFH
D1:   MOV R6,#0AEH
D2:   
      NOP
      NOP
      DJNZ R6,D2
      DJNZ R7,D1
      RET

      END

The simulation results are as follows:

2. LED lights from left to right, and then from right to left two-way flow display (only one light is on), repeat round-trip.

	 ORG   0000H
	 JMP   Start
	 ORG   0100H
Start:	
	 MOV R0,#08H
	 MOV A,#0FEH; forward flow lamp    
LOOP1:  
	 MOV P1,A      ;Light up P1 Port low level lamp
	 LCALL DELAY   ;delayed
	 RL A          ;A Left ring shift 1 position
	 DJNZ R0,LOOP1
	 MOV R0,#08H
	 MOV A,#07FH; reverse flow lamp
LOOP2:  
	 MOV P1,A       ;Light up P1 Port low level lamp
	 LCALL DELAY
	 RR A           ;A Right ring shift 1 position
	 DJNZ R0,LOOP2
	 LJMP START    
	 
DELAY:	 MOV R7,#0FFH; delay subroutine
D1:  	 MOV R6,#088H
D2:  	
        NOP
	    NOP
	    DJNZ R6,D2
	    DJNZ R7,D1
	    RET
        END

The simulation results are as follows:

Realize double flashing

      ORG 0000H
      LJMP MAIN
      ORG 0030H

MAIN:
      CLR P1.0
      LCALL DELAY
      SETB P1.0
      LCALL DELAY
      CLR P1.7
      LCALL DELAY
      SETB P1.7
      LCALL DELAY
      LJMP MAIN
DELAY:		      ;Delay subroutine
      MOV R7,#0FFH
D1:   MOV R6,#0A8H
D2:   
      NOP
      NOP
      DJNZ R6,D2
      DJNZ R7,D1
      RET
      END

The simulation results are as follows:

Posted on Wed, 01 Dec 2021 16:45:04 -0500 by iKwak