Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;       Hacemos parpadear un led cuando se pulsa un botón,
  2. ;       y permanece apagado cuando el botón no está siendo
  3. ;       pulsado.
  4.  
  5. ;       PORTA,0----Pulsador
  6. ;       PORTB,0----LED
  7. ;----------ZONA DE CONFIGURACIÓN--------------------------
  8.     #include    <p16f84a.inc>
  9.     LIST        p=16f84a
  10.     __CONFIG _RC_OSC & _WDT_ON & _PWRTE_OFF & _CP_OFF
  11.  
  12. ;---------ZONA DE CÓDIGO---------------------------------
  13.     org     0
  14. tiempo  EQU 0xC    
  15.  
  16. puertos
  17.     bsf     STATUS,RP0      ; Banco 1
  18.     clrf    TRISB           ;Configuramos portB completo como salida
  19.     movwf   0x01            ;Movemos 00000001 al registro W
  20.     movwf   TRISA           ;Configuramos el bit 1 del puerto A como entrada
  21.     bcf     STATUS,RP0      ;Banco 0
  22.     clrf    PORTB           ;Apagamos todas las salidas del puerto B
  23.     call    reset_tiempo    ;Asigna 255 a tiempo
  24.    
  25. loop
  26.     btfsc   PORTA,0         ;Si el botón está pulsado, ejecuta blink,
  27.     goto    blink           ;si no está pulsado, vuelve a comprobar
  28.     goto    loop            ;
  29.    
  30. blink                       ;
  31.     bsf     PORTB,0         ;Encendemos el led
  32.     call    delay           ;retardo
  33.     bcf     PORTB,0         ;Apagamos el led
  34.     call    delay           ;retardo
  35.     goto    loop            ;Volvemos a la comprobación del botón
  36.    
  37. delay
  38.     decfsz  tiempo          ;Decrementa tiempo y regresa cuando tiempo=0
  39.     goto    delay           ;
  40.     call    reset_tiempo    ;Tiempo=255
  41.     return                  ;
  42.    
  43. reset_tiempo
  44.     movlw   d'255'          ;Cargamos 255 decimal al registro W
  45.     movwf   tiempo          ;movemos W a tiempo, tiempo=d'255'
  46.     return
  47.    
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement