홈페이지> 블로그> PIC16F628 infrared receiver

PIC16F628 infrared receiver

March 16, 2024
EL-C1600N100013-B
0805 red light emitting diode
>

PIC16F628 infrared receiver
;SomenotesonRC5
;
;14RC5bits:
;SSTAAAAACCCCCC
;
;S:2startbits, T:1togglebit, A:5addressbits,C:6commandbits
;
;Usuallybothstartbitsarehigh.ExtendedRC5usesthe2ndstartbitforexpanding
;the6commandbitsto7bits.Afterreceivingacomplete14bitword,thisbit
;isinvertedandaddedasbit6totheregister'RC5_CMD'.Thetogglebitis
;copiedtobit7of'RC5_CMD'.The5LSBsofregister'RC5_ADR'containthe
;5addressbits;the3MSBsaresetto0.
;Resultafteravalidcodehasbeenreceived:;RC5_ADR:000AAAAARC5_CMD:TCCCCCCC
;NotethatmostIRreceiverChips(egSFH5110-xx)haveanactivelowoutput,however,the
;PIC'sinternalcomparatorinvertsthesignal.AninvertingdrivertransistorfortheRS232
;interfacefinallyinvertsandlevelshiftsthesignalagainsothatthestandardLIRC
;configuration(ieactivelow)mustbeused.
;
;
;PIC16F628connections
;
;PINFUNCTION
;
;RB7ICSP
;RB6ICSP
;RA5ICSP
;
; RB5 test output, active high
;RB4PWRin--PC switch input active low
;RB3RESETout--output transistor redial, active high
;RB2PWRout--output transistor forMBATXpwron/off, active high
;RB1LEDgrn--output LED green tube, active high
;RB0LEDred--output LED red tube, active high
;
;RA74.000MCcrystal
;RA64.000MCcrystal
;
;RA4(unused)
;RA3comparatorC1output--transistorbasedriveforRS232TX
;RA2(internallyconnectedtoVref=1.25volts)
;RA1ATXin--comparatorC2invertinginputforsensing-5voltsofATXpowersupply
;RA0IRin--comparatorC1invertinginputforIRreceiverchip
;
;---Configuration--------------------------------------------- -----------------------------------
;
;PIC16F628, Poweruptimer, nowatchdog, HS-oscillator, *no*brownoutdetect, LVPoff, CPoff,
;MCLREoff, f=4MHz

Listp=16f628

__CONFIG_pwrte_on&_wdt_off&_hs_osc&_boden_off&_lvp_off&_cp_off&_mclre_off

Include

;---Variables[allUPPERCASE]------------------------------------------ -------------------------

cbLOCkh'20'

DATA_1;16-bitshiftregisterforincomingRC5bits
DATA_2;
DATA_TMP1;temporaryregisterforRC5codes
DATA_TMP2;temporaryregisterforRC5codes
BITCOUNT;counterfortheRC5bits
COUNT;universaltemporarycountregister
TMP;universaltemporaryregisters
TMP1;
TMP2;
RC5_ADR;receivedRC5addressaftercleanup: '000AAAAA'
RC5_CMD;receivedRC5commandaftercleanup: '0CCCCCCC'
RC5_CMD_TMP;temporaryregisterforRC5command
RC5_CMD_TMP_1;temporaryregisterforRC5command
KEYCOUNT;countstheincomingRC5pwr-keyPACketstosetupadelay
KEYCOUNT_1;countstheincomingRC50-keypacketstosetupadelay
RC5_TX_1;16-bitshiftregisterforoutgoingRC5bits
RC5_TX_2;
EEADR_TMP; holdstheEEPROMaddresswhencallingtheEEPROMwritesubroutine
EEDATA_TMP; holdstheEEPROMdatawhencallingtheEEPROMwritesubroutine

PWR_ON_DELAY;00...99 (recalledfromEEPROMlocationh'00')
PWR_KEY_ADR;signedRC5pwrkeyaddress'000AAAAA'(recalledfromEEPROMlocationh'01')
PWR_KEY_CMD;signedRC5pwrkeycommand'0CCCCCCC'(recalledfromEEPROMlocationh'02')

D1;temporaryregistersfordelayroutines
D2;
D3;

