Problema:
Al microcontrolador PIC16F84A conectar un led al pin RB7. El programa deberá encender y apagar ese led cada 200ms aproximadamente (+/- 5%), usando un clock a cristal de 4MHz.
Dibujar el esquemático en el KICAD
Programar en lenguaje assembler al microcontrolador con el MPLAB, resolviendo el problema
;····································································································
;Actividad 3.asm
;El programa hace parpadear a una Led conectado a RB7
;····································································································
LIST p=PIC16F84A
INCLUDE <p16f84a.inc>
__CONFIG _WDT_OFF & _PWRTE_ON & _CP_OFF & _XT_OSC; CONFIG es donde configuramos el tipo de oscilación que vamos a usar
ERRORLEVEL -302
;····································································································
;Equivalencias:
#DEFINE BANK0 bcf STATUS,RP0 ; Cambio al banco 0
#DEFINE BANK1 bsf STATUS,RP0 ; Cambio al banco 1
SW EQU 0
LED EQU 7
;····································································································
; Variables
CBLOCK 0x00
d1
d2
ENDC
;····································································································
; Vectores
ORG 0x000
goto Inicio ; Vector de Reset
ORG 0x004
goto Isr ; Vector de Interrupción
;····································································································
; Rutina de servicio de interrupción
Isr
retfie
;····································································································
Inicio ; Configuramos el bit 7 (Port B) como salida (RB7)
bsf STATUS,RP0
bcf TRISB,LED
bcf STATUS,RP0
Principal
bcf PORTB, LED
call Delay_200ms
bsf PORTB, LED
call Delay_200ms
goto Principal
;····································································································
; Sub-Rutinas
; Delay = 0.2 seconds
; Clock frequency = 4 MHz
; Actual delay = 0.2 seconds = 200000 cycles
; Error = 0 %
Delay_200ms
;199993 cycles
movlw 0x3E
movwf d1
movlw 0x9D
movwf d2
Delay_200ms_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_200ms_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
END

0 comentarios:
Publicar un comentario