daily pastebin goal
49%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ; +----+----+----+
  3. ; | 11 | 10 | 9  |  P0.3
  4. ; +----+----+----+
  5. ; | 8  | 7  | 6  |  P0.2
  6. ; +----+----|----+
  7. ; | 5  | 4  | 3  |  P0.1
  8. ; +----+----+----+
  9. ; | 2  | 1  | 0  |  P0.0
  10. ; +----+----+----+
  11. ;  P0.6 P0.5 P0.4
  12.  
  13.  
  14.  
  15. ;           A
  16. ;       ---------
  17. ;       |       |
  18. ;      F|       |B
  19. ;       |   G   |
  20. ;       ---------
  21. ;       |       |
  22. ;      E|       |C
  23. ;       |_______|
  24. ;           D
  25. ;
  26. ;   GFEDCBA  
  27. ; #11000000B - 0
  28. ;   GFEDCBA
  29. ; #11111001B - 1
  30. ;   GFEDCBA
  31. ; #10100100B - 2
  32. ;   GFEDCBA
  33. ; #10110000B - 3
  34. ;   GFEDCBA
  35. ; #10011001B - 4
  36. ;   GFEDCBA
  37. ; #10010010B - 5
  38. ;   GFEDCBA
  39. ; #10000010B - 6
  40. ;   GFEDCBA
  41. ; #11111000B - 7
  42. ;   GFEDCBA
  43. ; #10000000B - 8
  44. ;   GFEDCBA
  45. ; #10010000B - 9
  46.  
  47. start:
  48.     MOV R0, #0
  49.  
  50.     ;first row
  51.     CLR P0.0       
  52.     CALL cols_scan;
  53.     SETB P0.0
  54.  
  55.     JB F0, display_num ;if found key in row 0,1,2 jump to display procedure
  56.  
  57.  
  58.  
  59.     ;second row
  60.     CLR P0.1
  61.     CALL cols_scan;
  62.     SETB P0.1
  63.  
  64.     JB F0, display_num ;if found key in row 3,4,5 jump to display procedure
  65.  
  66.  
  67.  
  68.     ;third row
  69.     CLR P0.2
  70.     CALL cols_scan;
  71.     SETB P0.2
  72.  
  73.     JB F0, display_num ;if found key in row 6,7,8 jump to display procedure
  74.  
  75.  
  76.  
  77.     ;fourth row
  78.     CLR P0.3
  79.     CALL cols_scan;
  80.     SETB P0.3;
  81.  
  82.     JB F0, display_num ;if found key in row 9,10,11 jump to display procedure
  83.  
  84.  
  85. keep_scanning:
  86.     jmp start
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. display_num:
  96.     CLR F0 
  97.     MOV A, R0   ; move R0 (pressed number on keypad) to A, so we can divide
  98.     MOV B, #10  ; move 10 to B register
  99.     DIV AB  ; divide A (pressed number on keypad) by 10 (value of B),
  100.             ; so if we have for example pressed 12 -> A:1 B:2 etc. reminder in B value of division in A
  101.  
  102.     MOV R0, A ; for later use
  103.  
  104.  
  105.     CLR P3.4 ; choose display 0
  106.     CLR P3.3 ; choose display 0
  107.     MOV P1, #0FFH; clear the display
  108.  
  109.     mov A, B
  110.     CALL num_in_A_to_display
  111.  
  112.  
  113.  
  114.  
  115.     CLR P3.4  ; choose display 1
  116.     SETB P3.3 ; choose display 1
  117.     MOV P1, #0FFH; clear the display
  118.  
  119.     MOV A, R0
  120.     CALL num_in_A_to_display
  121.  
  122.  
  123.     jmp keep_scanning
  124.  
  125.  
  126.  
  127.  
  128. num_in_A_to_display:
  129.     CLR F0
  130.     JZ num_0_to_display ;if zero in A, jump to procedure that puts 0 on display
  131.  
  132.     CLR C               ;clear carry flag, so it won't affect substracion
  133.     SUBB A, #1          ;substract 1 from A, so if initailly A stored 1 it will be 0 now
  134.     JZ num_1_to_display ;if A is zero now, jump to procedure that puts 1 on display
  135.  
  136.     CLR C      
  137.     SUBB A, #1          ;substract 1 from A, so if initially A stored 2, now is 1, because of previous substraction
  138.     JZ num_2_to_display ;if A is 0 now (after second subtraction) jump to procedure that puts 2 on display
  139.  
  140.     ;carry on as above up to 9
  141.     CLR C
  142.     SUBB A, #1
  143.     JZ num_3_to_display
  144.  
  145.     CLR C
  146.     SUBB A, #1
  147.     JZ num_4_to_display
  148.  
  149.     CLR C
  150.     SUBB A, #1
  151.     JZ num_5_to_display
  152.  
  153.     CLR C
  154.     SUBB A, #1
  155.     JZ num_6_to_display
  156.  
  157.     CLR C
  158.     SUBB A, #1
  159.     JZ num_7_to_display
  160.  
  161.     CLR C
  162.     SUBB A, #1
  163.     JZ num_8_to_display
  164.  
  165.     CLR C
  166.     SUBB A, #1
  167.     JZ num_9_to_display
  168.  
  169.     RET
  170.  
  171.  
  172. num_0_to_display:
  173.     MOV P1, #11000000B;
  174.     RET
  175.  
  176. num_1_to_display:
  177.     MOV P1, #11111001B;
  178.     RET
  179.  
  180. num_2_to_display:
  181.     MOV P1, #10100100B;
  182.     RET
  183.  
  184. num_3_to_display:
  185.     MOV P1, #10110000B;
  186.     RET
  187.  
  188. num_4_to_display:
  189.     MOV P1, #10011001B;
  190.     RET
  191.  
  192. num_5_to_display:
  193.     MOV P1, #10010010B;
  194.     RET
  195.  
  196. num_6_to_display:
  197.     MOV P1, #10000010B;
  198.     RET
  199.  
  200. num_7_to_display:
  201.     MOV P1, #11111000B;
  202.     RET
  203.  
  204. num_8_to_display:
  205.     MOV P1, #10000000B;
  206.     RET
  207.  
  208. num_9_to_display:
  209.     MOV P1, #10010000B;
  210.     RET
  211.  
  212. cols_scan:
  213.     JNB P0.4, gotKey
  214.     INC R0
  215.  
  216.     JNB P0.5, gotKey
  217.     INC R0
  218.  
  219.     JNB P0.6, gotKey
  220.     INC R0
  221.    
  222.     RET
  223.  
  224.  
  225. gotKey:
  226.     SETB F0 ; indicate found key by setting f0 flag
  227.     RET
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top