1. Experimental tasks Use AT89S51 single-chip microcomputer to make a manual counter. Connect a touch switch to the P3.7 pin of the AT89S51 single-chip microcomputer as a manual counting button. Connect a common cathode digital tube to the P2.0-P2.7 of the single-chip microcomputer as the unit digit display of 00-99 counting. Connect a common cathode digital tube to the P0.0-P0.7 of the single-chip microcomputer as the tens digit display of 00-99 counting. The hardware circuit diagram is shown in Figure 19. 2. Circuit diagram 3. Hardware connection on the system board We only need to remove 7 of the 8 short-circuit caps in the 4*4 button, because we only use one button. Then use a double-ended connecting wire to connect the pin of this button to the negative node. The LED part does not need to be changed. 4. Programming content (1. The process of key recognition by the single-chip microcomputer (2. The single-chip microcomputer counts the keys that are correctly recognized, and when the count is full, it starts counting from zero; (3. The single-chip microcomputer needs to display the counted value digitally. The counted number is a decimal number, containing tens and ones. We need to separate the tens and ones digits and send them to the corresponding digital tubes for display. How to separate the tens and ones digits? We can take the remainder of the counted value by 10, which is the ones digit, and divide it by 10 to get the tens digit. (4. Use a table lookup to display the ones and tens digits separately. 5. Flowchart 6. Assembly source program Count EQU 30H SP1 BIT P3.7 ORG 0 START: MOV Count,#00H NEXT: MOV A,Count MOV B,#10 DIV AB MOV DPTR,#TABLE MOVC A,@A+DPTR MOV P0,A MOV A,B MOVC A,@A+DPTR MOV P2,A WT: JNB SP1,WT WAIT: JB SP1,WAIT LCALL DELY1 0MS JB SP1,WAIT INC Count MOV A,Count CJNE A,#100,NEXT LJMP START DELY10MS: MOV R6,#20 D1: MOV R7,#248 DJNZ R7,$ DJNZ R6,D1 RET TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH END
|