;************************************************** ; Six Channel Ir Sistem ; scir.ASM ; ; (c) 2001, alfonsi alfredo alfalf73@libero.it ; http://digilander.iol.it/alfred73, www.alfredoalfonsi.too.it ************************************************** PROCESSOR 16F84 RADIX DEC INCLUDE "P16F84.INC" ;Suppress MPASM warning message 302: ;"Register in operand not in bank 0. Ensure that bank bits are correct" ERRORLEVEL -302 __CONFIG 3FF1H ;input ;Infrared receiver RX_IFR equ 2 ;Sensore ad infrarossi ; ************* o u t p u t ***************** ;LED data line bus LEDDB0 equ 1 ;LED data line DB0 LEDDB1 equ 2 ;LED data line DB1 LEDDB2 equ 3 ;LED data line DB2 LEDDB3 equ 4 ;LED data line DB3 LEDDB4 equ 5 LEDDB5 equ 6 LEDDB6 equ 7 PIEZO equ 3 ;piezo data line RA3 ;IFR timing IFR_K1 equ 46 ;1.5ms IFR_K2 equ 125 ;4ms IFR_K3 equ 93 ;3ms IFR_K4 equ 31 ;1ms ORG 0CH counta res 1 msDelayCounter res 2 COUNT res 1 IfrKeyCode res 1 ;Code of the last key pressed IfrCount res 1 IfrBuf res 4 ;Sign read buffer ;Reset Vector ORG 00H Start bsf STATUS,RP0 ;Swap to register bank 1 movlw 00010111B ;Set PORTA lines movwf TRISA movlw 11111111B ;Set PORTB lines movwf TRISB bcf PORTB,LEDDB0 bcf PORTB,LEDDB1 bcf PORTB,LEDDB2 bcf PORTB,LEDDB3 bcf PORTB,LEDDB4 bcf PORTB,LEDDB5 bcf PORTB,LEDDB6 movlw 00000100B movwf OPTION_REG bcf STATUS,RP0 ;Swap to register bank 0 ;Reset IFR code clrf PORTB clrf IfrKeyCode call ritardo MainLoop movlw 2 movwf counta ;Check IFR input line CheckIFR btfsc PORTA,RX_IFR goto MainLoop checked call RxIfr ;Decode IFR signal movwf IfrKeyCode ;Save the IFR code ;Read the received code and send a message to the LED CheckPPKey movlw 1 xorwf IfrKeyCode,W btfss STATUS,Z goto _CheckPPKey movf PORTB,W xorlw 2 movwf PORTB btfsc PORTB,LEDDB0 call ritardo call ritardo call ritardo goto MainLoop _CheckPPKey CheckMKey movlw 2 xorwf IfrKeyCode,W btfss STATUS,Z goto _CheckMKey movf PORTB,W xorlw 4 movwf PORTB btfsc PORTB,LEDDB1 call ritardo call ritardo call ritardo goto MainLoop _CheckMKey CheckVPKey movlw 3 xorwf IfrKeyCode,W btfss STATUS,Z goto _CheckVPKey movf PORTB,W xorlw 8 movwf PORTB btfsc PORTB,LEDDB2 call ritardo call ritardo call ritardo goto MainLoop _CheckVPKey CheckPMKey movlw 4 xorwf IfrKeyCode,W btfss STATUS,Z goto _CheckPMKey movf PORTB,W xorlw 16 movwf PORTB btfsc PORTB,LEDDB3 call ritardo call ritardo call ritardo goto MainLoop _CheckPMKey CheckPWKey movlw 5 xorwf IfrKeyCode,W btfss STATUS,Z goto _CheckPWKey movf PORTB,W xorlw 32 movwf PORTB btfsc PORTB,LEDDB4 call ritardo call ritardo call ritardo goto MainLoop _CheckPWKey CheckVMKey movlw 6 xorwf IfrKeyCode,W btfss STATUS,Z goto _CheckVMKey movf PORTB,W xorlw 64 movwf PORTB btfsc PORTB,LEDDB5 call ritardo call ritardo call ritardo goto MainLoop _CheckVMKey btfsc PORTB,LEDDB1; funzione di provatelecomandi IR se il tasto PM è premuto call ritardo goto MainLoop ;************************************************************************** ; Decodifica degli impulsi provenienti dal trasmettitore IFR Visa Simplex ; ; Output ; ; W = 0 Nessun tasto premuto o tasto non valido ; 1 P+, 2 Mute, 3 Vol +, 4 P-, 5 Power, 6 Vol - ; ;************************************************************************** RxIfr btfsc PORTA,RX_IFR ;Segnale da IFR ? retlw 0 ;No, fine _RxIfr clrf IfrCount ;Azzera il contatore di segni letti movlw IfrBuf ;Set del puntatore al buffer di memorizzazione movwf FSR ;dei segni ricevuti nop nop nop ifri clrf 0 ;Azzera il byte che deve contenere il prossimo segno ifra clrf TMR0 ;Azzera il misuratore di durata ifrc clrwdt btfsc PORTA,RX_IFR ;Segnale ancora presente ? goto ifrb ;No, continua movlw IFR_K1 ;Si, Segnale attivo per piu' di 1.5ms ? subwf TMR0,W btfsc STATUS,C retlw 0 ;Si, annulla goto ifrc ;No, continua a campionare ifrb incf 0,1 ;Incremento il numero di segno ricevuto clrf TMR0 ;Azzera il misuratore di durata ifrf clrwdt btfss PORTA,RX_IFR ;Segnale ritornato attivo ? goto ifrg ;Si, continua movlw IFR_K2 ;No. Segnale non attivo per piu' di 4ms ? subwf TMR0,W btfsc STATUS,C goto ifrz ;Si, fine... goto ifrf ;No, continua a campionare ifrg movlw IFR_K3 ;Segnale rimasto non attivo per piu' di 3ms ? subwf TMR0,W btfsc STATUS,C goto ifre ;Si, passa al segno successivo ... ifrd movlw IFR_K4 ;No, Segnale rimasto non attivo per almeno 1ms ? subwf TMR0,W btfsc STATUS,C goto ifra ;Si, rimane sullo stesso segno retlw 0 ;No, annulla ifre incf FSR,1 ;Incrementa il puntatore al buffer dei segni incf IfrCount,1 ;Incrementa il contatore di byte ricevuti movlw 4 ;Ricevuti 4 segni ? xorwf IfrCount,W btfss STATUS,Z goto ifri ;No, continua a ricevere goto ifrzz ;Si, fine ifrz clrwdt incf FSR,1 ;Incrementa il puntatore al buffer dei segni incf IfrCount,1 ;Incrementa il contatore di byte ricevuti movlw 4 ;Ricevuti 4 segni ? xorwf IfrCount,W btfsc STATUS,Z goto ifrzz ;Si, fine clrf 0 ;No, azzera il buffer dei segni fino al 4 goto ifrz ifrzz ;In base ai segni ricevuti estrae lo scan code del tasto premuto kCode clrwdt swapf IfrBuf+0,W ;Compatta i quattro segni in due byte iorwf IfrBuf+1,W movwf IfrBuf+0 swapf IfrBuf+2,W iorwf IfrBuf+3,W movwf IfrBuf+1 movlw 16h xorwf IfrBuf+0,W btfss STATUS,Z goto k2 movlw 00h xorwf IfrBuf+1,W btfss STATUS,Z retlw 0 retlw 1 k2 movlw 13h xorwf IfrBuf+0,W btfss STATUS,Z goto k3 movlw 30h xorwf IfrBuf+1,W btfss STATUS,Z retlw 0 retlw 2 k3 movlw 11h xorwf IfrBuf+0,W btfss STATUS,Z goto k4 movlw 50h xorwf IfrBuf+1,W btfss STATUS,Z retlw 0 retlw 3 k4 movlw 25h xorwf IfrBuf+0,W btfss STATUS,Z goto k5 movlw 00h xorwf IfrBuf+1,W btfss STATUS,Z retlw 0 retlw 4 k5 movlw 21h xorwf IfrBuf+0,W btfss STATUS,Z goto k6 movlw 13h xorwf IfrBuf+1,W btfss STATUS,Z retlw 0 retlw 5 k6 movlw 34h xorwf IfrBuf+0,W btfss STATUS,Z retlw 0 movlw 00h xorwf IfrBuf+1,W btfss STATUS,Z retlw 0 retlw 6 ;********************************************************************** ; Delay subroutine ; ; ;********************************************************************** ritardo movlw 15 movwf COUNT movlw 6 movwf TMR0 bsf PORTA,PIEZO ciclo movf TMR0,W btfss STATUS,Z goto ciclo movlw 6 movwf TMR0 decfsz COUNT,1 goto ciclo bcf PORTA,PIEZO return END