Basic Aplication InOut With mCS51
Basic Aplication InOut With mCS51
CounterUp099
C1
30pF
Application1
C2
30pF
X1
U1
19 XTAL1 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD 39 38 37 36 35 34 33 32 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 P0.0 P0.1 P0 1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.0 P0.1 P0 1 P0.2 P0.3 P0.4 P0.5 P0.6
R2
CRYSTAL
18
XTAL2
C3
9 10uF RST
PULLUP P2.0 P2 0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P0.0 P0 0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P2.0 P2 0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6
R1
10k 29 30 31 PSEN ALE EA
1 2 3 4 5 6 7 8
S1:
MOV DPTR,#TABLE MOV R0,#00H MOV P0 #00H P0,#00H MOV P2,#00H INC R0 CJNE R0,#100,S2 MOV R0 #00H R0,#00H JB P3.7,$ LCALL DELAY JB P3.7,S2 MOV A,R0 MOV B,#10 DIV AB MOVC A,@A+DPTR MOV P0,A MOV A,B AB MOVC A,@A+DPTR MOV P2,A JB P3.7,S1 LJMP S3 MOV R5,#20 MOV R6,#250 DJNZ R6,$ DJNZ R5,D1 RET DB 3FH,06H,5BH,4FH,66H DB 6DH,7DH,07H,7FH,6FH
;Set the first address segment code table ;R0 keep count ;Digital Display initialization ;Plus 1 count ;Determine whether the maximum count ;Wait for button ;Remove button jitter
S2:
S3:
;Separate count of ten and a bit ;Were taken 10 and a bit of segment code and display
DELAY: D1:
TABLE: END
U1
19 XTAL1 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0 5/AD5 P0.6/AD6 P0.7/AD7 P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2 6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD 39 38 37 36 35 34 33 32 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7
18
XTAL2
Application2
RST
Keypadinput to7segment
P3.0
29 30 31
PSEN ALE EA
1 2 3 4 5 6 7 8
R9 0 4 8 C 1 5 9 D 2 6 A E 3 7 B F
47k
R10
P3.1 47k
R11
P3.2 47k
R12
P3.3 47k
LINE EQU ROW EQU VAL EQU ORG 00H START: LSCAN: L1:
30H 31H 32H MOV DPTR,#TABLE ;The first section of code table address MOV P2,#00H ;Digital display initialization MOV P3,#0F0H ;Out line set high, bound set high JNB P3.0,L2 P3 0 L2 ;Progressive Scan LCALL DELAY JNB P3.0,L2 MOV LINE,#00H ;Reload No. LJMP RSCAN JNB P3.1,L3 LCALL DELAY JNB P3.1,L3 MOV LINE,#01H ;Reload No. LJMP RSCAN JNB P3.2,L4 LCALL DELAY JNB P3.2,L4 MOV LINE,#02H ;Reload No. LJMP RSCAN JNB P3.3,L1 LCALL DELAY JNB P3.3,L1 MOV LINE,#03H ;Reload No. MOV P3,#0FH ;Line line line-level exchange column JNB P3.4,C2 ;By column scanning MOV ROW,#00H ;Keep the column number LJMP CALCU JNB P3.5,C3 MOV ROW,#01H ;Keep the column number LJMP CALCU JNB P3.6,C4 MOV ROW,#02H ;Keep the column number LJMP CALCU JNB P3.7,C1 MOV ROW,#03H ;Keep the column number MOV A,LINE ;According to calculation of the line number and column number keys MOV B,#04H MUL AB ADD A,ROW MOV VAL,A ;Key deposit MOVC A,@A+DPTR ;Code section to search, according to key MOV P2,A ;Output of the Segment Display LJMP LSCAN MOV R6,#20 MOV R7,#250 DJNZ R7,$ DJNZ R6,D1 RET DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H
L2:
L3:
L4:
DELAY: D1:
TABLE: END
C1
30pF
C2
30pF
X1
19 CRYSTAL
18
C3
9 10uF R1 10k 29 30 31 RST
PSEN ALE EA
1 2 3 4 5 6 7 8
C0 C1 C2 C3 C4 C5 C6 C7
R7 R6 R5 R4 R3 R2 R1 R0
DSP_0: L0:
DSP_1: L1:
DSP_2: L2: L2
DSP_3: L3:
END
EQU EQU ORG MOV MOV MOV MOV ADD JMP SJMP SJMP SJMP SJMP MOV MOV MOV LCALL RL INC MOV CJNE INC MOV LJMP MOV MOV MOV LCALL RR INC MOV CJNE INC MOV LJMP MOV MOV MOV LCALL RR INC MOV CJNE INC MOV LJMP MOV MOV A,#0FEH MOV P0,A LCALL RL A INC RS_CNT MOV R0,RS_CNT CJNE R0,#24,L3 MOV DSP_CNT,#00H MOV RS_CNT,#00H LJMP A0 MOV R5,#10 MOV MOV DJNZ DJNZ DJNZ RET
31H 34H 00H RS_CNT,#00H DSP_CNT,#00H DPTR,#SWITCH A,DSP_CNT A,DSP_CNT @A+DPTR DSP_0 DSP_1 DSP_2 DSP_3 P0,#00H A,#01H P3,A , DELAY A RS_CNT R0,RS_CNT R0,#24,L0 DSP_CNT RS_CNT,#00H A0 P0,#00H A,#80H P3,A P3 A DELAY A RS_CNT R0,RS_CNT R0,#24,L1 DSP_CNT RS_CNT,#00H A0 P3,#0FFH A,#7FH P0,A P0 A DELAY A RS_CNT R0,RS_CNT R0,#24,L2 DSP_CNT RS_CNT,#00H A0 P3,#0FFH DELAY
;Display Mode ;The initial value of display mode ;Setup the first address jump table ;Double-byte instruction, offset by 2 ;Display mode according to the value of jump ;Process jump table
;Display Mode 0, all home line line 0 ;Initial column scan code ; ;Output Display p p y ;Column scan code shift ;Model 0 shows complete? ;Show the next mode ;Display Mode 1, all home line line 0 ;Initial column scan code ;Output Display ;Column scan code shift ;Model 1 shows the complete? ;Show the next mode ;Display mode 2, column 1, line all set ;Initial line scan code ;Output Display O t t Di l ;Line scan code shift ;Model 2 shows the complete? ;Show the next mode ;Display mode 3, column 1, line all set ;Initial line scan code ;Output Display ;Line scan code shift ;Model 3 shows the complete? ;Show the next mode ;Delay subroutine
TUGAS(programanalyze)
U2
9 CLK 8 R SRG8 C1/-> 3 S0 S0 S1 S2 S3 S4 S5 S6 DIN 1 2
Switchinputto7segment
&
1D 4 5 6 10 11 12 13 S1 S2 S3 S4 S5
U1
19 XTAL1 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P2.0/A8 P2 0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3 1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD 39 38 37 36 35 34 33 32 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 DIN CLK
18 S6
XTAL2
9 74LS164
RST
29 30 31
PSEN ALE EA
1 2 3 4 5 6 7 8
R1
10k
DIN EQU P3.0 CLK EQU P3.1 DBUF EQU 30H TEMP EQU 40H ORG 00H MOV 30H,#16 MAIN: KEY:
ACALL DISP ACALL KEY AJMP MAIN MOV P1,#0FFH MOV A,P1 CJNE A,#0FFH,K00 AJMP KEY ACALL DELAY MOV A,P1 CJNE A #0FFH K01 A,#0FFH,K01 AJMP KEY MOV R3,#8 MOV R2,#0 MOV B,A MOV DPTR,#K0TAB MOV A,R2 MOVC A,@A+DPTR CJNE A,B,K04 MOV A,P1 CJNE A,#0FFH,K03 ACALL DELAY MOV A,R2 RET INC R2 DJNZ R3,K02 MOV A,#0FFH AJMP KEY , , , DB 0FEH,0FDH,0FBH,0F7H DB 0EFH,0DFH,0BFH,07FH MOV DBUF,A MOV R0,#DBUF MOV R1,#TEMP MOV DPTR,#SEGTAB MOV A,@R0 MOVC A,@A+DPTR MOV @R1,A MOV R0,#TEMP MOV R2,#8 MOV A,@R0 RLC A MOV DIN,C CLR CLK SETB CLK DJNZ R2,DP13 RET DB 3 3FH,06H,5BH,4FH,66H 06 66 DB 6DH,7DH,07H,7FH,6FH MOV R4,#02H MOV R5,#0F8H DJNZ R5,AA DJNZ R4,AA1 RET
;Digital display initialization ;Show ;Calculation of key C l l ti fk ;Calculating key completely different program ;Reading before writing a ;Determine whether there is button pressed
K00:
K01:
K02: K03:
K04:
K0TAB: DISP:
DP10:
;Taken under paragraph code key look-up table ;Temporary section of code ;Set shift frequency ;Section of code shift output ;Shift pulse output
DP12: DP13: