?? ver30.asm
字號:
bcf updirectionflag ;不再處于上升狀態
bcf storeflag
call writedatasub ;保存數據
btfss mainflag ;不是主控制器則跳過延時
goto upnotmainbranch
call delay10ssub ;延時10S
call changeparametersub ;改變系統參數
upnotmainbranch
movlw topstart ;計算延時數據地址
addwf topcount,w
movwf fsr
movf indf,w
movwf delaytemp
;movwf indf ;把延時數據保存
btfss runmodeflag
goto modesetbranch
bcf bottomerrorflag
;bcf storeflag
;call writedatasub ;保存數據
goto downnormalrunstart ;轉到向下正常運轉
updelay10sbranch
bcf storeflag
call writedatasub ;保存數據
btfss mainflag
goto upnotmainbranch1
call delay10ssub ;延時10S
call changeparametersub ;改變系統參數
upnotmainbranch1
movlw topstart ;計算延時數據地址
addwf topcount,w
movwf fsr
movf indf,w
movwf delaytemp
;movwf indf ;把延時數據保存
;incf topcount,f ;指向下一組地址
btfss runmodeflag
goto modesetbranch
bcf storeflag
call writedatasub ;保存數據
goto upnormalrun ;繼續向上正常運轉
downnormalrunstart ;下降開始
;call readdatasub ;數據重新讀取
movf advcount,w
movwf advcounttemp
;movlw 3h
;subwf topcount,f
;clrf topcount
bcf topflag ;不再處于頂部
bsf downdirectionflag ;處于下降狀態
;goto downnormalrunbranch1
downnormalrun
downnormalrunbranch
btfsc stopflag
goto waitdownstartrun1
btfsc notrunvoltagestopflag
goto downcall1 ;如由于停電引起則downcall1
btfsc mainflag
goto continuedownbranch ;為主控制器則直接運轉
btfss finishflag ;一幅畫已完成?
goto continuedownbranch ;沒有完成則應完成該幅畫
downcheckinput
btfsc mode
goto modeset ;處于參數設置狀態
call voltagecomparesub ;比較電壓低于規定值則斷開蓄電池并保存數據
btfsc startpulseinput ;檢測有沒有負脈沖發生
goto downcheckinput
call delaysub
call delaysub
btfsc startpulseinput
goto downcheckinput
btfsc directioninput ;是否向下運行
goto downcheckinput ;不是則等待向下運行
continuedownbranch
movlw d'3'
subwf topcount,f ;指向下一組地址
movlw d'1'
subwf topcount,w
btfsc status,z ;判斷TOPCOUNT是否為1
goto topcountisone
movlw d'4'
subwf topcount,f
call getdatafromramsub ;從RAM中提取數據
goto addspeeddatalowbranch
topcountisone
movf bottomlow,w ;是則置0
movwf toplow
movwf lowspeedlow
movf bottommed,w
movwf topmed
movwf lowspeedmed
movf bottomhig,w
movwf tophig
movwf lowspeedhig
movlw topstart
movwf fsr ;第一幅畫的停留時間
movf indf,w
movwf delaytemp
addspeeddatalowbranch
call addspeeddatalowsub ;計算需要減速的位置
goto downcall
downcall1
bcf notrunvoltagestopflag
goto downcall
downcall2
bcf stopflag
downcall
bcf storeflag
call writedatasub
bsf pclath,3h
call downsub ;電機下降
bcf pclath,3h
btfss stopflag
goto downrunbranch1 ;如沒有按停止鍵則繼續往復運轉
waitdownstartrun1
btfsc lockerrorflag
call lockerrorhowtodosub
btfsc bottomerrorflag
call bottomerrorhowtodosub
;goto downcall2
;如按下停止鍵則等待按下開始運行鍵
waitdownstartrun
movlw remotemask
andwf remote,w ;讀取遙控器輸入數據
movwf remotetemp
movlw increasekey ;是否為increasekey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
goto downcall2
call presschangespeedkeysub ;是否按下速度變化鍵
call writedatasub ;保存數據
call cannotrunvoltagesub ;電壓低于規定值則關閉電源
btfsc mode
goto modeset ;處于參數設置狀態
goto waitdownstartrun
downrunbranch1
decfsz advcounttemp,f
goto downdelay10sbranch
bsf bottomflag ;處于最低位置
bcf downdirectionflag ;不再處于下降狀態
bcf storeflag
call writedatasub ;保存數據
btfss mainflag
goto downnotmainbranch
call delay10ssub ;延時10S
call changeparametersub ;改變系統參數
downnotmainbranch
movlw topstart ;計算延時數據地址
movwf fsr
movf indf,w
movwf delaytemp
;movwf indf ;把延時數據保存
btfss runmodeflag
goto modesetbranch
;bcf storeflag
;call writedatasub ;保存數據
movlw bottommin
movwf pulselow1
clrf pulsemed1
clrf pulsehig1
bcf toperrorflag
goto upnormalrunstart ;轉到向上正常運轉
downdelay10sbranch
bcf storeflag
call writedatasub ;保存數據
btfss mainflag
goto downnotmainbranch1
call delay10ssub ;延時10S
call changeparametersub ;改變系統參數
downnotmainbranch1
movlw topstart ;計算延時數據地址
addwf topcount,w
movwf fsr
movf indf,w
movwf delaytemp
;movwf indf ;把延時數據保存
btfss runmodeflag
goto modesetbranch
;bcf storeflag
;call writedatasub ;保存數據
goto downnormalrun ;繼續向下正常運轉
return
;****************
;主控制器判斷子程序
;****************
mainchecksub
bsf directionsignal ;7輸出高電平
banksel trisc
movlw b'10001111' ;0,1,2,3,7輸入,其他輸出
movwf trisc
banksel portc
bcf startpulsesignal ;輸出低電平
call delaysub
btfss directionsignal ;判斷PORT6,PORT7是否聯在一起
goto notmain
bsf mainflag ;沒有聯在一起則為主控制
;call delaysub
;call delaysub
notmain
banksel trisc
movlw b'00001111'
movwf trisc
banksel portc
bsf startpulsesignal
bsf directionsignal
return
;*********************
;上限超錯誤處理子程序
;*********************
toperrorhowtodosub
bsf systemerror
call threehightonesub
call delaysub
call delaysub
call delaysub
call threehightonesub
call delaysub
call delaysub
call delaysub
call threehightonesub
call delaysub
call delaysub
call delaysub
return
;*********************
;下限超錯誤處理子程序
bottomerrorhowtodosub
bsf systemerror
call threelowtonesub
call delaysub
call delaysub
call delaysub
call threelowtonesub
call delaysub
call delaysub
call delaysub
call threelowtonesub
call delaysub
call delaysub
call delaysub
return
;********************
;按速度改變鍵子程序
;********************
presschangespeedkeysub
movlw highspeedkey ;是否為highspeedkey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call highspeedkeysub
movlw medspeedkey ;是否為medspeedkey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call medspeedkeysub
movlw lowspeedkey ;是否為lowspeedkey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call lowspeedkeysub
movlw stoptime1minkey ;是否為stoptime1minkey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call stoptime1minkeysub
movlw stoptime5minkey ;是否為stoptime5minkey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call stoptime5minkeysub
movlw stoptime10minkey ;是否為stoptime10minkey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call stoptime10minkeysub
return
;***********************
;系統發生堵轉錯誤時處理子程序
;***********************
lockerrorhowtodosub
bsf systemerror
call threelowtonesub
call delaysub
call delaysub
call delaysub
call threehightonesub
call delaysub
call delaysub
call delaysub
call threelowtonesub
call delaysub
call delaysub
call delaysub
waitpersondo
call cannotrunvoltagesub
movlw remotemask
andwf remote,w ;讀取遙控器輸入數據
movwf remotetemp
movlw increasekey ;是否為increasekey按鈕
subwf remotetemp,w ;remotetemp-w
btfss status,z ;=0?
goto waitpersondo
call delaysub
call delaysub
movlw remotemask
andwf remote,w ;讀取遙控器輸入數據
movwf remotetemp
movlw increasekey ;是否為increasekey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
goto waitpersondo
bcf lockerrorflag
bcf systemerror
call threelowtonesub
return
;**************************
;計算繼電器吸合斷開電壓子程序
;**************************
calculatevoltagesub
bsf adcon0,go ;開始轉換
call readadcsub ;讀取輸入電壓
movf adcvoltage,w
movwf turnonvoltagereg
movwf turnoffvoltagereg
movlw deltturnoffvoltage
subwf turnoffvoltagereg,f ;計算實際的繼電器斷開電壓
movlw deltturnonvoltage
subwf turnonvoltagereg,f ;計算實際的繼電器吸合電壓
return
;*********************
;檢查電機HALL輸入子程序
;*********************
checkhallinputsub
checkhallinputstart
;判斷上電機霍爾元件輸入信號是否正確
movlw upsensormask ;retain only the sensor bits
andwf sensorport,w ;get sensor data
btfsc status,z ;sensor=0?
GOTO DOSYSTEMERROR ;sensor=0則錯誤燈亮
;bsf systemerror
xorlw b'00000111' ;sensor=7?
btfss status,z
goto upsensornotequal7
bsf systemerror ;sensor=7則錯誤燈亮
goto dosystemerror
upsensornotequal7
bcf systemerror ;其他則錯誤燈滅
upsensorend
;判斷下電機霍爾元件輸入信號是否正確
movlw downsensormask ;retain only the sensor bits
andwf sensorport,w ;get sensor data
btfsc status,z ;sensor=0?
goto dosystemerror ;sensor=0則錯誤燈亮
;bcf systemerror
xorlw b'00111000' ;sensor=7?
btfss status,z
goto downsensornotequal7
dosystemerror
bsf systemerror ;sensor=7則錯誤燈亮
call threelowtonesub ;三聲低音
;call threelowtonesub ;三聲低音
goto checkhallinputstart
downsensornotequal7
bcf systemerror ;其他則錯誤燈滅
return
;**************
;改變參數子程序
;**************
changeparametersub
changeparameterstart
btfss changeparameterflag
return
movlw remotemask
andwf remote,w ;讀取遙控器輸入數據
movwf remotetemp
movlw increasekey ;是否為increasekey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call increasekeysub ;=0則調用increasekeysub
movlw decreasekey ;是否為decreasekey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call decreasekeysub ;=0則調用decreasekeysub
movlw runtomodekey ;是否為runtomodekey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call runtomodekeysub ;=0則調用runtomodekeysub
movlw stopandrunkey ;是否為stopandrunkey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z ;=0?
call clearchangeparameterflagsub ;=0則調用clearchangeparameterflagsub
movlw stoptimekey ;是否為stoptimekey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z
call stoptimekeysub ;=0則調用stoptimekeysub
movlw allstoptimekey ;是否為allstoptimekey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z
call allstoptimekeysub ;=0則調用allstoptimekeysub
movlw allstoptime3key ;是否為allstoptime3key按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z
call allstoptime3keysub ;=0則調用allstoptime3keysub
movlw defaultspeedkey ;是否為defaultspeedkey按鈕
subwf remotetemp,w ;remotetemp-w
btfsc status,z
call defaultspeedkeysub ;=0則調用defaultspeedkeysub
call cannotrunvoltagesub ;低于規定電壓則需關閉系統
btfsc mode
bcf runmodeflag ;處于參數設置狀態
goto changeparameterstart
return
;********************
;從RAM中取數據子程序
;********************
getdatafromramsub
movlw topstart ;取出比較數據
addwf topcount,w
movwf fsr
movf indf,w
movwf toplow ;停止位置
movwf lowspeedlow ;開始減速位置
incf fsr,f
movf indf,w
movwf topmed ;停止位置
movwf lowspeedmed ;開始減速位置
incf fsr,f
movf indf,w
movwf tophig ;停止位置
movwf lowspeedhig ;開始減速位置
incf fsr,f
movf indf,w
movwf delaytemp
movlw 3h
addwf topcount,f ;到延時數據地址
return
;********************
;減去SPEEDDATALOWSUB
;********************
subspeeddatalowsub
movlw speeddatalow
subwf lowspeedlow,f
btfsc status,c
goto subspeedmed ;lowspeedmed-speedatamed
movlw 1h ;有借位則LOWSPEEDMED-1
subwf lowspeedmed,f
btfsc status,c
goto subspeedmed ;lowspeedmed-speeddatamed
decf lowspeedhig,f ;有借位則LOWSPEEDHIG-1
subspeedmed
movlw speeddatamed
subwf lowspeedmed,f
btfsc status,c
return
decf lowspeedhig,f ;有借位則LOWSPEEDHIG-1
return
;********************
;增加speeddatalowsub
;********************
addspeeddatalowsub
addspeeddatabranch1
movlw speeddatalow
addwf lowspeedlow,f ;lowspeedlow+speeddatalow
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -