51单片机系列之九:A/D的应用:温度检测控制系统 一、设计任务
1、如图,单片机的P0口接上7SEG-MPX4的数据端,P2.0—P2.3接上7SEG-MPX4的位选端口,P2.4接ADC0809的CLOCK端,P2.5接0809的ALE和START端,P2.6接上0809的EOC端,P2.7接上0809的OE端口,P3.0和P3.1端口分别接上两个灯(用作温度超过警戒的指示灯),P3.7接上一个扬声器。ADC0809的IN0接上一滑动变阻器(POT-LIN),A,B,C端口都接地(用于选择IN0)。用单片机和ADC0809实现:滑动变阻器改变阻值,对应的不同的电压值输入给0809的IN0端口,0808转换后输出值给单片机显示在数码管上,单片机则判断:当温度低于30度时,发出长报警声和绿灯亮;当温度高于60度时,发出短报警声和红灯亮。测量的温度范围为0——99度。
二、电路原理图
图1——1:温度超过60度,红灯亮,扬声器报警
图1——2:温度在30——60度之间,灯不亮,扬声器不报警
图1——3:温度低于30度,绿灯亮,扬声器报警
三、设计程序
//温度检测
LED_0
EQU 30H
LED_1
EQU 31H
LED_2
EQU 32H
ADC
EQU 35H
TCNTA
EQU 36H
TCNTB
EQU 37H
H_TEMP EQU 38H
L_TEMP EQU 39H
FLAG
BIT 00H
H_ALM
BIT P3.0
L_ALM
BIT P3.1
SOUND
BIT P3.7
CLOCK
BIT P2.4
ST
BIT P2.5
EOC
BIT P2.6
OE
BIT P2.7
ORG 00H
SJMP START
ORG 0BH
LJMP INT_T0
ORG 1BH
LJMP INT_T1
START: MOV LED_0,#00H
MOV LED_1,#00H
MOV LED_2,#00H
MOV DPTR,#TABLE
MOV H_TEMP,#153
MOV L_TEMP,#77
MOV TMOD,#12H
MOV TH0,#245
MOV TL0,#0
MOV TH1,#(65536-1000)/256
MOV TL1,#(65536-1000)MOD 256
MOV IE,#8AH
CLR C
SETB TR0
WAIT:
SETB H_ALM
SETB L_ALM
CLR ST
SETB ST
CLR ST
JNB EOC,$
SETB OE
MOV ADC,P1
CLR OE
MOV A,ADC
SUBB A,L_TEMP
JC LALM
MOV A,H_TEMP
MOV R0,ADC
SUBB A,R0
JC HALM
CLR TR1
LJMP PROC
LALM:
CLR L_ALM
SETB TR1
CLR FLAG
LJMP PROC
HALM:
CLR H_ALM
SETB TR1
SETB FLAG
LJMP PROC
PROC:
MOV A,ADC
MOV B,#100
DIV AB
MOV LED_2,A
MOV A,B
MOV B,#10
DIV AB
MOV LED_1,A
MOV LED_0,B
LCALL DISP
SJMP WAIT
INT_T0:CPL CLOCK
RETI
INT_T1:MOV TH1,#(65536-1000)/256
MOV TL1,#(65536-1000)MOD 256
CPL SOUND
INC TCNTA
JB FLAG,I1
CJNE A,#30,RETUNE
SJMP I2
I1:
CJNE A,#20,RETUNE
I2:
MOV TCNTA,#0
INC TCNTB
MOV A,TCNTB
CJNE A,#25,RETUNE
MOV TCNTA,#0
MOV TCNTB,#0
LCALL DELAY2
RETUNE:RETI
DISP:
MOV A,LED_0
MOVC A,@A+DPTR
CLR P2.3
MOV P0,A
LCALL DELAY
SETB P2.3
MOV A,LED_1
MOVC A,@A+DPTR
CLR P2.2
MOV P0,A
LCALL DELAY
SETB P2.2
MOV A,LED_2
MOVC A,@A+DPTR
CLR P2.1
MOV P0,A
LCALL DELAY
SETB P2.1
RET
DELAY: MOV R6,#10
D1:
MOV R7,#250
DJNZ R7,$
DJNZ R6,D1
RET
DELAY2:MOV R5,#20
D2: MOV R6,#20
D3: MOV R7,#250
DJNZ R7,$
DJNZ R6,D3
DJNZ R5,D2
RET
TABLE: DB 3FH,06H,5BH,4FH,66H
DB 6DH,7DH,07H,7FH,6FH
END |