;************************************************** ; ; DBLINT.ASM ; ;************************************************** PROCESSOR 16F84 RADIX DEC INCLUDE "P16F84.INC" ERRORLEVEL -302 ;Setup of PIC configuration flags ;XT oscillator ;Disable watch dog timer ;Enable power up timer ;Disable code protect __CONFIG 3FF1H LED1 EQU 0 LED2 EQU 1 LED3 EQU 2 LED4 EQU 3 ORG 0CH Count RES 2 nTick RES 1 ;Reset Vector ;Starting point at CPU reset ORG 00H ;Jump to the main body of program to avoid the interrupt handler ;code. goto Start ;Interrupt vector ;Starting point at CPU interrupts ORG 04H ;********************************************************************** ; Interrupt handler ;********************************************************************** ;Check the interrupt event btfsc INTCON,T0IF goto IntT0IF btfsc INTCON,RBIF goto IntRBIF ;Reset the T0IF and RBIF flags to re-enable the interrupts End_ih bcf INTCON,T0IF bcf INTCON,RBIF ;Go back to the main program retfie ;********************************************************************** ; TMR0 Interrupt handler ;********************************************************************** IntT0IF ;Turn on LED3 if it's off btfsc PORTB,LED3 goto LED3_off bsf PORTB,LED3 goto End_ih LED3_off bcf PORTB,LED3 goto End_ih ;********************************************************************** ; RB4-RB7 interrupt handler ;********************************************************************** IntRBIF ;Turn on LED 2 bsf PORTB,LED2 ;Starts the LED1 blink counter movlw 3 movwf nTick goto End_ih ;********************************************************************** ; Main body ;********************************************************************** Start: ;Commuta sul secondo banco dei registri per accedere ai registri TRISA e TRISB bsf STATUS,RP0 ;Definizione delle linee di I/O (0=Uscita, 1=Ingresso) ;Definizione della porta A movlw 00011111B movwf TRISA & 7FH ;Definizione della porta B ;Le linee da RB0 a RB3 vengono programmate in uscita per essere collegate ai quattro led ;Le linee da RB4 a RB7 vengono programmate in ingresso per essere collegate ai quattro pulsanti movlw 11110000B movwf TRISB & 7FH ;Assegna il PRESCALER a TMR0 e lo configura a 1:256 movlw 00000111B movwf OPTION_REG & 7FH ;Commuta sul primo banco dei registri bcf STATUS,RP0 ;Spegne tutti i led collegati sulla porta B bcf PORTB,LED1 bcf PORTB,LED2 bcf PORTB,LED3 bcf PORTB,LED4 ;Abilita l'interrupt sul TMR0 e sul cambiamento di stato delle linee RB4,5,6,7 movlw 10101000B movwf INTCON ;********************************************************************** ; Loop principale ;********************************************************************** MainLoop call Delay ;Ritardo software btfss PORTB,LED1 ;Led acceso ? goto TurnOnLed1 ;No, lo accende goto TurnOffLed1 ;Si, lo spegne ;Accensione led e decremento del contatore di lampeggi TurnOnLed1 bsf PORTB,LED1 ;Controlla se LED 2 di segnalazione dell'interrupt e' gia acceso. ;Se e' acceso decrementa il contatore nTick ad ogni lampeggio di ;LED1. Quando nTick vale 0 spegne LED 2 btfss PORTB,LED2 ;LED2 acceso ? goto MainLoop ;No, continua a lampeggiare decf nTick,1 ;Si, decrementa nTick btfss STATUS,Z ;nTick = 0 ? goto MainLoop ;No, continua a lampeggiare bcf PORTB,LED2 ;Si, spegne LED2 goto MainLoop ;Continua a lampeggiare ;Spegnimento led TurnOffLed1 bcf PORTB,LED1 ;Spegne LED 1 goto MainLoop ;Continua a lampeggiare ;********************************************************************** ; Subroutine ;********************************************************************** ;Subroutine di ritardo software Delay clrf Count clrf Count+1 DelayLoop decfsz Count,1 goto DelayLoop decfsz Count+1,1 goto DelayLoop return END