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

📄 sht10.asm

📁 一个温湿度控制的全部源程序
💻 ASM
📖 第 1 页 / 共 4 页
字号:
		call	de10us
		djnz	r7,sht2_temp1
		;setb	data_sht10	
		setb	sck2
		call	de10us
		clr	sck2
		call	de10us
	
		setb	data2		;011------测量温度
		call	de10us	
		setb	sck2
		call	de10us
		clr	sck2
		call	de10us
		;clr	data_sht10	
		setb	sck2
		call	de10us
		clr	sck2
		call	de10us
	
		clr	data2		;ACK
		;call	de5us	
		setb	sck2
		call	de10us
		clr	sck2
		call	de10us
		setb	data2		;等待传感器测量结束(结束时DATA被SHT10拉低				
		clr	err_sensor2
		mov	count2,#200
sht2_t0:	mov	count1,#200		
sht2_t1:	jnb	data2,sht2_t2	;11-210Ms			
        	;call	de10us
        	call	fast_key

        	djnz	count1,sht2_t1
        	djnz	count2,sht2_t0
		setb	err_sensor2
		jmp	sht2_end
sht2_t2:	call	sht2_read	;把两个字节测量数据送到r2,r3
sht2_end:	ret
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;********************
sht_humi:	clr     sck1        ;测湿度命令000 00101
				    ;call	de5us
        	clr     data1
        	call	de10us
        	mov     r7,#05h         ;
sht_humi1:   	setb    sck1
		call	de10us
        	clr     sck1
        	call	de10us
        	djnz    r7,sht_humi1        
       	 	setb    data1		;写101
       	 		;call	de5us
        	setb    sck1 
        	call	de10us   
        	clr     sck1
        	call	de10us        
        	clr     data1 
        		;call	de5us       
        	setb    sck1
        	call	de10us
        	clr     sck1
        	call	de10us
        
       	 	setb    data1 		;ACK脉冲
       	 		;call	de5us       
       	 	setb    sck1
       	 	call	de10us
       	 	clr     sck1
       	 	call	de10us        
        	clr     data1
        		;call	de5us                 
        	setb    sck1
        	call	de10us
        	clr     sck1
        	call	de10us        
        	setb    data1        	
		
		mov	count2,#200
sht_h0:		mov	count1,#200		
sht_h1:  	jnb     data1,sht_h2     ;11-210Ms 
		;call	de10us
		call	fast_key

		djnz	count1,sht_h1
		djnz	count2,sht_h0
		setb	err_sensor1          
        	jmp    	sht_h_end
sht_h2:  	call   	sht_read            ;将测量数据送到r2,r3
			;mov	r0,#zan1
			;mov	r2,#2
			;call	rs232
sht_h_end:	ret

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;2路
sht2_humi:	jb	err_sensor2,sht2_h_end
		clr     sck2        ;测湿度命令000 00101
			;call	de5us
        	clr     data2
        	call	de10us
        	mov     r7,#05h         ;
sht2_humi1:   	setb    sck2
		call	de10us
        	clr     sck2
        	call	de10us
        	djnz    r7,sht2_humi1
        
       	 	setb    data2		;写101
       	 		;call	de5us
        	setb    sck2 
        	call	de10us   
        	clr     sck2
        	call	de10us        
        	clr     data2 
        		;call	de5us       
        	setb    sck2
        	call	de10us
        	clr     sck2
        	call	de10us
        
       	 	setb    data2 		;ACK脉冲
       	 		;call	de5us       
       	 	setb    sck2
       	 	call	de10us
       	 	clr     sck2
       	 	call	de10us        
        	clr     data2
        		;call	de5us                 
        	setb    sck2
        	call	de10us
        	clr     sck2
        	call	de10us        
        	setb    data2        	
		
		mov	count2,#200
sht2_h0:	mov	count1,#200		
sht2_h1:  	jnb     data2,sht2_h2     ;11-210Ms 
		;call	de10us			
		call	fast_key	

		djnz	count1,sht2_h1
		djnz	count2,sht2_h0
		setb	err_sensor2          
        	jmp    	sht2_h_end
sht2_h2:  	call   	sht2_read            ;将测量数据送到r2,r3
	
			;mov	r0,#zan1
			;mov	r2,#2
			;call	rs232	
sht2_h_end:	ret

fast_key:	push	acc
		;clr	fast_key_f
		call	key_scan
		cjne	a,#2,fast_key1
		;setb	fast_key_f
		call	key_xunxian
		jmp	fast_key_end
fast_key1:	cjne	a,#3,fast_key2
		;setb	fast_key_f
		call	key_hand 
		jmp	fast_key_end

fast_key2:	cjne	a,#4,fast_key_end
		;setb	fast_key_f
		call	key_zhaoming
fast_key_end:	pop	acc	
		ret
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;继电器控制函数
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
kongzhi:	call	kongzhi_div
		call	panduan_baojing
		jb	baojing_f,kong_jump1	;优先级最高
		jb	shoudong_f,kong_jump1	;优先级次高		
		jb	no_kongzhi_f,kong_jump1	
		
		clr	c
		jb	jiare1_f,kongzhi2
		mov	a,zan1
kong0:		subb	a,t1l
		jc	kongzhi1
		
		jb	jiare1_f,kong2	;如果不加热,再判断湿度
		mov	a,zan2		;把湿度送给A
kong1:		clr	c 
		subb	a,h1h
		jc	kongzhi0
		jmp	kongzhi1

kong_jump1:	jmp	kongzhi_end	


kong2:		mov	a,zan2
		add	a,#10		;湿度回差是10%
		jmp	kong1

kongzhi0:	clr	led_jiare_a	;不加热	
		setb	jiare_a
		clr	jiare1_f
		jmp	kong_paifeng

kongzhi1:	setb	led_jiare_a	;加热A
		clr	jiare_a
		setb	jiare1_f
		jmp	kong_paifeng
kongzhi2:	clr	c 
		mov	a,zan1
		subb	a,#5		;温度回差是5度
		clr	c 
		jmp	kong0

kong_paifeng:	clr	c 		;排风扇的控制	
		jb	paifeng1_f,paifeng1	;排风温度回差5度
		mov	a,zan1
paifeng0:	subb	a,t1h
		jnc	kong_paifeng1
					
		clr	paifeng1_f	;不排风	
		jmp	kongzhi3	
kong_paifeng1:	setb	paifeng1_f	;排风
		jmp	kongzhi3
paifeng1:	mov	a,zan1		;回差
		add	a,#5		;温度回差是5度
		clr	c 
		jmp	paifeng0
	
;第二路温度控制判断
kongzhi3:	clr	c
		jb	jiare2_f,kongzhi2_2
		mov	a,zan3
kong2_0:	subb	a,t2l
		jc	kongzhi2_1
		
		jb	jiare2_f,kong2_2	;如果不加热,再判断湿度
		mov	a,zan4		;把湿度送给A
kong2_1:	clr	c 
		subb	a,h2h
		jc	kongzhi2_0
		jmp	kongzhi2_1

kong2_2:	mov	a,zan4
		add	a,#10		;回差是10度回差是10度
		jmp	kong2_1

kongzhi2_0:	clr	led_jiare_b	;不加热	
		setb	jiare_b
		clr	jiare2_f
		jmp	kong2_paifeng

kongzhi2_1:	setb	led_jiare_b	;加热A
		clr	jiare_b
		setb	jiare2_f
		jmp	kong2_paifeng
kongzhi2_2:	clr	c 
		mov	a,zan3
		subb	a,#5		;回差是10度回差是10度
		clr	c 
		jmp	kong2_0

kong2_paifeng:	clr	c 		;排风扇的控制	
		jb	paifeng2_f,paifeng2_1	;排风温度回差10度
		mov	a,zan3
paifeng2_0:	subb	a,t2h
		jnc	kong2_paifeng1

		clr	paifeng2_f	;不排风(A,B都不排风时)
		jb	paifeng1_f,kong2_paifeng1
		setb	paifeng
		clr	led_paifeng
		jmp	kongzhi_end
kong2_paifeng1:				;排风
		setb	paifeng2_f
		setb	led_paifeng
		clr	paifeng
		jmp	kongzhi_end
paifeng2_1:	mov	a,zan3		;回差
		add	a,#5		;回差是10度回差是10度
		clr	c 
		jmp	paifeng2_0

kongzhi_end:	call	disp
		ret

panduan_baojing:		
		clr	c 
		mov	a,zan1		;t1
		subb	a,zan3		;t2
		jc	baojing1
		mov	a,zan1		;把温度高的参入比较
		jmp	baojing2
baojing1:	mov	a,zan3
baojing2:	jb	baojing_f,baojing4	;如果报警了,有1度的回差
baojing3:	clr	c 
		subb	a,bao
		jc	baojing_no	;没有超温的情况
		setb	baojing_f	;超温报警	
		setb	led_a
		setb	led_b
		clr	led_jiare_a
		clr	led_jiare_b
		setb	led_paifeng
		clr	shoudong_f
		clr	led_shoudong

		setb	jiare_a		;关闭加热A
		setb	jiare_b		;关闭加热B 
		clr	paifeng		;打开排风
		clr	baojing		;打开报警
		jmp	baojing_end
baojing4:	inc	a		;有1度的回差
		jmp	baojing3

baojing_no:	clr	baojing_f
		setb	baojing		;关报警继电器
baojing_end:	ret


;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

;双字节变单字节t1,h1,t2,h2对应出口zan1,zan2,zan3,zan4
kongzhi_div:	clr	no_kongzhi_f
		mov	r3,#0
		mov	r4,t1h_485
		mov	r5,t1l_485
		mov	r7,#10
		call	dv31
		mov	a,r4
		jz	kongzhi_div1
kongzhi_div0:	setb	no_kongzhi_f
		jmp	kongzhi_div_end
kongzhi_div1:	mov	zan1,r5
		mov	r3,#0
		mov	r4,h1h_485
		mov	r5,h1l_485
		mov	r7,#10
		call	dv31
		mov	a,r4
		jz	kongzhi_div2
		jmp	kongzhi_div0
kongzhi_div2:	mov	zan2,r5
		mov	r3,#0
		mov	r4,t2h_485
		mov	r5,t2l_485
		mov	r7,#10
		call	dv31
		mov	a,r4
		jz	kongzhi_div3
		jmp	kongzhi_div0
kongzhi_div3:	mov	zan3,r5
		mov	r3,#0
		mov	r4,h2h_485
		mov	r5,h2l_485
		mov	r7,#10
		call	dv31
		mov	a,r4
		jz	kongzhi_div4
		jmp	kongzhi_div0
kongzhi_div4:	mov	zan4,r5
kongzhi_div_end:	ret

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;***************
;接收2个字节的测量数据
;出口:R2(高字节)zan1,R3(低字节)zan2
;****************
sht_read:	setb	data1
			call	de10us  
		clr	sck1
		call	de10us
		clr	a
		mov	r7,#08h
rc1:		setb	sck1
		call	de10us			
		mov	c,data1
		rlc	a
			call	de10us
		clr	sck1
		call	de10us
		djnz	r7,rc1

		clr	sck1
			call	de10us
		mov	r2,a
		clr	data1
		call	de10us
		setb	sck1
		call	de10us

		clr	sck1
		call	de10us
		setb	data1
		call	de10us
		clr	a
		mov	r7,#08h
rc2: 	  	setb    sck1
		call	de10us
		mov	c,data1
			call	de10us
		rlc	a
		clr	sck1
		call	de10us
		djnz	r7,rc2
		clr	sck1
		mov	r3,a
			call	de10us
		clr	data1
		call	de10us
		setb	sck1
		call	de10us
		clr	sck1
		call	de10us
		setb	data1
		call	de10us
		setb	sck1	

		mov	zan1,r2			;高字节暂存zan1
		mov	zan2,r3

			;mov	r0,#zan1
			;mov	r2,#2
			;call	rs232
		ret 
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;2路
sht2_read:	setb	data2
				call	de10us;call	de5us  
		clr	sck2
		call	de10us
		clr	a
		mov	r7,#08h
rc1_2:		setb	sck2
		call	de10us			
		mov	c,data2
		rlc	a
			call	de10us
		clr	sck2
		call	de10us
		djnz	r7,rc1_2

		clr	sck2
			call	de10us
		mov	r2,a
		clr	data2
		call	de10us
		setb	sck2
		call	de10us

		clr	sck2
		call	de10us
		setb	data2
		call	de10us
		clr	a
		mov	r7,#08h
rc2_2: 	  	setb    sck2
		call	de10us
		mov	c,data2
			call	de10us
		rlc	a
		clr	sck2
		call	de10us
		djnz	r7,rc2_2
			call	de10us
		clr	sck2
		mov	r3,a
		clr	data2
		call	de10us
		setb	sck2
		call	de10us
		clr	sck2
		call	de10us
		setb	data2
		call	de10us
		setb	sck2	

		mov	zan1,r2			;高字节暂存zan1
		mov	zan2,r3

			
			;mov	r0,#zan1
			;mov	r2,#2
			;call	rs232

		ret 
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

;实际结果都*10,目的是为了带小数点
;出口:	temp_h,temp_l(0~1600)    公式:T=d1+d2*SOt=====>0.01*t-40
temp_chuli:			
		clr     c     
        	mov     r4,zan1
        	mov     r5,zan2        				
        	mov     r6,#3eh         ;温度为120度时的测量数据值“16000=3E80H”
        	mov     r7,#80h
        	call   	nsubb            ;测量数据与最大值“16000”比较,如果超出范围,定为“16000”
        	jc     	tch1
	   	mov     zan1,r6
        	mov     zan2,r7          ;62,63 存没除以100的温度值
        	setb	t1over_f		;温度溢出

tch1:   	clr     c               ; l
	   	mov     r2,#00h
        	mov     r3,#00h
        	mov     r4,zan1
        	mov     r5,zan2
       	 	mov     r6,#00h         ;/10   也就是 data*0.1
       	 	mov     r7,#0ah
        	call   	divd           	;r2r3r4r5/r6r7=r2r3        	
        	mov	temp_h,r2
        	mov	temp_l,r3
temp_chuli_end:
		ret

        	
humi_chuli:	mov	r2,zan1
		mov	r3,zan2
		mov	r6,zan1
		mov	r7,zan2	
		call	muld		;r2r3xr6r7=r2r3r4r5,按照公式data*data
		mov	r6,#03h
		mov	r7,#0e8h	
		call	divd 		;1000=03e8h,按照公式(data*data)/1000
		mov	r6,#00h
		mov	r7,#28
		call	muld		;按照公式[(data*data)*28]/1000
		mov	r6,#03h
		mov	r7,#0e8h
		call	divd		;[(data*data)*28]/1000000
		mov	zan3,r2		;暂存
		mov	zan4,r3

		mov	r2,zan3
		mov	r3,zan4
		mov	r4,#00h
		mov	r5,#40
		call	nadd
		mov	zan3,r6
		mov	zan4,r7		;[(data*data)*28]/1000000+40

		mov	r2,zan1
		mov	r3,zan2
		mov	r6,#01h		;405=0195h
		mov	r7,#95h
		call	muld
		mov	r6,#03h
		mov	r7,#0e8h
		call	divd
		
		mov	humi_h,r2
		mov	humi_l,r3
		mov	r4,humi_h
		mov	r5,humi_l
		mov	r6,zan3
		mov	r7,zan4
		call	nsubb
		mov	humi_h,r2
		mov	humi_l,r3

;在此求出不带温度补偿的湿度:(zan1=SOrh)
;公式:RH=[(Tc-250)/100][1+(8RHo)/1000]+RH(liner)
		mov	r2,zan1
		mov	r3,zan2
		mov	r6,#0
		mov	r7,#8
		call	muld
		mov	r6,#03h		;1000=03e8
		mov	r7,#0e8h
		call	divd

		clr	c 	;+1 
		mov	a,r3 
		add	a,#1
		mov	zan2,a 
		mov	a,r2
		addc	a,#0
		mov	zan1,a 

		mov	r4,temp_h	;Tc-650
		mov	r5,temp_l
		mov	r6,#02h
		mov	r7,#8ah	;650=028ah
		call	nsubb 
		jnc	hch1
		setb	hover_f
		mov	r4,#02h
		mov	r5,#8ah
		mov	r6,temp_h
		mov	r7,temp_l 
		call	nsubb 
		
hch1:		mov	r6,zan1
		mov	r7,zan2
		call	muld
		mov	r6,#0
		mov	r7,#100
		call	divd 
		mov	zan1,r2
		mov	zan2,r3
		mov	r6,zan1
		mov	r7,zan2

		mov	r4,humi_h
		mov	r5,humi_l 
hch_end:	ret

;***************************************************************
key_scan:	setb	keyset
		setb	keyadd
		setb	keysubb
		setb	keyzhao
		clr	a		;清A
		jb	keyset,scan1
		call	de10ms
		jb	keyset,scan1
		mov	a,#01h		;只按SET,键值=1		
		jmp	key_scan_end
scan1:		jb	keyadd,scan2

⌨️ 快捷键说明

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