温度传感器选择
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一、温度传感器选择
由于采用NTC热敏电阻与温度的关系是非线性的,用电桥实现温度升高引起的电阻变化对应于电压变化,因此输出的结果测试精度较低,并且不能达到我们对温度控制的要求。
温度传感器AD590是一种电压输入、电流输出型集成温度传感器,测温范围为-55℃
~150℃,精度高,非线性误差仅为±0.3℃,调节系数为1微安每K,输出电流I=(273+T)微安。
温度传感器LM1335,V0=10毫伏每摄氏度,具有很高的工作精度与线性工作范围。
器件输出电压与温度成线性关系,调节系数为10毫伏每摄氏度,因而优越之处在于无需外部校准微调,可以供±1\4℃常用室温精度。
二、转换电路
将采集到的电信号转换为0~5V之间,使之可以直接加到ADC0809端口。
三、采样值量化
算法:比例系数KT=0.0278V|℃=27.8MV
0摄氏度时,电压为0+55*0.0278=1.529V,每个数字量对应电压值19.53MV,用KS表示得到数字量与温度的关系。
KT|KS=1.426数字量每摄氏度
0摄氏度对用AD输出量D0=55*1.426=78.43≈79
=01001111B
四、ADC0809
五、基本功能是用三个按键来控制风速、类型以及停止这三个状态的变换。
当风速键按下时实现风速强、中、弱三种状态依次循环切换,并用三个LED 指示灯来显示;当类型键按下时实现类型正常、睡眠、自然三种状态的依次循环切换,并用三个LED 指示灯来显示。
题目中类型键要求自然状态转2 秒,停4 秒;睡眠状态转2 秒,停转6 秒,这个涉及到时间问题,可以通过硬件或者软件来实现,选择通过软件来实现。
控制系统分四个功能模块,主要包含风速设置、类型设置、默认状态显示和退出系统。
1、风速设置
这个模块中风速的三个状态强、中、弱之间的循环切换是通过将端口A的键值逐次加1(初始值为0, 每按下一次风速键寄存器值加1),然后对3求余,取其余数分别代表这三个状态来实现的。
由于对3求余的余数只有0、1、2 三个值,分别代表强、中、弱,将其余数保存到寄存器中,根据寄存器中是0、1、2 来判断强、中、弱风三个状态。
2、类型设置
风的类型有:正常、自然、睡眠三种。
a) 正常电扇连续运转。
b) 自然电扇模拟自然风,即转2s,停4s。
c) 睡眠电扇慢转,产生轻柔的微风,运转2s,停转6s。
自然状态和睡眠状态时间的控制是通过调用延时子程序来实现的,由于一个机器周期是10 -6 秒,延时程序是通过循环来实现的,让指令执行106 次来实现1 秒。
不是很精确。
MY8255_A EQU 0FF00H ;8255A
MY8255_B EQU 0FF01H ;8255B
MY8255_C EQU 0FF02H ;8255C
MY8255_MODE EQU 0FF03H ;8255
STACK1 SEGMENT
STACK
DW 256 DUP(?)
STACK1 ENDS
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:
MOV DX,MY8255_MODE
MOV AL,90H
OUT DX,AL
MOV DX,MY8255_C
MOV AL,00H
OUT DX,AL
MOV DX,MY8255_B
MOV AL,0FFH
OUT DX,AL
START1:
MOV DX,MY8255_A //对8255A口进行扫描
IN AL,DX
AND AL,00001000B
CMP AL,08H //对按键进行判断
JNZ T1
CALL ZIRAN //调用自然模式
T1: MOV DX,MY8255_A
IN AL,DX
AND AL,00000111B //屏蔽按键
CMP AL,00H
JNZ T10
CALL STOP
T10: CMP AL,01H
JNZ T6
CALL QIANG
T6: CMP AL,02H
JNZ T8 //AL非02H跳入T8
CALL ZHONG
T8: CMP AL,04H
JNZ T9
CALL RUO
T9: JMP START1
//自然模式
ZIRAN PROC NEAR
MOV DX,MY8255_B //对8255B口进行初始化MOV AL,0F7H
OUT DX,AL
MOV CX,40 //循环次数进行控制
T: MOV [DI],1770H
CALL ZHENGZHUAN
LOOP T
CALL DL4S
RET
ENDP
//强风模式
QIANG PROC NEAR
MOV DX,MY8255_B //对8255B口进行初始化MOV AL,0FEH
OUT DX,AL
MOV [DI],0A00H
MOV DX,MY8255_A //扫描8255A口
IN AL,DX
AND AL,00010000B
CMP AL,10H //对按键进行判断
JNZ T2
CALL FANZHUAN
CMP AL,01H
JZ T3
T2: CALL
ZHENGZHUAN
T3: RET ENDP
//中风模式
ZHONG PROC NEAR
MOV DX,MY8255_B //对8255B口进行初始化
MOV AL,0FDH
OUT DX,AL
MOV [DI],1000H
MOV DX,MY8255_A //扫描8255A口
IN AL,DX
AND AL,00010000B
CMP AL,10H //对按键进行判断
JNZ T4
T4: CALL FANZHUAN
CMP AL,10H
JNZ T5
CALL ZHENGZHUAN
T5: RET
ENDP
//停止模式
STOP PROC NEAR
MOV DX,MY8255_B //对8255B口进行初始
MOV AL,0FFH
OUT DX,AL
MOV DX,MY8255_C //对8255C口进行初始化
MOV AL,00H
OUT DX,AL
CALL DL500ms //调用延时
RET
ENDP
//弱风模式
RUO PROC NEAR
MOV DX,MY8255_B //对8255B口进行初始MOV AL,0FBH OUT DX,AL
MOV [DI],1B00H
MOV DX,MY8255_A //扫描8255A
IN AL,DX
AND AL,00010000B
CMP AL,10H //对按键进行判断
JNZ A1
CALL FANZHUAN
A1: CMP AL,10H
JNZ A2
CALL ZHENGZHUAN
A2: RET
ENDP
//反转模式
FANZHUAN PROC NEAR
MOV DX,MY8255_A //扫描8255A
IN AL,DX
NOT AL
MOV DX,MY8255_B
OUT DX,AL
MOV DX,MY8255_C
MOV AL,09H //设置风扇的旋转方式
OUT DX,AL CALL DELAY MOV AL,0CH OUT DX,AL CALL DELAY
MOV AL,06H
OUT DX,AL
CALL DELAY
MOV AL,03H
OUT DX,AL
CALL DELAY
RET
ENDP
//正转模式
ZHENGZHUAN PROC NEAR
PUSH DX
MOV DX,MY8255_C //对8255C口进行初始化
MOV AL,03H
OUT DX,AL
CALL DELAY
MOV AL,06H //设置风扇的旋转方式
OUT DX,AL
CALL DELAY
MOV AL,0CH
OUT DX,AL
CALL DELAY
MOV AL,09H
OUT DX,AL
CALL DELAY
POP DX
RET
ENDP
//延时程序设置
DELAY PROC NEAR PUSH CX
MOV CX,[DI]
DATE: LOOP DATE
POP CX
RET
ENDP
DL500ms PROC NEAR PUSH CX
MOV CX,60000
DL500ms1: LOOP DL500ms1 POP CX
RET
DL500ms
ENDP
DL4S PROC NEAR
PUSH CX
MOV CX,8
DL4S1: CALL DL500ms LOOP DL4S1
POP CX
RET
ENDP
CODE ENDS
END START
data segment
isend db 0
n0 db 0
n1 db 0
n2 db 0
isright db 1
keykind db 0
oldkey db 0
kind db 0
isstop db 0
flags db 0
numbers db 3fh,6,5bh,0,0,0,0,0,0,0
data ends
code segment
assume cs:code,ds:data
main:;主程序cli
mov ax,cs
mov ds,ax
mov kind,0
mov isright,1
mov keykind,0ah
mov oldkey,0ah
mov kind,0
mov isstop,0
mov flags,0
mov isend,0
mov n0,0
mov n1,0
mov n2,0
call initnumbers
call init8255
call init8259
call init8253
call modifyint
mov dx,212h
mov al,0
out dx,al
call cleardevice
call display
mov al,0
mov dx,22ah
out dx,al
mov al,30h
out dx,al
mov al,7fh
sti
dowhat:
push ax
dowait:
mov al,0ffh;单色灯清零mov dx,211h
out dx,al
mov dx,210h
in al,dx
test al,1;判断开关
jz dowait
pop ax
call readakey
cmp keykind,0ah
jnz a1
mov kind,2
call gotonext
jmp aa
a1:;判断风速改变cmp keykind,0bh
jnz a2
mov kind,1
call gotonext
jmp aa
a2:
cmp keykind,0ch
jnz a3
mov kind,0
call gotonext
jmp aa
a3:
cmp keykind,0dh
jnz a4
push ax
mov dx,212h
mov al,0
out dx,al
pop ax
mov isstop,0
push ax
mov al,oldkey
mov keykind,al
call reading
mov dx,212h
mov al,0ffh
out dx,al
pop ax
sti
jmp aa
a4:
cmp keykind,0eh
jnz aa
not flags
push ax
mov al,oldkey
mov keykind,al
pop ax
aa:
jmp dowhat
gotonext:;单色灯循环亮灭mov dx,211h
out dx,al
cmp flags,0
jnz noror
ror al,1
noror:
cmp al,0feh
jnz continue
jmp continue
continue:
cmp kind,2
jnz mm1
call speed2
jmp mm3
mm1:;改变风速
cmp kind,1
jnz mm2
call speed1
jmp mm3
mm2:
cmp kind,0
jnz mm3
call speed0
mm3:
push ax
mm33:
cmp isstop,0
jz mm4
mov dx,211h
mov al,0ffh
out dx,al
mov dx,210h
in al,dx
test al,1
jnz mm33
mov isstop,0
cli
mm4:
pop ax
ret
readakey:;读取键盘输入push ax
mov al,keykind
mov oldkey,al
mov dx,22ah
in al,dx
and al,0fh
cmp al,0
jz gotoexit
mov al,40h
mov dx,22ah
out dx,al
mov dx,228h
in al,dx
mov keykind,al
gotoexit:
pop ax
ret
speed1:;速度设置push cx
mov cx,18000
sp1:
loop sp1
pop cx
ret
speed2:
push cx
mov cx,50000
sp2:
loop sp2
pop cx
ret
speed0:
push cx
mov cx,8000
sp0:
loop sp0
pop cx
ret
readisd:
key:
mov dx,22ah
in al,dx
and al,0fh
cmp al,0
jz key
mov al,40h
out dx,al
mov dx,228h
in al,dx
cmp al,0dh
jnz key
ret
reading:;输入时间push ax
mov n0,0
mov n1,0
mov n2,0
call readanumber
mov n0,al
call display
call readanumber
cmp al,0dh
jz readexit
mov ah,n0
mov n0,al
mov n1,ah
call display
call readanumber
cmp al,0dh
jz readexit
mov ah,n0
mov n0,al
mov al,n1
mov n1,ah
mov n2,al
call display
call readisd
readexit:
pop ax
ret
readanumber:
key2:
mov dx,22ah
in al,dx
and al,0fh
cmp al,0
jz key2
mov al,40h
out dx,al
mov dx,228h
in al,dx
ret
initnumbers:
push bx
mov bx,offset numbers
mov byte ptr[bx],3fh
mov byte ptr[bx+1],6
mov byte ptr[bx+2],5bh
mov byte ptr[bx+3],4fh
mov byte ptr[bx+4],66h
mov byte ptr[bx+5],6dh
mov byte ptr[bx+6],7dh
mov byte ptr[bx+7],7
mov byte ptr[bx+8],7fh
mov byte ptr[bx+9],6fh
pop bx
ret
display:;时间显示call cleardevice
mov bx,offset numbers
mov al,80h
mov dx,22ah
out dx,al
mov al,n0
xor ah,ah
add bx,ax
mov al,[bx]
mov dx,228h
out dx,al
mov bx,offset numbers mov al,81h
mov dx,22ah
out dx,al
mov dx,228h
mov al,n1
xor ah,ah
add bx,ax
mov al,[bx]
out dx,al
mov bx,offset numbers mov al,82h
mov dx,22ah
out dx,al
mov dx,228h
mov al,n2
xor ah,ah
add bx,ax
mov al,[bx]
out dx,al
ret
intcount:
push ax
push bx
push dx
cmp n0,0
jz next1
dec n0
jmp next4
next1:
mov n0,9
cmp n1,0
jz next2
dec n1
jmp next4
next2:
mov n1,9
cmp n2,0
jz next3
dec n2
jmp next4
next3:
mov n2,9
next4:
cmp n0,0
jnz next5
cmp n1,0
jnz next5
cmp n2,0
jnz next5
mov isstop,1
mov dx,212h
mov al,0
out dx,al
next5:
call display
pop dx
pop bx
pop ax
iret
init8255:
mov al,90h
mov dx,213h
out dx,al
ret
init8259:
mov al,13h
mov dx,220h
out dx,al
mov dx,221h
mov al,30h
out dx,al
mov al,3
out dx,al
mov al,0feh
out dx,al
ret
modifyint:
push ds
push bx
push ax
xor ax,ax
mov ds,ax
mov bx,30h*4
mov ax,offset intcount mov [bx],ax
mov ax,8100h mov [bx+2],ax pop ax
pop bx
pop ds
ret
init8253:
push ax
mov al,35h mov dx,203h out dx,al mov ax,0ffffh mov dx,200h out dx,al mov al,ah out dx,al mov al,75h mov dx,203h out dx,al mov ax,27 mov dx,201h out dx,al mov al,ah out dx,al
pop ax
ret cleardevice: push ax push dx
mov al,0c1h mov dx,22ah out dx,al wait1:
mov dx,22ah in al,dx
test al,80h jnz wait1 pop dx
pop ax
ret
code ends
end main。