SHARE
TWEET

Untitled

cabeca_de_pica Nov 12th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <REG51F380.H>
  2.  
  3. ;-------------------------------------------------------------------------------------------------------------------;
  4. ;CONSTANT DEFINES FOR CHAR_NUM AND CHAR_STATE
  5. ;-------------------------------------------------------------------------------------------------------------------;
  6. CHAR_0          EQU 0C0H                ;DEFINE CHARS FOR 8BITSEG
  7. CHAR_1          EQU 0F9H
  8. CHAR_2          EQU 0A4H
  9. CHAR_3          EQU 0B0H
  10. CHAR_4          EQU 099H
  11. CHAR_5          EQU 092H
  12. CHAR_6          EQU 082H
  13. CHAR_7          EQU 0F8H
  14. CHAR_8          EQU 080H
  15. CHAR_9          EQU 090H
  16. CHAR_A          EQU 088H
  17. CHAR_B          EQU 083H
  18. CHAR_C          EQU 0C6H
  19. CHAR_D          EQU 0A1H
  20. CHAR_E          EQU 086H
  21. CHAR_F          EQU 08EH
  22. ;-------------------------------------------------------------
  23. AND_OP EQU 88H
  24. OR_OP EQU 0C0H
  25. NOT_OP EQU 0ABH
  26. XOR_OP EQU 89H
  27. ADD_OP EQU 8CH
  28. SUB_OP EQU 0EAH
  29. ROTL_OP EQU 0C7H
  30. ROTR_OP EQU 0CEH
  31.  
  32. S_READY EQU 0
  33. S_SELECT EQU 1
  34. S_PROCESS EQU 2
  35.  
  36. OP_1 DATA 30H
  37. OP_2 DATA 31H
  38. OPER DATA 32H
  39. STATE DATA 33H
  40. N_STATE DATA 34H
  41. MASQ EQU 0FH
  42.    
  43. FLAG_OP1 BIT 1
  44.    
  45. FLAG_OP2 BIT 0
  46.  
  47. KSET EQU P0.6
  48. KLOAD EQU P0.7
  49.    
  50. CSEG AT 400H
  51.     OP_TABLE:       ;OPERADORES
  52.         DB AND_OP, OR_OP, NOT_OP, XOR_OP, ADD_OP, SUB_OP, ROTL_OP, ROTR_OP
  53. CSEG AT 500H        ;caracteres segmento 8bits
  54.     DIGITS_TABLE:
  55.         DB CHAR_0, CHAR_1, CHAR_2, CHAR_3, CHAR_4, CHAR_5, CHAR_6, CHAR_7, CHAR_8, CHAR_9, CHAR_A, CHAR_B, CHAR_C, CHAR_D, CHAR_E, CHAR_F   ;0-F
  56.                
  57. CSEG AT 0H
  58.     JMP RESET
  59. ;-------------------------------------------------------------------------------------------------
  60. ;       INIT_DEVICE
  61. ;-------------------------------------------------------------------------------------------------
  62. PCA_Init:
  63.     MOV  PCA0MD,    #000h
  64.     RET
  65. Port_IO_Init:
  66.     MOV  XBR1,      #040h
  67.     RET
  68. Init_Device:
  69.     lcall PCA_Init
  70.     lcall Port_IO_Init
  71.     ret
  72. ;-------------------------------------------------------------------------------------------------
  73. ;       RESET
  74. ;-------------------------------------------------------------------------------------------------
  75. RESET:
  76.     ACALL Init_Device
  77.     SETB KSET               ;ATIVAR BOTOES
  78.     SETB KLOAD
  79.     SETB FLAG_OP1
  80.     CLR FLAG_OP2
  81.     MOV R3, #0H
  82.     MOV A, #0H
  83.     MOV OP_1, #0H
  84.     MOV OP_2, #0H
  85.     MOV OPER, #0H
  86.     MOV STATE, #S_READY
  87.     MOV N_STATE, #S_READY
  88.     JMP STATE_MACHINE
  89. ;-------------------------------------------------------------------------------------------------
  90. ;       STATE MACHINE
  91. ;-------------------------------------------------------------------------------------------------
  92. DOISOPERADORES:
  93.     MOV N_STATE, #S_READY
  94.     JMP STATE_MACHINE
  95. SINGLE:
  96.     MOV N_STATE, #S_PROCESS
  97. STATE_MACHINE:
  98.     MOV STATE, N_STATE
  99.     MOV A, STATE
  100.     RL A
  101.     MOV DPTR, #JMP_TABLE
  102.     JMP @A+DPTR
  103. JMP_TABLE:
  104.     AJMP READY
  105.     AJMP SELECT
  106.     AJMP PROCESS
  107. ;-------------------------------------------------------------------------------------------------
  108. ;       STATE READY - selecao do op1 e op2
  109. ;-------------------------------------------------------------------------------------------------
  110. READY:
  111.     MOV DPTR, #DIGITS_TABLE
  112.     JB FLAG_OP1, READY_OP1
  113.     JB FLAG_OP2, READY_OP2
  114. READY_OP1:
  115.     MOV P2, #0AFH
  116.     ACALL START
  117.     JMP DISPLAYBCD
  118. READY_OP2:
  119.     MOV P2, #0A4H
  120.     ACALL START
  121.    
  122. DISPLAYBCD:
  123.     MOV A, R3
  124.     MOVC A, @A+DPTR
  125.     MOV P2, A
  126. BUTTONS:
  127.     JNB KLOAD, OPERANDO
  128.     JB KSET, BUTTONS
  129. INCREMENT:
  130.     JNB KSET, $
  131.     INC R3
  132.     CJNE R3, #16, DISPLAYBCD
  133.     MOV R3, #0H
  134.     JMP DISPLAYBCD
  135.  
  136. START:              ;aguarda que o utilizador carregue no kset para iniciar programa
  137.     JB KSET, START
  138.     JNB KSET, $
  139.     RET
  140.    
  141. OPERANDO:
  142.     JNB KLOAD, $
  143.     JB FLAG_OP1, OPER1
  144.     JB FLAG_OP2, OPER2
  145. OPER1:
  146.     MOV OP_1, R3
  147.     MOV P1, OP_1
  148.     CLR FLAG_OP1
  149.     SETB FLAG_OP2
  150.     MOV N_STATE, #S_SELECT
  151.     JMP STATE_MACHINE
  152. OPER2:
  153.     MOV OP_2, R3
  154.     MOV P1, OP_2
  155.     MOV N_STATE, #S_PROCESS
  156.     JMP STATE_MACHINE
  157. ;-------------------------------------------------------------------------------------------------
  158. ;       STATE SELECT
  159. ;-------------------------------------------------------------------------------------------------
  160. SELECT:
  161.     MOV DPTR, #OP_TABLE
  162.     MOV R3, #0H
  163. SELECT_2:
  164.     MOV A, R3
  165.     MOVC A, @A+DPTR
  166.     MOV P2, A
  167. BUTT_OPER:
  168.     JNB KLOAD, OPERADOR
  169.     JB KSET, BUTT_OPER
  170. INC_OPER:
  171.     JNB KSET, $
  172.     INC R3
  173.     CJNE R3, #8, SELECT_2
  174.     JMP SELECT
  175. OPERADOR:
  176.     JNB KLOAD, $
  177.     MOV OPER, R3
  178. ;--------------------------------------------------
  179. /*  CJNE OPER, #2, AUX
  180.     MOV N_STATE, #S_PROCESS
  181.     JMP STATE_MACHINE
  182. AUX:
  183.     CJNE OPER, #6, AUX_2
  184.     MOV N_STATE, #S_PROCESS
  185.     JMP STATE_MACHINE
  186. AUX_2:
  187.     CJNE OPER, #6, AUX_3
  188.     MOV N_STATE, #S_PROCESS
  189.     JMP STATE_MACHINE
  190. AUX_3:
  191.     MOV N_STATE, #S_READY
  192.     JMP STATE_MACHINE*/
  193. ;--------------------------------------------------
  194.     MOV A, OPER
  195.     RL A
  196.     MOV DPTR, #OPERJMP_TABLE
  197.     JMP @A+DPTR
  198. OPERJMP_TABLE:
  199.     AJMP DOISOPERADORES
  200.     AJMP DOISOPERADORES
  201.     AJMP SINGLE
  202.     AJMP DOISOPERADORES
  203.     AJMP DOISOPERADORES
  204.     AJMP DOISOPERADORES
  205.     AJMP SINGLE
  206.     AJMP SINGLE
  207. ;-------------------------------------------------------------------------------------------------
  208. ;       STATE PROCESS
  209. ;-------------------------------------------------------------------------------------------------
  210. PROCESS:
  211.     CLR AC
  212.     MOV A, OPER
  213.     RL A
  214.     MOV DPTR, #FUNC_JMP_TABLE
  215.     JMP @A+DPTR
  216. FUNC_JMP_TABLE:
  217.     AJMP AND_FUNC
  218.     AJMP OR_FUNC
  219.     AJMP NOT_FUNC
  220.     AJMP XOR_FUNC
  221.     AJMP ADD_FUNC
  222.     AJMP SUB_FUNC
  223.     AJMP RL_FUNC
  224.     AJMP RR_FUNC
  225.  
  226. AND_FUNC:
  227.     MOV A, OP_1
  228.     ANL A, OP_2             ;A AND OP_2
  229.     JMP IMPRIMIR
  230. OR_FUNC:
  231.     MOV A, OP_1
  232.     ORL A, OP_2
  233.     JMP IMPRIMIR
  234. NOT_FUNC:
  235.     MOV A, #0FH             ;TB PODEMOS USAR O COMANDO CPL A
  236.     SUBB A, OP_1
  237.     INC A
  238.     JMP IMPRIMIR
  239. XOR_FUNC:
  240.     MOV A, OP_1
  241.     XRL A, OP_2
  242.     JMP IMPRIMIR
  243. ADD_FUNC:
  244.     MOV A, OP_1
  245.     ADD A, OP_2
  246.     JB AC, OVERFLOW
  247.     JMP IMPRIMIR
  248. SUB_FUNC:
  249.     MOV A, OP_1
  250.     SUBB A, OP_2
  251.     INC A
  252.     JB AC, OVERFLOW
  253.     JMP IMPRIMIR
  254. RL_FUNC:
  255.     MOV A, OP_1
  256.     RL A
  257.     JB AC, OVERFLOW
  258.     JMP IMPRIMIR
  259. RR_FUNC:
  260.     MOV A, OP_1
  261.     RR A
  262.     JB AC, OVERFLOW
  263.     JMP IMPRIMIR
  264.  
  265. OVERFLOW:
  266.     ANL A, MASQ
  267. IMPRIMIR:
  268.     MOV DPTR,#DIGITS_TABLE
  269.     MOVC A, @A+DPTR
  270.     MOV P2, A
  271.     JB AC, PONTO
  272.     JMP ENGODO
  273. PONTO:
  274.     CLR P2.7
  275.     CLR AC
  276. ENGODO:
  277.  
  278. JNB KSET, ENGODO
  279. END
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