Vous êtes sur la page 1sur 3

list p=16f877A ; list directive to define processor

#include <p16f877A.inc> ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC &
_WRT_OFF & _LVP_OFF & _CPD_OFF

;***** VARIABLE DEFINITIONS


w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving

;**********************************************************************
ORG 0x000 ; processor reset vector

nop ; nop required for icd


goto main ; go to beginning of program

ORG 0x004 ; interrupt vector location

movwf w_temp ; save off current W register contents


movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register

goto Interrupcion

Salir_Int:
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt

main
clrf PORTD
bsf STATUS,RP0
bcf STATUS,RP1 ; Banco 1
clrf TRISD ; PORTD Salida
movlw 0xFF
movwf TRISB ; PORTB Entrada
;Configurar el OPTION_REG
movlw b'10000111'
movwf OPTION_REG
bcf STATUS,RP0
bcf STATUS,RP1 ; Banco 0
;Activar Interrupcion
bsf INTCON,GIE ; GIE=1
bsf INTCON,T0IE ; TMR0=1
;Cargar TMR0
movlw .60
movwf TMR0

PP:
bcf PORTD,0
call Delay_100ms
bsf PORTD,0
call Delay_100ms
goto PP

Interrupcion:
btfsc INTCON,T0IF
goto Int_TMR0
goto Salir_Int

Int_TMR0:
movlw .60
movwf TMR0
btfss PORTD,1
goto Hacer1_D1
goto Hacer0_D1
Hacer1_D1:
bsf PORTD,1
goto Salir_Int_TMR0
Hacer0_D1:
bcf PORTD,1
goto Salir_Int_TMR0
Salir_Int_TMR0:
bcf INTCON,T0IF
goto Salir_Int

#include "ModDelay_20M.asm"

END ; directive 'end of program'


; Programa de retaso de tiempo

CONTA1 EQU 0x20


CONTA2 EQU 0x21

Delay_100ms:
call Delay_50ms
call Delay_50ms
return

Delay_50ms:
call Delay_10ms
call Delay_10ms
call Delay_10ms
call Delay_10ms
call Delay_10ms
return

Delay_10ms:
movlw d'67'
movwf CONTA1
bucle1:
movlw d'250'
movwf CONTA2
bucle2:
decfsz CONTA2,F
goto bucle2
decfsz CONTA1,F
goto bucle1
return

Vous aimerez peut-être aussi