📄 ver30.asm
字号:
;****************
delaysub
movlw d'64'
movwf count3
delayloop2
MOVLW 0h
MOVWF COUNT2
delayloop1
DECFSZ COUNT2,F
GOTO delayLOOP1
decfsz count3,f
goto delayloop2
return
;*********************
;蜂鸣器高低电平延时子程序
;*********************
beephighlowdelaysub
;movlw d'50'
movwf count3
beephighlowdelayloop2
;MOVLW d'100'
MOVWF COUNT2
beephighlowdelayloop1
DECFSZ COUNT2,F
GOTO beephighlowdelayLOOP1
decfsz count3,f
goto beephighlowdelayloop2
return
;*******************
;蜂鸣器高音子程序
;*******************
beephightonesub
movlw beephightonecount
movwf beepcount
beephightonesubloop
bsf beepcontrol ;蜂鸣器高电平
movlw d'25'
movwf count3
movlw d'25'
movwf count2
call beephighlowdelaysub
bcf beepcontrol ;蜂鸣器高电平
movlw d'25'
movwf count3
movlw d'25'
movwf count2
call beephighlowdelaysub
decfsz beepcount,f
goto beephightonesubloop
return
;*******************
;蜂鸣器低音子程序
;*******************
beeplowtonesub
movlw beeplowtonecount
movwf beepcount
beeplowtonesubloop
bsf beepcontrol ;蜂鸣器高电平
movlw d'100'
movwf count3
movlw d'100'
movwf count2
call beephighlowdelaysub
bcf beepcontrol ;蜂鸣器高电平
movlw d'100'
movwf count3
movlw d'100'
movwf count2
call beephighlowdelaysub
decfsz beepcount,f
goto beeplowtonesubloop
return
;****************
;三声高音子程序
;****************
threehightonesub
call beephightonesub
call delaysub
call delaysub
call delaysub
call beephightonesub
call delaysub
call delaysub
call delaysub
call beephightonesub
return
;****************
;三声低音子程序
;****************
threelowtonesub
call beeplowtonesub
call delaysub
call delaysub
call delaysub
call beeplowtonesub
call delaysub
call delaysub
call delaysub
call beeplowtonesub
return
;****************
;二声低音子程序
;****************
twolowtonesub
call beeplowtonesub
;call delaysub
;call delaysub
;call delaysub
;call beeplowtonesub
return
;****************
;一高音二低音子程序
;****************
onehightwolowtonesub
call beephightonesub
call delaysub
call delaysub
call delaysub
call delaysub
call beeplowtonesub
call delaysub
call delaysub
call delaysub
call delaysub
call beeplowtonesub
return
;**************
;持续上升子程序
;**************
continueupsub
call delaysub ;延时后按钮是否仍为continueup按钮,是则继续
call delaysub
movlw remotemask
andwf remote,w ;读取遥控器输入数据
movwf remotetemp
movlw updownkey ;是否为updownkey按钮
subwf remotetemp,w ;remotetemp-w
btfss status,z ;=0?
return
bsf pclath,3h
call motornotrunsub ;电机不运转
bcf pclath,3h
btfsc voltagelowflag ;电压低于22V则关闭
return
btfsc lockerrorflag
return
; clrf lastupsensor
; clrf lastdownsensor
bcf topsetflag
bcf starttime
bsf directionbit ;电机转向为开门
bcf storeflag
clrf tmr2 ;timer2用于判断电机是否堵转
clrf timer2ifcount
movf setspeedreg,w
movwf upmotoradc ;上电机设置参数时电机转速
movf sametimespeedreg,w
movwf downmotoradc ;下电机运转转速
bcf brakecontrol ;机械刹车不起作用
continueuploop
bsf needpulsecountflag ;需要脉冲计数
bsf addpulsecountflag ;脉冲加计数
bsf pclath,3h
call upmotorrunsub ;上电机运转
bcf needpulsecountflag ;下电机运转不需要计数
call downmotorrunsub ;下电机运转
bcf pclath,3h
movlw remotemask
andwf remote,w ;读取遥控器输入数据
movwf remotetemp
movlw updownkey ;是否为updownkey按钮
subwf remotetemp,w ;remotetemp-w
btfss status,z ;=0?
goto continueupend
movlw cannotrunvoltage ;电压是否低于18V
movwf voltagecompare
call voltagelowsub ;电压是否低于18V
btfsc voltagelowflag
goto continueupend ;是则结束
BTFSS position ;是否经过校正位置
call storepositionsub ;是则保存数据
btfsc position
bcf positionflag
goto continueuploop
continueupend
call calculatetopmaxsub
bsf pclath,3h
call motornotrunsub
bcf pclath,3h
call motorlocksub ;电机电刹车
bsf brakecontrol ;机械刹车起作用
return
;****************
;电机电刹车子程序
;****************
motorlocksub
clrf driveport ;上电机电刹车停止
bsf enableupmotor
nop
bcf enableupmotor
nop
bsf enabledownmotor ;下电机电刹车起作用
nop
bcf enabledownmotor
return
;***************
;持续下降子程序
;***************
continuedownsub
call delaysub ;延时后是否仍为continuedown按钮,是则继续
call delaysub
movlw remotemask
andwf remote,w ;读取遥控器输入数据
movwf remotetemp
movlw updownkey ;是否为updownkey按钮
subwf remotetemp,w ;remotetemp-w
btfss status,z ;=0?
return
btfsc voltagelowflag ;电压低则返回
return
btfsc lockerrorflag
return
bsf pclath,3h
call motornotrunsub ;电机不运转
bcf pclath,3h
; clrf lastdownsensor
; clrf lastupsensor
bcf topsetflag
bcf starttime
bcf directionbit ;门下降方向
bcf storeflag
clrf tmr2
clrf timer2ifcount
bcf brakecontrol ;机械刹车起作用
movf setspeedreg,w ;初始ADC值
movwf downmotoradc ;下电机设置参数时的转速
movf sametimespeedreg,w
movwf upmotoradc ;上电机同时运转的转速
continuedownloop
; bsf needpulsecountflag ;下电机运转需要计数
; bcf addpulsecountflag ;脉冲减计数
bcf needpulsecountflag ;下电机运转不需要计数
bsf pclath,3h
call downmotorrunsub ;下电机运转
bsf needpulsecountflag ;上电机同时运转需要计数
bcf addpulsecountflag ;脉冲减计数
call upmotorrunsub ;上电机同时运转
bcf pclath,3h
movlw remotemask
andwf remote,w ;读取遥控器输入数据
movwf remotetemp
movlw updownkey ;是否为updownkey按钮
subwf remotetemp,w ;remotetemp-w
btfss status,z ;=0?
goto continuedownend
movlw cannotrunvoltage ;电压是否低于18V
movwf voltagecompare
call voltagelowsub
btfsc voltagelowflag
goto continuedownend ;是则结束
goto continuedownloop
continuedownend
call calculatetopmaxsub
bsf pclath,3h
call motornotrunsub ;电机不运转
bcf pclath,3h
call motorlocksub ;电机电刹车
bsf brakecontrol ;机械刹车不起作用
return
;******************
;pulse1上限位置计算
;******************
calculatetopmaxsub
movf pulselow1,w ;pulse1->topmax
movwf toplowmax
movf pulsemed1,w
movwf topmedmax
movf pulsehig1,w
movwf tophigmax
movlw delttop ;pulselow1+deltop->toplowmax
addwf toplowmax,f
btfss status,c ;有无进位
return ;无进位则返回
movlw d'1' ;有进位则topmedmax+1
addwf topmedmax,f
btfss status,c ;有无进位
return
incf tophigmax ;有进位则tophigmax+1
return
;********************
;保存校正位置值子程序
;********************
storepositionsub
btfsc store2flag
return
btfsc positionflag
return
movf count5,f
btfss status,z ;是否第一次经过校正位置
goto nz1
movf pulsemed,w ;是则保存位置
movwf datamed1
movf pulselow,w
movwf datalow1
bsf store1flag
incf count5,f
bsf positionflag
return
nz1 movlw 1
subwf count5,w ;是否第二次经过校正位置
btfss status,z
return
movf pulsemed,w ;是则保存位置
movwf datamed2
movf pulselow,w
movwf datalow2
bsf store2flag
incf count5,f
bsf positionflag
return
org 0800h
;****************
;电机不运转子程序
;****************
motornotrunsub
movlw b'00010101'
movwf driveport ;上电机电刹车不起作用
bsf enableupmotor
nop
bcf enableupmotor
nop
bsf enabledownmotor ;下电机电刹车不起作用
nop
bcf enabledownmotor
return
;***************
;校正位置子程序
;***************
positionsub
btfsc positionflag ;是否已在校正位置上
return ;是则返回
movf count5,f
btfss status,z ;第一次经过校正位置?
goto second ;转到SENCOND
INCF COUNT5,f
movlw d'1' ;判断DATAmed1是否大于=1(data>=256?)
SUBwf datamed1,w
BTFSS STATUS,c
GOTO NOTEQU3 ;不是则转到NOTEQU3(判断DATAlow1<153?)
movlw d'51' ;DATA>=307
subwf datalow1,w
btfss status,c
goto notequ ;DATA<307且>256为1/3---2/3之间
;DATA>307
;pulse<153?
movf pulsemed,w
btfss status,z ;pulsemed=0?
goto notequ ;不是则表明PULSE>256
MOVLW d'153' ;是则判断PULSElow<153
subWF PULSElow,W
BTFSc STATUS,c
GOTO notequ ;不是则转到NOTEQU(第一次位置)
BSF secondcount ;pulselow<153则需要下一次位置
bsf positionflag ;已在校正位置上
RETURN ;返回
second
btfss secondcount ;需要下一次位置?
return ;不需要
btfss store1flag ;第一的数据是否保存过
return ;没有则结束
movf datamed1,w ;把DATA1给PUSLE
movwf pulsemed
movf datalow1,w
movwf pulselow
bsf positionflag ;已在校正位置上
bcf secondcount ;不需要下一次位置
return
NOTEQU3
MOVLW d'153'
subWF DATAlow1,W ;判断DATAlow1<153?
BTFSc STATUS,c
GOTO NOTEQU ;大于153则用第一次位置数据
;PULSE>307
MOVLW d'1' ;判断PULSEmed>=1?(pulse>256?)
subWF PULSEmed,W
BTFSS STATUS,c
GOTO NOTEQU ;pulse<256
movlw d'51'
subwf pulselow,w
btfss status,c ;pulse>307?
goto notequ ;pulse<307
;pulse>307
btfss store2flag ;第二个数据是否保存过
return ;没有则结束
MOVF DATAMED2,W ;把DATA2的值传给PULSE
MOVWF PULSEMED
MOVF DATALOW2,W
MOVWF PULSELOW
bsf positionflag ;已在校正位置上
RETURN
NOTEQU
btfss store1flag ;第一个数据是否保存过
return ;没有则结束
MOVF DATAMED1,W ;其他则把DATA1的值传给PULSE
MOVWF PULSEMED
MOVF DATALOW1,W
MOVWF PULSELOW
bsf positionflag ;已在校正位置上
RETURN
;*********************
;下降子程序
;*********************
downsub
btfsc voltagelowflag ;电压是否低于22V
return
btfsc lockerrorflag
return
btfsc bottomerrorflag ;已超过下限位置则不能继续下降
return
bcf notrunvoltagestopflag
bcf storeflag
bcf directionbit ;广告画向下运行
call motornotrunsub ;电机不运转
call page1delaysub
call page1delaysub
call page1delaysub
call producedownsignalsub
btfsc lowspeedflag ;是否处于低速运行状态
goto downlowspeedrun
clrf tmr1L ;TIMER1为0
clrf tmr1h
bsf t1con,tmr1on ;启动TIMER1
bsf starttime
clrf tmr2
clrf timer2ifcount
bcf brakecontrol ;机械刹车不起作用
increasedown2
movlw downdirupstartadc ;开始启动时ADC的值
movwf upmotoradc
movlw downdirdownstartadc
movwf downmotoradc
increasedown
btfss starttime
goto downhighspeedrun
BTFSs PIR1,TMR1IF ;TIMER1时间到,电机启动
goto increasedowntimer1noover
bcf pir1,tmr1if ;清除tmr1if
movlw downdirdownaccadc
addwf downmotoradc,f
btfss status,c
goto addupmotoradcbran
movlw d'255'
movwf downmotoradc
goto increasedownbranch1
addupmotoradcbran
movlw downdirupaccadc ;upmotoradc>=sametimespeedregtemp?
addwf upmotoradc,w
btfss status,c
goto downhighspeedrun ;upmotoradc<downrunupspeedadc
movlw upsametimehighspeedadc ;upmotoradc>=downrunupspeedadc则
movwf upmotoradc
goto downhighspeedrun
increasedownbranch1
bcf starttime ;电机启动结束,开始正常运转
movlw
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -