北京信息科技大学
自动化学院
实验报告
课程名称智能检测与仪表
实验名称便携式温度计
专业自动化 ____
班级/学号自控1102/2011010794 学生姓名吴启婷 ____
实验日期 __________
实验地点 __________
成绩 __________
指导教师 __________
便携式仪表设计仿真图
程序:
#include <reg51.h>
#include <intrins.h>
//端口定义
sbit START = P2^0;
sbit OE = P2^1;
sbit EOC = P3^2;
sbit show_shi = P3^4;
sbit show_ge = P3^5;
typedef unsigned char BYTE;
//共阴极数码管字型码
unsigned char code tab[]=
{
0x3f, //0
0x06, //1
0x5b, //2
0x4f, //3
0x66, //4
0x6d, //5
0x7d, //6
0x07, //7
0x7f, //8
0x6f //9
};
unsigned char code tab1[]=
{ 0,1,2,3,4,5,6,7,0,8,9,10,
11,0,12,13,0,14,15,0,16,17,0,18,19,0,20,
0,21,22,0,23,0,24,0,25,0,26,0,27,0,28,29,0,30,
0,31,0,32,0,0,33,0,34,0,35,0,36,0,37,0,38,0,39,0,40, //温度表0,41,0,0,42,0,43,0,44,0,45,0,46,0,47,0,48,0,0,49,0,50
};
void delay(BYTE ms)
{ // 延时子程序
BYTE i;
while(ms--)
{
for(i = 0; i< 250; i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
void main()
{
unsigned char Val_AD=0; //用于储存AD值
unsigned char gewei;
unsigned char shiwei;
while(1)
{
START=0;
_nop_();_nop_();_nop_();
START=1;
_nop_();_nop_();_nop_();
START=0; //给START一个脉冲,启动AD转换
while(EOC==0); //等待AD转换结束
OE=1; //准备读取AD数据
Val_AD=P0; //读取P0口的值,即为AD值
Val_AD=194-Val_AD;
Val_AD=tab1[Val_AD];
gewei=Val_AD%10;
shiwei=Val_AD/10;
while(1)
{
show_shi=1;
show_ge=0; //选通个位数码管
P1=tab[gewei]; //显示个位
delay(10);
show_ge=1; //选通十位
show_shi=0;
P1=tab[shiwei];
delay(10);
}
}
}
热敏电阻分度表及经ADC0809转换后的电压数字量温度(℃)热敏电阻阻值(千欧)转换后的电压数字量
在程序中,Val_AD=194-Val_AD;这一句将各温度的电压数字量与0度的电压数字量相减,然后表中的该位置的后一位填上温度值即可。
仿真结果。