1. Experimental tasks Use P1.0-P1.3 of the microcontroller to connect four light-emitting diodes L1-L4 to indicate the current count data; use P1.4-P1.7 as the input end of the preset data, connect four toggle switches K1-K4, and use P3.6/WR and P3.7/RD ports to connect two touch switches to act as add-count and subtract-count switches. The specific circuit schematic is shown in the figure below. 2. Circuit diagram
3. Hardware connection on the system board (1) Remove the short-circuit cap of P0.0-05 pin . (2) Change the status of K1-K4 by connecting P0.0-P0.3 pins to the positive and negative poles. (3) Connect the common line at the bottom of the button to the negative pole, and the buttons of P0.6 and P0.7 pins are effective. 4. Programming content (1. Processing of two independent key recognitions; (2. Problems with reading preset initial values ; (3. LED output indication 5. Flowchart 6. 汇编源程序 COUNT EQU 30H ORG 00H START: MOV A,P3 ANL A,#0FH MOV COUNT,A MOV P1,A SK2: JB P3.6,SK1 LCALL DELY10MS JB P3.6,SK1 INC COUNT MOV A,COUNT CJNE A,#16,NEXT MOV A,P3 ANL A,#0FH MOV COUNT,A NEXT: MOV P1,A WAIT: JNB P3.6,WAIT LJMP SK2 SK1: JB P3.7,SK2 LCALL DELY10MS JB P3.7,SK2 DEC COUNT MOV A,COUNT CJNE A,#0FFH,NEX MOV A,P3 ANL A,#0FH MOV COUNT,A NEX: MOV P1,A WAIT2: JNB P3.7,WAIT2 LJMP SK2 DELY10MS: MOV R6,#20 MOV R7,#248 D1: DJNZ R7,$ DJNZ R6,D1 RET END
|