Advertisement
Guest User

Untitled

a guest
May 9th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 2.88 KB | None | 0 0
  1. #include "p16f877a.inc"
  2.  
  3. ; CONFIG
  4. ; __config 0xFF7E
  5.  __CONFIG _FOSC_XT & _WDTE_ON & _PWRTE_OFF & _BOREN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _CP_OFF
  6.  
  7.    
  8.    
  9.    
  10.    
  11.     ;NOTA EL OSCILADOR DEBE ESTAR EN XT POR QUE SE USARAN 4 MHZ 3- a 10 mhz
  12.     ; nota, empa agregale la mascara al numero c ya que este es el de la eleccion 00000111B
  13.     ; FALTA AGREGAR LAS ULTIMAS DOS OPCIONES, no recuerdo si era cuenta especial y rotabit
  14.     ;custom equs0, procurar que esten en el banco 1
  15.  numeroA EQU 0x20 ;
  16.  numeroB EQU 0x21 ;
  17.  numeroC EQU 0X22  ;eleccion
  18.  contador EQU 0x23
  19.  ParteAltaMul EQU 0x24
  20.  Cociente     EQU 0X25
  21.  ;variables para contador por software
  22.  Temporizador1 EQU 0X26
  23.  Temporizador2 Equ 0x27
  24.  Temporizador3 EQU 0X28
  25.  
  26.         org 0
  27.     goto main
  28.  
  29. ;Por ahi escuche que con 4 mhz el ciclo de ejecucion es de un micro segundo
  30.  
  31. retardo250Micros:
  32.         MOVLW 0XFA
  33.         MOVWF Temporizador1
  34. LOOPTR0:    DECFSZ  Temporizador1
  35.         GOTO LOOPTR0
  36.         RETURN
  37.        
  38. Retardo1Seg:
  39.        MOVLW 0XFA
  40.        MOVWF Temporizador2
  41.        MOVLW 0X10
  42.        MOVWF Temporizador3
  43. LOOPTR3:       
  44. LOOPTR1: DECFSZ Temporizador2
  45.          CALL retardo250Micros
  46.      DECFSZ Temporizador3
  47.      goto LOOPTR3
  48.     RETURN
  49.    
  50.    
  51. ConfigurarMicro:
  52.         MOVLW 0X20
  53.     IORWF STATUS
  54.     MOVLW 0XFF
  55.     MOVWF TRISA ;puerto a como input
  56.     MOVWF TRISB ;puerto b como input
  57.     MOVLW 0x00
  58.     MOVWF TRISC ;puerto  c como output
  59.     ; no hay nada mas que confifurar c:
  60.     clrf STATUS
  61.     RETURN
  62.    
  63. get8bit:
  64.    
  65. hold:   BTFSS PORTA,0
  66.         GOTO hold
  67. RELASE: BTFSC PORTA,0
  68.     GOTO RELASE
  69.     MOVF PORTB,W
  70.     RETURN
  71.    
  72.    
  73. get3Nums:
  74.     MOVLW 0X03
  75.     MOVWF contador
  76.     MOVLW numeroA ; puntero a la primera direccion de arreglo de numeros
  77.     MOVWF   FSR
  78. LOOP:   CALL get8bit
  79.     MOVWF INDF
  80.     INCF FSR
  81.     DECFSZ contador
  82.     GOTO LOOP
  83.     RETURN
  84.    
  85. main:
  86.        
  87.         CALL get3Nums
  88.    
  89.     DECFSZ numeroC
  90.     goto next
  91.     ;opcion 1 suma
  92.         MOVF numeroA,W
  93.     ADDWF numeroB,W
  94.     MOVWF PORTC
  95.     goto ends
  96. next:   DECFSZ numeroC
  97.     goto next1
  98.         ;opcion2 resta
  99.     MOVF numeroB,W
  100.     SUBWF numeroA,W
  101.     MOVWF PORTC
  102.     goto ends
  103. next1:  DECFSZ numeroC
  104.          goto next2
  105.      ;opcion3 multiplicacion
  106.      MOVLW 0X00
  107. LOOPMUL: DECFSZ numeroB
  108.          goto breakloopmul  
  109.      ADDWF numeroA,W
  110.      ;si hay carry sumarlo :P
  111.      btfsc STATUS,C
  112.      goto endCarryif
  113.      INCF ParteAltaMul
  114.      BCF STATUS,C ; limpiamos carry
  115. endCarryif:
  116.      goto LOOPMUL
  117. breakloopmul:
  118.          MOVWF PORTC
  119.    
  120.     goto ends
  121. next2:  DECFSZ numeroC
  122.     goto next3
  123.     ;opcion 4 division
  124.     CLRC
  125.     MOVF numeroB,W
  126. DivisionLoop: SUBWF numeroA,1 ; que se vaya a f el resultado ojo 1 quiere decir f
  127.           INCF Cociente
  128.           BTFSC STATUS,C
  129.           GOTO endDivisionLoop
  130.           GOTO DivisionLoop
  131. endDivisionLoop:
  132.        
  133.     goto ends
  134. next3:  DECFSZ numeroC
  135.     goto next4
  136.     ;OPCION 5 rotar el numero
  137.    
  138.     goto ends
  139. next4:  DECFSZ numeroC
  140.     goto ends
  141.     ;opcion 6 Secuencia especial
  142. ends:
  143.        
  144.        
  145.    
  146.        
  147.     END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement