数字温度计实验报告
程序代码:
#include
#define uchar unsigned char
#define uint unsigned int
#define OPEN P2_7
uchar x,y;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar code p2[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
void delay2(int d)//延时函数
{
}
char init()//初始化
{
} P1_2 = 1;//18b20复位 //delay2(5); P1_2 = 0;//总线拉低 delay2(60); P1_2 = 1;//拉高总线 delay2(10); return P1_2;454 while(d--);
void write(char dat)
{
}
void write_char(unsigned char data_char)
{
}
char read()
{ char i; for(i=0;i> 1; P1_2 = 1; //delay2(5); P1_2 = 0; P1_2 = 0; P1_2 = dat; delay2(2); P1_2 = 1; delay2(1);
}
char dat; P1_2 = 1; //delay2(5); P1_2 = 0; P1_2 = 0; P1_2 = 1; d=2; while(d--); dat = P1_2; delay2(1); return dat;
char read_char()
{
unsigned char data_char = 0;
char i;
for(i=0;i> 1; if(read()) } data_char |= 0x80;//从高位开始读数
}
void config(char TH, char TL, char SPEED)//设置温度上下限
{
}
void star()
{
}
int get_temp()
{
unsigned char temp_H; unsigned char temp_L; unsigned char temp_int; init(); write_char(0xCC); write_char(0x44);//开启温度转换模式 init(); write_char(0xCC);//忽略ROM模式,直接单片机进行操作 write_char(0x4E);//发送设置温度上下限指令 write_char(TH);//设置最高温度 write_char(TL);//设置最低温度 write_char(SPEED);
init(); write_char(0xCC);
write_char(0xBE);//读取暂存器内部的9字节数据
}
void Delay(unsigned int ii)//延时函数
{
unsigned int jj;
for(;ii>0;ii--)
for(jj=0;jj
}
void show(unsigned char x,unsigned char num)
{
P0=0x00;
P2=p2[x];//选择几号数码管亮 temp_L = read_char(); temp_H = read_char(); temp_float = temp_L & 0x0F; temp_L = temp_L >> 4; temp_H = temp_H
OPEN=1;
}
P0=table[num];//给数码管送数字 OPEN=0; Delay(1);
void main()
{
while(1) { if(i==255) { star(); temp = get_temp(); N0 = temp % 10;//个位 N1 = (temp / 10) % 10;//十位 N2 = (temp / 100) % 10;//百位 i = 0; config(0x7D, 0x00, 0x7F);//设置温度上下限 int temp; unsigned char N0 = 0; unsigned char N1 = 0; unsigned char N2 = 0; unsigned char i = 0;
}
} //show(4,0); show(5,N2); show(6,N1); P0 = 0x80;//动态扫描显示小数点 Delay(1); show(7,N0); i++;
实验总结
通过这次技术测试实验,使我学习到了不少实用的知识,更重要的是做实验的过程,思考问题的方法,这与做其他实验是通用的,真正使我们受益匪浅。