FLAGS;flags, seedefinitions

Endc

;---EEPROMdefaultdata--------------------------------------------- -----------------------------

Orgh'2100'
;adrcontent
Ded'45';h'00'PWR_ON_DELAY
Deb'00000101';h'01'PWR_KEY_ADR
Deb'00001100';h'02'PWR_KEY_CMD

;---Definitions[allMixedCase]------------------------------------------ -----------------------

#defineATX_C_outcmcon,7;comparator2output
#defineIRinporta,0;inputforIRreceiverchip(activelow)
#defineIRinTristrISA,0;trisregisterbitforIRin
#defineIR_C_outcmcon,6;comparator1output

#defineLEDredportb,0;outputforbicolorLEDredanode
#defineLEDgrnportb,1;outputforbicolorLEDgreenanode
#definePWRoutportb,2;outputtodrivetransistorforMBATXpwron/off
#defineRESEToutportb,3;outputtodrivetransistorforMBreset
#definePWRinportb,4;inputforPCpwrswitch
#defineTestOutportb,5;debugoutputforscope

#defineTurnOnDelayd'9';turnondelaywhenpressingremotepwrkeyto
;wakeupfromstandby(9makesapprox.onesecond)

#defineRebootDelayd'15';additionalrebootdelay(inseconds)

#defineRC5_FlagFLAGS,0;0:RC_5codevalid,1:RC_5codeinvalid
#defineReboot_FlagFLAGS,1;0:normalbootdelay,1:additionaldelayneeded


;---Macros[allMixedCase]------------------------------------------ ----------------------------

Bank_0macro
Bcfstatus, 5
Bcfstatus, 6
Endm

Bank_1macro
Bsfstatus, 5
Bcfstatus, 6
Endm

Testmacro
bsfTestOut
bcfTestOut
Endm

LED_redmacro
bsfLEDred
bcfLEDgrn
Endm

LED_grnmacro
bsfLEDgrn
bcfLEDred
Endm

LED_offmacro
bcfLEDred
bcfLEDgrn
Endm

;---Reset--------------------------------------------- -------------------------------------------

Orgh'00'
Gotoinit;reset->init

;---Interrupt--------------------------------------------- ---------------------------------------

Orgh'04'
Gotoinit;nointerrupt

;************************************************* *************************************************
;Initialization
;************************************************* *************************************************

Init

;configurationofportaandportb------------------------------------------------ ----------------

Bank_0
Clrfporta;clearportaregister
Clrfportb;clearportbregister

Bank_1
MOVlwb'00000111';RA0...RA2input,RA3...RA7output
MOVwftrisa
MOVlwb'00010000'; RB0...RB3output, RB4input, RB5...RB7output
MOVwftrisb
Bcfoption_reg,7;enableportbweakpullups
Bank_0

;configurationofanalogcomparators------------------------------------------------ -------------

MOVlwb'00000110';twocommonreferencecomparatorswithoutputs
MOVwfcmcon
Bank_1
MOVlwb '11100110'; Vref=1.25volts, connectedtoRA2
MOVwfvrcon
Bank_0

;timer0------------------------------------------------ ------------------------------------------

Bank_1
MOVlwb '01000000';timer0internalclock,prescaler1:2,enableportbweakpullups
MOVwfoption_reg;
Bank_0

;timer1------------------------------------------------ ------------------------------------------

MOVlwb'00110001';prescaler=8,internalclock,enabled
MOVwft1con

;************************************************* *************************************************
;Mainprogram
;************************************************* *************************************************

Start
clrfFLAGS;clearallflags
Callcopy_ee;copydefaulteepromvaluestoRAMregisters

Main_loop
btfscATX_C_out; checkifATXisstandby
Gotogreen;on-->LEDgreen
LED_red;standby-->LEDred
Gotopwr_sw
Green
LED_grn

Pwr_sw
btfssPWRin;testPWRin(activelow)
Gotopwr_sw_1;iflowgotopwr_sw_1

btfssIR_C_out;waitforhighlevelatIR_C_out
Gotomain_loop;
Callrc5_rx;callrc5_rxsubroutine
btfscRC5_Flag;RC5codeOK?
Gotomain_loop;no,gotomain_loop

LED_off;turnoffgreenLEDfor50mseachtimeavalidcode
Calldelay_t4; hasbeenreceived
LED_grn

Pwr_key;checkifpwrkeyofremotecontrolispressed
MOVfwRC5_ADR;loadRC5_ADRintow
subwfPWR_KEY_ADR,w;
Btfssstatus,z;dosPWR_KEY_ADRmatch?
Gotono_match;-no,gotono_match
;
MOVfwRC5_CMD;-yes,loadRC5_CMDintow
Andlwb'01111111';andcleartogglebit
subwfPWR_KEY_CMD,w;
Btfssstatus,z;dosPWR_KEY_CMDmatch?
Gotono_match;-no,gotono_match
;
MOVfwRC5_CMD_TMP;-yes,togglebitalsounchanged?
subwfRC5_CMD,w;
Btfssstatus,z;
Gotono_match;-no,gotono_match
;
btfscATX_C_out;activatePWRoutonlyifATXisstandbytopowerupPC
Gotovdr_pwr_down;ifon,VDR'sshutdownscriptwillturnoffPC

;ATXisstandby,nowcheckifpwrkeyofremotecontrolis
;pressedlongenough(approx.TurnOnDelay*114ms)

incfKEYCOUNT,f;-yes,unchanged,incrementKEYCOUNT
MOVfwKEYCOUNT;
sublwTurnOnDelay; ifreachedTurnOnDelay,activatePWRout
Btfssstatus,z
Gotocont
bsfPWRout;activatePWRoutfor250ms
Calldelay_t6
bcfPWRout
Gotoboot_delay;andgotoboot_delay

No_match
clrfKEYCOUNT;clearKEYCOUNT

Cont
MOVfwRC5_CMD; copyRC5_CMDtotemporaryregister
MOVwfRC5_CMD_TMP;forexttogglebitcomparison

Zero_key;checkif0keyonremotecontrolispressed
;atleast44*114ms(RC5coderepetitionrate)=approx.5s
MOVfwRC5_CMD; loadRC5_CMDintow
Andlwb'01111111';andcleartogglebit
Btfssstatus,z;doesOkey(command'0000000',anyaddress)match?
Gotono_match_1;

MOVfwRC5_CMD_TMP_1;togglebitalsounchanged?
subwfRC5_CMD,w;
Btfssstatus,z;
Gotono_match_1;-no,haschanged
incfKEYCOUNT_1,f;-yes,unchanged,incrementKEYCOUNT_1
MOVfwKEYCOUNT_1;
Sublwd'44';
Btfssstatus,z;reached44(approx.5s)?
Gotocont_1;-no,loop
Gotopgm_or_reboot;-yes,gotopgm_or_reboot

No_match_1
clrfKEYCOUNT_1;clearKEYCOUNT_1

Cont_1
MOVfwRC5_CMD; copyRC5_CMDtotemporaryregister
MOVwfRC5_CMD_TMP_1;fornexttogglebitcomparison

Gotomain_loop

Pgm_or_reboot
btfssATX_C_out
Gotopgm_mode;PCisinstandby-->enableprogrammode

LED_red;turnLEDredtoinDICatethatreboothasbeeninitialized

MOVlwh'1f';setaddresstoh'1f'
MOVwfRC5_TX_2;
MOVlwh'3f';setcommandtoh'3f'
MOVwfRC5_TX_1;Thiscombinationisnotusedbytheremotecontrol.Suitable
;entriesinlircd.confandlircrccallarebootscriptviairexec

Callrc5_tx
bsfReboot_Flag;setReboot_flagsothatadditionaldelayforgreenLEDflashing
Gotoboot_delay;willbeaddedandgotoboot_delay

;------------------------------------------------- -----------------------------------------------

Pwr_sw_1;checksifpwrswitchofPCispressedforlessormorethan
;5seconds: ifless-->poweron/off, ifmore-->reset

Calldelay_t4;50msdelay
btfscPWRin; stilllowafter50ms?
Gotomain_loop;ifnot,assumespikeandgotomain_loop

btfssATX_C_out; ATXonorstandby?
Gototurn_on;standby, aresetwouldbequiteuseless,soturnonVDR

Clrftmr1h;cleartimer1registers
Clrftmr1l;
MOVlwd'19';setCOUNTtod'19',thismakesapprox.19*262ms=5seconds
MOVwfCOUNT;

Chk_low
btfscPWRin;stilllow?
Gotovdr_pwr_down;ifnot,pwrkeywaspressed<5s-->turnoffVDR

Btfsctmr1h,7;checktimer1hregisterbit7(setafter262ms)
Gotodec_cnt1
Gotochk_low

Dec_cnt1
Clrftmr1h;cleartimer1registers
Clrftmr1l
decfszCOUNT,f
Gotochk_low;notyet5s,loop
Gotosetet;powerkeypressed>5s

Turn_on
bsfPWRout;activatePWRoutfor250ms
Calldelay_t6;
bcfPWRout;
Gotoboot_delay;andgotoboot_delay

ResetbsfRESETout;activateRESEToutfor250ms
Calldelay_t6
BcfRESETout

Boot_delay;variabledelayfrom0to127swhileLEDisflashinggreen
MOVfwPWR_ON_DELAY;andnocommandisaccepted,delayderivedfromuserpreset(0..99)
btfscReboot_Flag;addadditionaltime(definedinRebootDelay)ifReboot_Flagisset
addlwRebootDelay;
MOVwfCOUNT
Bcfstatus,c
RlfCOUNT;multiplyCOUNTbytwoastheg_flashroutinetakesonly0.5s
Sublwd'0';ifCOUNT=0stopimmediately
Btfssstatus,z
Gotog_flash
bcfReboot_Flag;clearReboot_Flag
Gotomain_loop

G_flash
LED_grn
Calldelay_t6
LED_off
Calldelay_t6

decfszCOUNT,f
Gotog_flash

Gotomain_loop

Vdr_pwr_down
LED_red;turnLEDred

MOVlwh'1f';setRC5addresstoh'1f'andcommandtoh'3e'andsendthecode
MOVwfRC5_TX_2;Thiscombinationisnotusedbytheremotecontrolandwill
MOVlwh'3e';besendtoLIRCinsteadoftheremote'snormalpwrkeycode.
MOVwfRC5_TX_1;Thiswayexactly*one*commandCANbesentinsteadofmultiple
;(autorepeatofRC5codes)--VDRwouldstartandimmediately
;aborttheshutdownifthepwrkeyispressedabittoolong...
;Acorrespondingentrymustbeaddedtolircd.confandthe
;originalpwrkeycodemustbereMOVed.
Callrc5_tx;
;FlashredLEDwhilecheckingifakeyontheremotecontrolis
;pressed(whichstopsVDRfromexecutingtheshutdownscript).
;Ifso,theprogrammreturnstothemainloopandtheLED
;turnsgreenagain.OtherwiseflashLEDuntilATXisinstandby
;andfinallyturnLEDred.Note:Theremote'spwrkeywillbe
;ignored(alsotoavoidproblemwithRC5/repeatandVDR).

MOVlwd'57';setCOUNTtod'57'fortimeoutcouter
MOVwfCOUNT;timeoutisapprox.2*262ms*57=30seconds

R_flash
LED_red;turnonredLED
Calltim_sub;calltimersubroutineandcheckifanyremotekeyispressed
LED_off;turnoffLED
Calltim_sub;calltimersubroutineandcheckifanyremotekeyispressed
decfszCOUNT,f
Gotor_flash;andloop
Gotomain_loop;timeoutafterapprox.30seconds(ifshutdownfails)

Tim_sub;
Clrftmr1h;cleartimer1registers
Clrftmr1l;

Ir_chk
btfssIR_C_out;highlevelatIR?
Gototim_chk;-no,checktimer1
Callrc5_rx;-yes,callrc5_rxsubroutine
btfscRC5_Flag;RC5codeOK?
Gototim_chk;-no,checktimer1

MOVfwRC5_CMD; copyRC5_CMDtowand
Andlwb'01111111';cleartogglebit
Bcfstatus,c;clearcarrybit
subwfPWR_KEY_CMD,w;checkifcommandispwrkey;thiswillbeignored
Btfssstatus,z;
Gotomain_loop;keypressed,abortshutdownandgotomain_loop

Tim_chk;
Btfsstmr1h,7;checktimer1hregisterbit7(setafter262ms)
Gotoir_chk;loopifnotyetset

Atx_chk
btfscATX_C_out;waituntilATXisstandby
Return;stillon,continueflashing

Gotomain_loop;nowstandby,gotomain_loop

;************************************************* *************************************************
;Programmode
;************************************************* *************************************************

Pgm_mode
MOVlwd'4'
MOVwfCOUNT

Rg_flash
LED_red; flashbicolorLEDaLTErnatelygreen/red
Calldelay_t6; (eitherfor250ms) 4timestoindicate
LED_grn;thattheprogrammodehasbeenentered
Calldelay_t6
decfszCOUNT
Gotorg_flash
LED_off; nowreadytolearncodes(LEDoff)

Learn_1
Callir_chk1;waitforhighlevelatIR_C_out,timeoutifidlefor>5s
Callrc5_rx;callrc5_rxsubroutinee
btfscRC5_Flag;RC5codeOK?
Gotolearn_1;no,tryagain

MOVfwRC5_CMD; copyRC5_CMDtowand
Andlwb'01111111';cleartogglebit
MOVwfTMP1; copytoTMP1andTMP2
MOVwfTMP2;
Bsfstatus,c;checkifcommandis0...9
Sublwd'9'
Btfssstatus,c
Gotolearn_1;no,tryagain

LED_grn;turnongreenLEDfor250msifa
Calldelay_t6;validcodehasbeenreceived
LED_off

MOVfwRC5_CMD; copyRC5_CMDtotemporaryregister
MOVwfRC5_CMD_TMP;forthenexttogglebitcomparison

Bcfstatus,c;multiplyTMP1by10
rlfTMP1,f;for10'sofPWR_ON_DELAY
rlfTMP1,f
rlfTMP1,f
MOVfwTMP2
addwfTMP1,f
addwfTMP1,f

Learn_2
Callir_chk1;waitforhighlevelatIR_C_out,timeoutifidlefor>5s
Callrc5_rx;callrc5_rxsubroutine
btfscRC5_Flag;RC5codeOK?
Gotolearn_2;no,tryagain

MOVfwRC5_CMD; checkiftogglebithaschanged
subwfRC5_CMD_TMP,w;
Btfscstatus,z;
Gotolearn_2;no,tryagain

MOVfwRC5_CMD; copyRC5_CMDtowand
Andlwb'01111111';cleartogglebit
MOVwfTMP2; copytoTMP2
Bsfstatus,c;checkifcommandis0...9
Sublwd'9';
Btfssstatus,c;
Gotolearn_2;no,tryagain

MOVfwTMP1; add10'sand1's
addwfTMP2,w;

MOVwfEEDATA_TMP;copytoEEDATA_TMP

MOVlwh'00';setEEADR_TMPtoh'00'
MOVwfEEADR_TMP;
Callwrite_ee;andwritetoEEPROM

LED_grn;turnongreenLEDfor250msifa
Calldelay_t6;validcodehasbeenreceived
LED_off

MOVfwRC5_CMD; copyRC5_CMDtotemporaryregister
MOVwfRC5_CMD_TMP;forthenexttogglebitcomparison

Learn_3
Callir_chk1;waitforhighlevelatIR_C_out,timeoutifidlefor>5s
Callrc5_rx;callrc5_rxsubroutine
btfscRC5_Flag;RC5codeOK?
Gotolearn_3;no,tryagain

MOVfwRC5_CMD; checkiftogglebithaschanged
subwfRC5_CMD_TMP,w;
Btfscstatus,z;
Gotolearn_3;no,tryagain

MOVfwRC5_CMD; copyRC5_CMDtowand
Andlwb'01111111';cleartogglebit
Bcfstatus,c;checkifcommandis0...9
Sublwd'9';whichcannotbeassigned
Btfscstatus,c;aspwr_key
Gotolearn_3;yes,tryagain

MOVfwRC5_ADR
MOVwfEEDATA_TMP;copytoEEDATA_TMP
MOVlwh'01';setEEADR_TMPtoh'01'
MOVwfEEADR_TMP;
Callwrite_ee;andwritetoEEPROM

MOVfwRC5_CMD; copyRC5_CMDtowand
Andlwb'01111111';cleartogglebit
MOVwfEEDATA_TMP;copytoEEDATA_TMP
MOVlwh'02';setEEADR_TMPtoh'02'
MOVwfEEADR_TMP;
Callwrite_ee;andwritetoEEPROM

Callcopy_ee;copynewvaluestoRAM

LED_grn;turnongreenLEDfor250mstoindicate
Calldelay_t6;thatavalidcodehasbeenreceived
LED_off

clrfKEYCOUNT_1;clearKEYCOUNT_1toresetzerokeydetectiondelay
Gotomain_loop

Ir_chk1;waitforhighlevelatIR_C_out,timeoutifidlefor>5s
Clrftmr1h;cleartimer1registers
Clrftmr1l
MOVlwd'19';setCOUNTtod'19',thismakes19x262ms=approx.5seconds
MOVwfCOUNT

Ir_chk2
btfscIR_C_out;waitforhighlevelatIR_C_out
Return;andreturn

Btfsctmr1h,7;checktimer1hregisterbit7(setafter262ms)
Gotodec_cnt
Gotoir_chk2

Dec_cnt
Clrftmr1h;cleartimer1registers
Clrftmr1l
decfszCOUNT,f
Gotoir_chk2;notyet5s,loop
clrfKEYCOUNT_1;clearKEYCOUNT_1toresetzerokeydetectiondelay
Gotomain_loop;timeoutafterapprox.5s


;************************************************* *************************************************
;RC5transmitsubroutine
;************************************************* *************************************************

Rc5_tx;wehave:RC5address'000AAAAA'andcommand'0CCCCCCC'
bsfRC5_TX_2,7;set1ststartbit
btfssRC5_TX_1,6;checkcommandbit#6and
bsfRC5_TX_2,6;set2ndstartbitifnecessary
Bcfstatus,c;clearcarrybit
rlfRC5_TX_1;leftshiftRC5_TX_1twicetobringcommandMSBto
Bcfstatus,c;left-mostposition
rlfRC5_TX_1;nowthe16-bitshiftregisterisreadyfor
;shiftingout:RC5_TX_21S0AAAAARC5_TX_1CCCCCC00

bsfIRin;setportregisterbitIRinhighbeforesettingtooutput
Bank_1;toavoida1祍spike
bcfIRinTris;setIRinasoutput
Bank_0;

Calldelay_t6;250msdelayfortimedecoupling(LIRCmightstillbebusywith
;processingIRcodesfromthereceiverandwouldnotreacttothe
;thecodegeneratedbelow)

MOVlwd'14';setBITCOUNTto14
MOVwfBITCOUNT;

Bit_test
btfssRC5_TX_2,7;testallbits
Gotoout_low_high;rememberthatwehavetoinvertthem

Out_high_low
bsfIRin;outputahigh-lowsequenceatIRin
Calldelay_t5;eitherstateis889祍
bcfIRin;
Calldelay_t5;
Gotonext_bit;gotonext_bit

Out_low_high
bcfIRin;outputalow-highsequenceatIRin
Calldelay_t5;eitherstateis889祍
bsfIRin;
Calldelay_t5;

Next_bit
rlfRC5_TX_1;leftshiftthe16-bitregister
rlfRC5_TX_2;
decfszBITCOUNT;untilall14bitsareout
Gotobit_test;

btfssIRin; ifthelastbitwasahigh-lowsequence,immediatelysetIRin
bsfIRin;hightoterminatetheRC5codeafterthecorrecttime

Calldelay_t6;250msdelayfortimedecoupling(IRcodesfromthereceiverchip
;occuringonlyafterthecodegeneratedabovewoulddestroy
;theintegrityofthiscode)
Bank_1
bsfIRinTris;setIRintoinputagain
Bank_0

Return


;************************************************* *************************************************
;RC5receiveroutine
;************************************************* *************************************************
;
;in:14bitdatafromIRinresp.DTRin
;
;out:RC5_ADR(8bit,000AAAAA)
;RC5_CMD (8bit, TCCCCCCC)
;RC5_Flag(1bit)0: RC5codevalid, 1: RC5codeinvalid
;
; Self-synchronizingcodewhichtoleratesinaccurateRC5timings.
;Toleranceisachievedbypolling+/-approx.250祍aroundeachexpectedlevelchange.Tomarkthe
;receivedcodeasvalid,thelevelbeforeandaftertheedgesmustbeopposite,notimer0overflow
;(512祍)occurred,andtwosamplestakenat1200祍and1500祍aftereachedgemustbeequal.

Rc5_rx
ClrfDATA_1;clearinputshiftregister
ClrfDATA_2;
MOVlwd'13';setBITCOUNTto13
MOVwfBITCOUNT;
Test;1祍mark
Calldelay_t1a;1520祍delayuntilapprox.256祍beforenextexpectedslope
Calldelay_t1b

Pre_slope
Test;1祍mark

Clrftmr0;cleartimer0register
bcfiNTCon,t0if;cleartimer0interruptflag

btfssIR_C_out;IR_C_outhigh?
Gotopoll_lo_hi;

Poll_hi_lo
Btfscintcon,t0if;checkfortimer0overflow(after512祍)
Gotoset_flag;andset'invalid'flag

btfscIR_C_out
Gotopoll_hi_lo
Gotonext_bit1

Poll_lo_hi
bsfDATA_1,0;setlsbinDATA_1

Btfscintcon,t0if;checkfortimer0overflow(after512祍)
Gotoset_flag;andset'invalid'flag

btfssIR_C_out
Gotopoll_lo_hi

Next_bit1
decfszBITCOUNT,1;if0:all14bitsreceived(1stwasusedfor
Gotoshift;triggerandhasnotbeenrecorded);donot
Gotocleanup;shiftanyfurtherandgoonwithcleanup

Shift
Bcfstatus,c;clearcarrybit
RlfDATA_1,1;leftshiftthe16-bitregisterDATA_2/DATA_1
RlfDATA_2,1;

Calldelay_t1a;aquiresample#1
clrfDATA_TMP1;cleartemporaryregister
btfssIR_C_out;IR_C_outlow?
bsfDATA_TMP1,0;thensetlsbinDATA_TMP1

Calldelay_t1b;aquiresample#2
clrfDATA_TMP2;cleartemporaryregister
btfssIR_C_out;IR_C_outlow?
bsfDATA_TMP2,0;thensetlsbinDATA_TMP2

Check;checkifsamplesareequal
MOVfwDATA_TMP1; copyDATA_1tow,
Andlwb'00000001';konlyonlylsbinw,
xorwfDATA_TMP2,0;xorLSBsofDATA_TMP2andw,
Btfssstatus,z;ifnotequaldiscarddataand
Gotoset_flag;gotoset_flag--novalidcodehasbeenreceived

Gotopre_slope;andloop

Cleanup;collectedsofar:DATA_2000STAAADATA_1AACCCCCC
MOVfwDATA_1;copyDATA_1tow
Andlwb'00111111';clearbits6and7
MOVwfRC5_CMD; copywtoRC5_CMD

btfscDATA_2,3;togglebitis0?
bsfRC5_CMD,7;ifnot,setbit7ofRC5_CMD
btfssDATA_2,4;2ndstartbitis1?
bsfRC5_CMD,6;ifnot,setbit6ofRC5_CMD(extendedRC5)

RlfDATA_2;leftshifttwotimes
RlfDATA_2;
MOVfwDATA_2;copyDATA_2tow
Andlwb'00011100';clear3MSBand2LSB
MOVwfRC5_ADR; andcopytoRC5_ADR
BtfscDATA_1,6;addressbit0is0?
bsfRC5_ADR,0;ifnot,setbit0ofRC5_ADR
BtfscDATA_1,7;addressbit1is0?
bsfRC5_ADR,1;ifnot,setbit1ofRC5_ADR
;nowwehave:RC5_ADR000AAAAARC5_CMDTCCCCCCC
bcfRC5_Flag;clearRC5_Flag--validcodehasbeenreceived

Return

Set_flag
bsfRC5_Flag;setRC5_Flag--novalidcodehasbeenreceived
Return


;************************************************* *************************************************
;EEPROMread/writesubroutines
;************************************************* *************************************************

Write_ee
Bank_0
MOVfwEEADR_TMP;copyEEADR_TMPtoeeadr
Bank_1
MOVwfeeadr
Bank_0
MOVfwEEDATA_TMP;copyEEDATA_TMPtoeedata
Bank_1
MOVwfeedata
Bsfeecon1,wren;enablewrite
MOVlwh'55'; eepromwriteunlocksequence
MOVwfeecon2;
MOVlwh'aa';
MOVwfeecon2;
Bsfeecon1, wr;write

W_ready
Btfsceecon1, wr; writecompleted?
Gotow_ready;
Bank_0

Return

;------------------------------------------------- -------------------------------------------------

Copy_ee;readsaddressandcommandforassignedremotepowerkey
;andturnondelayvaluefromEEPROMandcopiesthemto
;theRAMregistersPWR_KEY_ADR, PWR_KEY_CMD, andPWR_ON_DELAY
Bank_1
MOVlwh'00'
MOVwfeeadr
Bsfeecon1, rd
MOVfweedata
Bank_0
MOVwfPWR_ON_DELAY

Bank_1
MOVlwh'01'
MOVwfeeadr
Bsfeecon1, rd
MOVfweedata
Bank_0
MOVwfPWR_KEY_ADR

Bank_1
MOVlwh'02'
MOVwfeeadr
Bsfeecon1, rd
MOVfweedata
Bank_0
MOVwfPWR_KEY_CMD

Return

;************************************************* *************************************************
;Delayroutines(1cycleequals1祍@4MCoscillatorFrequency)
;************************************************* *************************************************

Delay_t1a;total:1200cycles
MOVlw0xEE; 1193cycles
MOVwfd1
MOVlw0x01
MOVwfd2
Delay_t1a_0
Decfszd1,f
Goto$+2
Decfszd2,f
Gotodelay_t1a_0

Goto$+1;3cycles
Nop
Return;4cycles(includingcall)

;------------------------------------------------- ---------

Delay_t1b;total:320cycles
MOVlw0x69; 316cycles
MOVwfd1
Delay_t1b_0
Decfszd1,f
Gotodelay_t1b_0

Return;4cycles(includingcall)

;------------------------------------------------- ---------

Delay_t2;total:500cycles
MOVlwh'A5';496cycles
MOVwfD1
Delay_5
decfszD1,f
Gotodelay_5
Return;4cycles(includingcall)

;------------------------------------------------- ---------

Delay_t3;total:1255cycles
MOVlwh'F9';1248cycles
MOVwfD1
MOVlwh'01'
MOVwfD2
Delay_6
decfszD1,f
Goto$+2
decfszD2,f
Gotodelay_6
Goto$+1;3cycles
Nop
Return;4cycles(includingcall)

;------------------------------------------------- ---------

Delay_t4;total:50000cycles
;49993cycles
MOVlwh'0E'
MOVwfD1
MOVlwh'28'
MOVwfD2
Delay_7
decfszD1,f
Goto$+2
decfszD2,f
Gotodelay_7
Goto$+1;3cycles
Nop
Return;4cycles(includingcall)

;------------------------------------------------- ---------

Delay_t5;total:886cycles
MOVlwh'AF';878cycles
MOVwfD1
MOVlwh'01'
MOVwfD2
Delay_8
decfszD1,f
Goto$+2
decfszD2,f
Gotodelay_8
Goto$+1;4cycles
Goto$+1
Return;4cycles(includingcall)

;------------------------------------------------- ---------

Delay_t6;total:250000cycles
MOVlwh'4E';249993cycles
MOVwfD1
MOVlwh'C4'
MOVwfD2
Delay_9
decfszD1,f
Goto$+2
decfszD2,f
Gotodelay_9
Goto$+1;3cycles
Nop
Return;4cycles(includingcall)

;------------------------------------------------- ---------
End

문의하기

Author:

Mr. Terry

Phone/WhatsApp:

+8613775341656

인기 상품
You may also like
Related Categories

이 업체에게 이메일로 보내기

제목:
휴대전화:
이메일:
메시지:

Your message must be betwwen 20-8000 characters

We will contact you immediately

Fill in more information so that we can get in touch with you faster

Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.

송신