当前位置:首页 > 单片机 > 单片机
[导读] PIC16F628红外接收程序;SomenotesonRC5;;14RC5bits:;SSTAAAAACCCCCC;;S:2startbits,T:1togglebit,A:5addressbits,C:6commandbits;;Usuallybothstartbitsarehigh.ExtendedRC5usesthe2ndstartbitforexpan

PIC16F628红外接收程序
;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(e.g.SFH5110-xx)haveanactivelowoutput,however,the
;PIC’sinternalcomparatorinvertsthesignal.AninvertingdrivertransistorfortheRS232
;interfacefinallyinvertsandlevelshiftsthesignalagainsothatthestandardLIRC
;configuration(i.e.activelow)mustbeused.
;
;
;PIC16F628connections
;
;PINFUNCTION
;
;RB7ICSP
;RB6ICSP
;RA5ICSP
;
;RB5测试输出,高电平有效
;RB4PWRin--PC开关输入低电平有效
;RB3RESETout--输出晶体管重拨,高电平有效
;RB2PWRout--输出晶体管forMBATXpwron/off,高电平有效
;RB1LEDgrn--输出LED绿管,高电平有效
;RB0LEDred--输出LED红管,高电平有效
;
;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;assignedRC5pwrkeyaddress’000AAAAA’(recalledfromEEPROMlocationh’01’)
PWR_KEY_CMD;assignedRC5pwrkeycommand’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;doesPWR_KEY_ADRmatch?
gotono_match;-no,gotono_match
;
MOVfwRC5_CMD;-yes,loadRC5_CMDintow
andlwb’01111111’;andcleartogglebit
subwfPWR_KEY_CMD,w;
btfssstatus,z;doesPWR_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;fornexttogglebitcomparison

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
gotoreset;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
;occuringdirectlyafterthecodegeneratedabovewoulddestroy
;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’;keeponlylsbinw,
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

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

9月2日消息,不造车的华为或将催生出更大的独角兽公司,随着阿维塔和赛力斯的入局,华为引望愈发显得引人瞩目。

关键字: 阿维塔 塞力斯 华为

加利福尼亚州圣克拉拉县2024年8月30日 /美通社/ -- 数字化转型技术解决方案公司Trianz今天宣布,该公司与Amazon Web Services (AWS)签订了...

关键字: AWS AN BSP 数字化

伦敦2024年8月29日 /美通社/ -- 英国汽车技术公司SODA.Auto推出其旗舰产品SODA V,这是全球首款涵盖汽车工程师从创意到认证的所有需求的工具,可用于创建软件定义汽车。 SODA V工具的开发耗时1.5...

关键字: 汽车 人工智能 智能驱动 BSP

北京2024年8月28日 /美通社/ -- 越来越多用户希望企业业务能7×24不间断运行,同时企业却面临越来越多业务中断的风险,如企业系统复杂性的增加,频繁的功能更新和发布等。如何确保业务连续性,提升韧性,成...

关键字: 亚马逊 解密 控制平面 BSP

8月30日消息,据媒体报道,腾讯和网易近期正在缩减他们对日本游戏市场的投资。

关键字: 腾讯 编码器 CPU

8月28日消息,今天上午,2024中国国际大数据产业博览会开幕式在贵阳举行,华为董事、质量流程IT总裁陶景文发表了演讲。

关键字: 华为 12nm EDA 半导体

8月28日消息,在2024中国国际大数据产业博览会上,华为常务董事、华为云CEO张平安发表演讲称,数字世界的话语权最终是由生态的繁荣决定的。

关键字: 华为 12nm 手机 卫星通信

要点: 有效应对环境变化,经营业绩稳中有升 落实提质增效举措,毛利润率延续升势 战略布局成效显著,战新业务引领增长 以科技创新为引领,提升企业核心竞争力 坚持高质量发展策略,塑强核心竞争优势...

关键字: 通信 BSP 电信运营商 数字经济

北京2024年8月27日 /美通社/ -- 8月21日,由中央广播电视总台与中国电影电视技术学会联合牵头组建的NVI技术创新联盟在BIRTV2024超高清全产业链发展研讨会上宣布正式成立。 活动现场 NVI技术创新联...

关键字: VI 传输协议 音频 BSP

北京2024年8月27日 /美通社/ -- 在8月23日举办的2024年长三角生态绿色一体化发展示范区联合招商会上,软通动力信息技术(集团)股份有限公司(以下简称"软通动力")与长三角投资(上海)有限...

关键字: BSP 信息技术
关闭
关闭