; Ten-Pulse Communications System ; device PIC16F84,rc_osc,wdt_off,pwrt_on UNIT = 3 XTIME = 1 ;seconds for timeout report org 12 flag ds 1 rblast ds 1 xtimer ds 1 data ds 1 temp ds 1 count ds 1 del0 ds 1 del1 ds 1 delx ds 1 secs ds 1 csum ds 1 psu ds 3 debug ds 1 POUT = ra.1 SPEED = ra.0 ; flag bit definitions HIT = flag.0 org 0 goto start org 4 reti start clrf rb movlw 00001b movwf ra bsf RP0 movlw 00000b movwf TRISA movlw 11111111b movwf TRISB movlw 0 movwf OPTION bcf RP0 movlw 123 movwf psu cycle call state ;current input state call slow btfsc rb,7 ;test mode bit goto :ok movf rb,w andlw 0f0h movwf rblast movlw 40 goto :dla :ok movlw XTIME movwf xtimer :wait movlw 30 call delay ;1 second at slow clock btfsc HIT goto :go decfsz xtimer goto :wait :dla call pseudo andlw 15 addlw 10 call delay :go call fast goto cycle slow bsf SPEED ;set bit high bsf RP0 bsf SPEED ;float the resistor bcf RP0 ret fast bsf SPEED bsf RP0 bcf SPEED ;enable fast pull-up bcf RP0 ret state movf rblast,w andlw 0f0h iorlw UNIT movwf temp swapf temp btfsc HIT ;immediate report? bsf temp,7 ;yes. movf temp,w call tpulse ret check movf csum,w xorlw 0ffh ;ones compliment call tpulse ret tpulse addwf csum ;accumulate checksum movwf data movlw 8 movwf count movlw 15 call :pulse ;minumum gap size movlw 5 call :pulse ;reference pulse :tpx movlw 3 btfsc data,0 movlw 7 call :pulse rrf data decfsz count goto :tpx ret :pulse movwf temp :px movlw 90 movwf del0 :pw decfsz del0 goto :pw decfsz temp goto :px bsf POUT movlw 80 movwf del0 :pwd nop nop decfsz del0 goto :pwd bcf POUT ret pseudo movf psu,w addwf psu+1,w movwf psu+1 addwf psu+2,w movwf psu+2 bcf c rrf psu+2 btfsc c bsf psu+2,7 movf psu+2,w addwf psu ret ; exponential delay of 'w' while testing rb<4:7> for changes delay bcf HIT movwf del1 :dx movf del1,w movwf del0 :dy movf rb,w ;get data lines andlw 0f0h ;high nibble only xorwf rblast,w ;check for changes btfss z ;match? goto :hit ;changed. decfsz del0 goto :dy decfsz del1 goto :dx ret :hit xorwf rblast,w ;restore original movwf rblast bsf HIT ;bit has changed ret end QED˙