⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ver30.asm

📁 用一片单片机控制两个直流无刷电机运转,所以可有效的控制两个直流无刷电机的同步运转
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	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 + -