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

📄 detect.asm

📁 应用松翰母体写的一款电磁炉
💻 ASM
字号:
;******************************************************
;name:mndetect
;function:用于各种A/D检测的切换
;input:
;output:
;register:
;*******************************************************
mndetect:
;//	jb1	malfunctionflag,mndetect90
	jb0	havecookerflag,mndetect90	;=1:锅符合,开始工作
	jb0	operateflag,mndetect90		;工作状态下,开启检测
	jb1	volADCflag,voltagedetect    	;电压检测
	jb1	curADCflag,currentdetect    	;电流检测 
	jb1	IgbtADCflag,Igbttempdetect  	;IGBT温度检测 
	jb1	cookerADCflag,cookertempdetect	;锅底温度检测
;-----
;强制纠错
	bset	volADCflag
	bclr	ADCstartflag
	bclr	ADCendflag
;-----
mndetect90:
	ret

;******************************************************
;name:voltagedetect
;function:用于电压检测(包括市电电压过压、欠压检测)
;input:
;output:
;register:temp0,temp1
;*******************************************************
voltagedetect:
	b0bts0	ADCendflag
	jmp	voltagedetect80
	b0bts0	ADCstartflag
	jmp	voltagedetect70
;-----
	bset	ADCstartflag
	mov	a,#01h
	mov	p4con,a		;isolate an0
	mov	a,#00h
	mov	adm,a		;enable an0
	mov_	var1,#4	
	clr	ADCvaluel
	clr	ADCvalueh
;-----
voltagedetect70:
	call	mnADconvert
	ret
;-------------------------
;取出AD值,进行比较
voltagedetect80:
;-----
	bclr	volADCflag
	bset	curADCflag
	bclr	IgbtADCflag
	bclr	cookerADCflag
	bclr	ADCstartflag
	bclr	ADCendflag
;-----
;先市电电压过压、欠压检测
	call	voltageanalyse
;-----
;pwm脉宽调整220V±5
	mov_	temp0,ADCvolbufl
	mov_	temp1,ADCvolbufh
	call	mnpwmpulseset	
;-----
voltagedetect90:
	ret
	
;******************************************************
;name:currentdetect
;function:用于检测负载电流
;input:
;output:
;register:temp0,temp1
;*******************************************************
currentdetect:
	b0bts0	ADCendflag
	jmp	currentdetect80
	b0bts0	ADCstartflag
	jmp	currentdetect70
;-----
	bset	ADCstartflag
	mov	a,#02h
	mov	p4con,a		;isolate an1
	mov	a,#01h
	mov	adm,a		;enable an1
	mov_	var1,#4	
	clr	ADCvaluel
	clr	ADCvalueh
;-----
currentdetect70:
	call	mnADconvert
	ret
;-------------------------------
;取出AD值,进行比较
currentdetect80:
;-----
	bclr	volADCflag
	bclr	curADCflag
	bset	IgbtADCflag
	bclr	cookerADCflag
	bclr	ADCstartflag
	bclr	ADCendflag
;-----
;先过流检测
	call	currentanalyse
;-----
;pwm脉宽调整
	mov_	temp0,ADCcurbufl
	mov_	temp1,ADCcurbufh
	call	mnpwmpulseset	
;-----
currentdetect90:
	ret
	
;******************************************************
;name:Igbttempdetect
;function:用于检测IGBT温度
;input:
;output:
;register:temp0,temp1
;*******************************************************
Igbttempdetect:
	b0bts0	ADCendflag
	jmp	Igbttempdetect70
	b0bts0	ADCstartflag
	jmp	Igbttempdetect60
;-----
	bset	ADCstartflag
	mov	a,#04h
	mov	p4con,a		;isolate an2
	mov	a,#02h
	mov	adm,a		;enable an2
	mov_	var1,#4	
	clr	ADCvaluel
	clr	ADCvalueh
;-----
Igbttempdetect60:
	call	mnADconvert
	ret
;-----
;取出AD值,进行比较
Igbttempdetect70:
;-----
	bclr	volADCflag
	bclr	curADCflag
	bclr	IgbtADCflag
	bset	cookerADCflag
	bclr	ADCstartflag
	bclr	ADCendflag
;-----
;温度传感器开、短路分析
	call	sensoranalyse
;-----
	b0bts0	malfunctionflag
	jmp	Igbttempdetect90
	mov_	temp0,#ADCIGBTvalueL
	mov_	temp1,#ADCIGBTvalueH
;-----
;IGBT过热分析
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1		 ;ADCvalue-temp
	b0bts1	fc
	jmp	Igbttempdetect80 ;没有超温
	bset	overtempflag
;-----
	mov_	seg2buf,#Errorvalue2
	mov_	seg1buf,#Errorvalue
	bset	malfunctionflag
	ret
;-----
Igbttempdetect80:
	bclr	overtempflag
;-----
Igbttempdetect90:
	ret
	
;******************************************************
;name:cookertempdetect
;function:用于检测锅底的温度
;input:
;output:
;register:temp0,temp1
;*******************************************************
cookertempdetect:
	b0bts0	ADCendflag
	jmp	cookertempdetect70
	b0bts0	ADCstartflag
	jmp	cookertempdetect60
;-----
	bset	ADCstartflag
	mov	a,#8h
	mov	p4con,a		;isolate an3
	mov	a,#03h
	mov	adm,a		;enable an3
	mov_	var1,#4	
	clr	ADCvaluel
	clr	ADCvalueh
;-----
cookertempdetect60:
	call	mnADconvert
	ret
;-----
;取出AD值,进行比较
cookertempdetect70:
;-----
	bset	volADCflag
	bclr	curADCflag
	bclr	IgbtADCflag
	bclr	cookerADCflag
	bclr	ADCstartflag
	bclr	ADCendflag
;-----
;温度传感器开、短路分析
	call	sensoranalyse
;-----
	b0bts0	malfunctionflag
	jmp	cookertempdetect90
;-----
;过热分析
	call	hotestanalyse
;-----
	b0bts0	malfunctionflag
	jmp	cookertempdetect90
;-----
;温度控制
	b0bts0	overtempflag
	jmp	cookertempdetect80
;-----
	mov_	temp0,ADCtempbufl
	mov_	temp1,ADCtempbufh
;-----
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1		   ;ADCvalue-temp
	b0bts1	fc
	jmp	cookertempdetect90 ;没有超温
;-----
;在哪一功能下
	mov	a,flag3
	and	a,#00011000b
	b0bts0	fz
	jmp	stopheat
	b0bts1	fourthstepflag
	jmp	cookertempdetect50
;-----------------------
stopheat:
	bset	overtempflag
	bclr	ptcout
	bclr	fpwm1out
	bclr	ftc1enb		   ;stop t1 pwm
	ret	
;----------------------
cookertempdetect50:
	bset	tempcomeflag
	ret
;----------------------
cookertempdetect80:	
;-----
	mov_	temp0,ADCtempbufl  ;超温后,温度往下降个10点再加热
	mov_	temp1,ADCtempbufh
	mov	a,temp0
	sub	a,#10
	mov	temp0,a
	mov	a,#0	
	mov	temp2,a
	mov	a,temp1
	sbc	a,temp2	
	mov	temp1,a
;-----
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1		   ;ADCvalue-temp
	b0bts0	fc
	jmp	cookertempdetect90
;---
	bclr	overtempflag
	bclr	Igbtstartupflag
;-----
cookertempdetect90:
	ret
	
;**********************************************
;Name	:cookercheck
;Function:无锅具、锅具材料不合、小物件检测
;Input  :
;Output	:
;Register Used:
;***********************************************
cookercheck:
;-----

;-----
cookercheck90:
	ret

;**********************************************
;Name	:mnADconvert
;Function:A/D转换四次,然求四次的平均值 
;Input  :
;Output	:
;Register Used:var1
;***********************************************	
mnADconvert:
;//	mov_	var1,#4	
;//	clr	ADCvaluel
;//	clr	ADCvalueh
	b0bset	fgchs		;enable ain
	b0bset	fadenb		;enable ad
	call	delay100us	;stable ad circuit
;----
convert_again:	
	b0bset 	fads		;start convert
waitadchigh:
	b0bts1	feoc		;check finish convert or not
	jmp	waitadchigh
	bclr	feoc
;----
	mov	a,adr
	and	a,#0fh
	mov	ADCtemp,a
	swap	adb
	and	a,#0f0h
	or	a,ADCtemp
	add	ADCvaluel,a	
	swap	adb		
	and	a,#0fh
	adc	ADCvalueh,a
	decms	var1		
	jmp	convert_again	;check again
;----
	bset	ADCendflag	;set A/D convert over
	b0bclr	fgchs		;disable ain
	b0bclr	fadenb		;disable ad
	clr	p4con		;release AIN pin
;----
	bclr	fc
	rrcm	ADCvalueh
	rrcm	ADCvaluel
;---
	bclr	fc
	rrcm	ADCvalueh
	rrcm	ADCvaluel	;AD/4	
	ret
;**********************************************
;Name	:mnpwmpulseset
;Function:pwm adjust
;Input  :
;Output	:
;Register Used:temp0,temp1
;***********************************************	
mnpwmpulseset:	
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1		;ADCvalue-temp
	b0bts1	fc
	jmp	incvolpwm	;<
;-----				;>
	mov	a,pwmpulsebuf	;dec pwm pulse width
	b0bts0	fz
	jmp	sendvolvalue
	decms	pwmpulsebuf
	nop
	jmp	sendvolvalue
;----
incvolpwm:
	mov	a,pwmpulsebuf
	sub	a,#31
	b0bts0	fc
	jmp	beyondrange
	incms	pwmpulsebuf
	nop
	jmp	sendvolvalue
;----
beyondrange:
	mov_	pwmpulsebuf,#31
;----
sendvolvalue:
	mov_	tc1c,pwmpulsebuf
	ret
;**********************************************
;Name	:voltageanalyse
;Function:市电电压分析
;Input  :
;Output	:
;Register Used:temp0,temp1
;***********************************************
voltageanalyse:
;-----
;过压分析
	mov_	temp0,#uppervaluel
	mov_	temp1,#uppervalueh
;----
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1
	b0bts0	fc
	jmp	beyondvolt	;过压
;----
	mov_	temp0,#lowervaluel
	mov_	temp1,#lowervalueh
;----
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1
	b0bts0	fc
	jmp	normalvolt	;电压正常
;----
;欠压
	mov_	seg2buf,#Errorvalue4
	mov_	seg1buf,#Errorvalue
	bset	malfunctionflag
	ret
;----
;过压
beyondvolt:
	mov_	seg2buf,#Errorvalue3
	mov_	seg1buf,#Errorvalue
	bset	malfunctionflag
	ret
normalvolt:
	bclr	malfunctionflag
	ret
	

;**********************************************
;Name	:currentanalyse
;Function:过流分析
;Input  :
;Output	:
;Register Used:temp0,temp1
;***********************************************
currentanalyse:
	mov_	temp0,#currentvaluel
	mov_	temp1,#currentvalueh
;----
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1
	b0bts1	fc
	jmp	normalcurrent
;----
;过流
	mov_	seg2buf,#Errorvalue0
	mov_	seg1buf,#Errorvalue
	bset	malfunctionflag
	ret
;----
normalcurrent:
	ret
	
;**********************************************
;Name	:hotestanalyse
;Function:陶瓷面板过热分析
;Input  :
;Output	:
;Register Used:temp0,temp1
;***********************************************	
hotestanalyse:
	mov_	temp0,#hotestvaluel
	mov_	temp1,#hotestvalueh
;----
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1
	b0bts1	fc
	jmp	normaltemp
;----
;过热
	mov_	seg2buf,#Errorvalue6
	mov_	seg1buf,#Errorvalue
	bset	malfunctionflag
	ret
;----
normaltemp:
;//	bclr	malfunctionflag		;需手动解除
	ret

	
	
;**********************************************
;Name	:sensoranalyse
;Function:传感器分析
;Input  :
;Output	:
;Register Used:temp0,temp1
;***********************************************	
sensoranalyse:
;----
;开路分析
	mov_	temp0,#openvaluel
	mov_	temp1,#openvalueh
;----
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1
	b0bts1	fc
	jmp	openproblem	;传感器开路
;----
;短路分析
	mov_	temp0,#shortvaluel
	mov_	temp1,#shortvalueh
;----
	mov	a,ADCvaluel
	sub	a,temp0
	mov	a,ADCvalueh
	sbc	a,temp1
	b0bts1	fc
	jmp	sensornormal	;传感器正常
;----
;传感器短路
	mov_	seg2buf,#Errorvalue6
	mov_	seg1buf,#Errorvalue
	bset	malfunctionflag
	ret
;------------------
;传感器开路
openproblem:
	mov_	seg2buf,#Errorvalue5
	mov_	seg1buf,#Errorvalue
	bset	malfunctionflag
	ret
;-------------
sensornormal:
;//	bclr	malfunctionflag		;需手动解除
	ret
;**********************************************
;Name	:func_analyse
;Function:under which function 
;Input  :
;Output	:
;Register Used:temp0,temp1
;***********************************************
func_analyse:


func_analyse90:
	ret
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -