12c509A示例程序
扫描二维码
随时随地手机看文章
include"P12c509a.inc"
__CONFIGh’000E’;CPoff,WDTon,internalcLOCk
DCConequ0
Ovl_inequ1
Relayequ2
Ovl_outequ4
CBLOCK0x0007
state;statesequence
time0;counter0
time1;counter1
time2;counter2
ENDC
org0
MOVwfOSCCAL;setcal
bcfSTATUS,PA0
MOVlwB’10001111’
option
;GP0DCCON/OFF(hiisON);;;;;;GP1isoverloadinput(activelo)
;GP2Reverseoutput;;;;;;;;GP4overloadoutput(HIisoverload)
;-----------------------------
MOVlwB’00000010’
trisGPIO
MOVlwB’00000001’;setports
MOVwfGPIO
clrfstate
;mainloopstartshere.SCANsforhionoverload.
testclrwdt
btfssGPIO,Ovl_in;lookforoverload
gotoset1
test1btfscstate,0;checkstate
gotocaltim;resetdelay
gototest;lookagain
;hereiftrueoverload
set1bcfGPIO,DCCon;turnoff
btfscstate,0;0iffirsttimeafterreset
gotostate1
bsfstate,0;settostate1
MOVfGPIO,W;getportsetting
xorlwB’00000100’;reverserelay
MOVwfGPIO
calldely25;delay25millisecsforrelay
bsfGPIO,DCCon;turnbackon
gototest;lookforoverload
state1bsfGPIO,Ovl_out;setalarm
calldel500
bsfstate,7;settimeout
bcfGPIO,Ovl_out;alarmoff
bsfGPIO,DCCon;outputon
gototest
caltimcalltimout;resettimer
gototest
delayMOVlw0xFF;shortdelay
MOVwftime0
delay1clrwdt
nop
nop
decfsztime0,F
gotodelay1
retlw0
dely25clrwdt
MOVlw.30;25millisecs
MOVwftime1
del25aMOVlw0xFF
MOVwftime2
del25bdecfsztime2,F
gotodel25b
decfsztime1,F
gotodel25a
retlw0
del500MOVlw0xFF;500millisecs
MOVwftime1
del500aMOVlw0xFF
MOVwftime2
del500bclrwdt
nop
nop
nop
nop
decfsztime2,F
gotodel500b
decfsztime1,F
gotodel500a
retlw0
timoutbtfssstate,7;continuecountdown
gotocountdn
MOVlw0xFF;setcounters
MOVwftime1
timo2MOVlw0xFF
MOVwftime2
bcfstate,7
countdndecfsztime2,F
retlw0
decfsztime1,F
gototimo3
clrfstate;reset
retlw0
timo3MOVlw0xFF
MOVwftime2
retlw0
end