Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; +----+----+----+
- ; | 11 | 10 | 9 | P0.3
- ; +----+----+----+
- ; | 8 | 7 | 6 | P0.2
- ; +----+----|----+
- ; | 5 | 4 | 3 | P0.1
- ; +----+----+----+
- ; | 2 | 1 | 0 | P0.0
- ; +----+----+----+
- ; P0.6 P0.5 P0.4
- ; A
- ; ---------
- ; | |
- ; F| |B
- ; | G |
- ; ---------
- ; | |
- ; E| |C
- ; |_______|
- ; D
- ;
- ; GFEDCBA
- ; #11000000B - 0
- ; GFEDCBA
- ; #11111001B - 1
- ; GFEDCBA
- ; #10100100B - 2
- ; GFEDCBA
- ; #10110000B - 3
- ; GFEDCBA
- ; #10011001B - 4
- ; GFEDCBA
- ; #10010010B - 5
- ; GFEDCBA
- ; #10000010B - 6
- ; GFEDCBA
- ; #11111000B - 7
- ; GFEDCBA
- ; #10000000B - 8
- ; GFEDCBA
- ; #10010000B - 9
- start:
- MOV R0, #0
- ;first row
- CLR P0.0
- CALL cols_scan;
- SETB P0.0
- JB F0, display_num ;if found key in row 0,1,2 jump to display procedure
- ;second row
- CLR P0.1
- CALL cols_scan;
- SETB P0.1
- JB F0, display_num ;if found key in row 3,4,5 jump to display procedure
- ;third row
- CLR P0.2
- CALL cols_scan;
- SETB P0.2
- JB F0, display_num ;if found key in row 6,7,8 jump to display procedure
- ;fourth row
- CLR P0.3
- CALL cols_scan;
- SETB P0.3;
- JB F0, display_num ;if found key in row 9,10,11 jump to display procedure
- keep_scanning:
- jmp start
- display_num:
- CLR F0
- MOV A, R0 ; move R0 (pressed number on keypad) to A, so we can divide
- MOV B, #10 ; move 10 to B register
- DIV AB ; divide A (pressed number on keypad) by 10 (value of B),
- ; so if we have for example pressed 12 -> A:1 B:2 etc. reminder in B value of division in A
- MOV R0, A ; for later use
- CLR P3.4 ; choose display 0
- CLR P3.3 ; choose display 0
- MOV P1, #0FFH; clear the display
- mov A, B
- CALL num_in_A_to_display
- CLR P3.4 ; choose display 1
- SETB P3.3 ; choose display 1
- MOV P1, #0FFH; clear the display
- MOV A, R0
- CALL num_in_A_to_display
- jmp keep_scanning
- num_in_A_to_display:
- CLR F0
- JZ num_0_to_display ;if zero in A, jump to procedure that puts 0 on display
- CLR C ;clear carry flag, so it won't affect substracion
- SUBB A, #1 ;substract 1 from A, so if initailly A stored 1 it will be 0 now
- JZ num_1_to_display ;if A is zero now, jump to procedure that puts 1 on display
- CLR C
- SUBB A, #1 ;substract 1 from A, so if initially A stored 2, now is 1, because of previous substraction
- JZ num_2_to_display ;if A is 0 now (after second subtraction) jump to procedure that puts 2 on display
- ;carry on as above up to 9
- CLR C
- SUBB A, #1
- JZ num_3_to_display
- CLR C
- SUBB A, #1
- JZ num_4_to_display
- CLR C
- SUBB A, #1
- JZ num_5_to_display
- CLR C
- SUBB A, #1
- JZ num_6_to_display
- CLR C
- SUBB A, #1
- JZ num_7_to_display
- CLR C
- SUBB A, #1
- JZ num_8_to_display
- CLR C
- SUBB A, #1
- JZ num_9_to_display
- RET
- num_0_to_display:
- MOV P1, #11000000B;
- RET
- num_1_to_display:
- MOV P1, #11111001B;
- RET
- num_2_to_display:
- MOV P1, #10100100B;
- RET
- num_3_to_display:
- MOV P1, #10110000B;
- RET
- num_4_to_display:
- MOV P1, #10011001B;
- RET
- num_5_to_display:
- MOV P1, #10010010B;
- RET
- num_6_to_display:
- MOV P1, #10000010B;
- RET
- num_7_to_display:
- MOV P1, #11111000B;
- RET
- num_8_to_display:
- MOV P1, #10000000B;
- RET
- num_9_to_display:
- MOV P1, #10010000B;
- RET
- cols_scan:
- JNB P0.4, gotKey
- INC R0
- JNB P0.5, gotKey
- INC R0
- JNB P0.6, gotKey
- INC R0
- RET
- gotKey:
- SETB F0 ; indicate found key by setting f0 flag
- RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement