#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define delayNOP() {_nop_();_nop_();_nop_();_nop_();}
sbit HI_LED=P2^3; //高温,低温白净闪烁 LED
sbit LO_LED=P2^6;
sbit DQ=P3^3; //DS18B20数据线
sbit BEEP=P3^7; //报警
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
sbit K1=P1^7; //正常显示温度,越界时报警
sbit K2=P1^4; //显示报警温度
sbit K3=P1^1; //查看 ROM CODE
uchar code RomCodeStr[]={"-- ROM CODE --"};
uchar RomCode[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //64位ROM CODE
uchar code Temp_Disp_Title[] ={"Current Temp: "};
uchar Current_Temp_Display_Buffer[]={"TEMPE: "};
uchar code Temperature_Char[8]={0x0c,0x12,0x12,0x0c,0x00,0x00,0x00,0x00}; //温度示字符
uchar code Alarm_Temp[]={"ALARM TEMP Hi Lo"};
uchar Alarm_HI_LO_STR[]={"Hi: Lo: "};
uchar temp_data[2]={0x00,0x00};
uchar temp_alarm[2]={0x00,0x00};
uchar display[5]={0x00,0x00,0x00,0x00,0x00,}; //温度值
uchar display1[3]={0x00,0x00,0x00}; //温度报警值
uchar code df_Table[]={0,1,1,2,3,3,4,4,5,6,6,7,8,8,9,9}; //温度小数位对照表
//.......................................................
99宿舍六级查询
//报警温度上下限(取值范围:-128~+127)(DS18B20温度范围为:-55~+125)
//数组中前一位为高温值,后一位为低温值
//此处类型注意设为char,否则不能进行有符号数的比较
char Alarm_Temp_HL[2]={70,-20};
//............................................................
至于英文uchar CurrentT=0; //当前读取温度整数部分
uchar Temp_Value[]={0x00,0x00};//从DS18B20读取的温度值
uchar Display_Digit[]={0,0,0,0};//待显示的各温度数位
bit HI_Alarm=0,LO_Alarm=0; //高低温报警标志
bit DS18B20_IS_OK=1; //传感器正常标志
uint Time0_Count=0; //定时器延时累加
//...........................
//延时
//...........................
void DelayXus(int x)
{
uchar i;
while(x--)for(i=0;i<200;i++);
}
//.......................................
//忙检测
bit LCD_Busy_Check()
{
bit LCD_Status;
RS=0;//寄存器选择
RW=1;//读状态寄存器EN=1;//开始读
DelayXus(1);
LCD_Status=(bit)(P0&0x80) ;
EN=0;
return LCD_Status;
}
//写LCD指令
void Write_LCD_Command(uchar cmd)
{
while((LCD_Busy_Check()&0x80)==0x80); //忙等待
RS=0; //写选择命令寄存器
RW=0; //写
EN=0;
P0=cmd; EN=1; DelayXus(1); EN=0;
}
//向LCD写数据
void Write_LCD_Data(uchar dat)
perfectgirls{
while((LCD_Busy_Check()&0x80)==0x80); //忙等待
RS=1;RW=0;EN=0;P0=dat;EN=1; DelayXus(1); EN=0;
专业美容培训}
//设置液晶显示位置
void Set_LCD_POS(uchar pos)
{
十日拍拖手册
Write_LCD_Command(pos |0x80);
}
//LCD初始化
void LCD_Initiali()
{
Write_LCD_Command(0x38);
DelayXus(1);
Write_LCD_Command(0x01); //清屏
DelayXus(1);
Write_LCD_Command(0x06); //字符进入模式:屏幕不动,字符后移
DelayXus(1);
Write_LCD_Command(0x0C); //显示开,关光标
DelayXus(1);
}
//...............................................
//..........................................
//自定义字符写CGRAM
//..................................
void Write_NEW_LCD_Char()yso
{
uchar i;
Write_LCD_Command(0x40); //写CGRAM
for(i=0;i<8;i++)
Write_LCD_Data(Temperature_Char[i]); //写入温度符号
}
//............................................
diapers
//延时
//........................................................
void Delay(uint num)
通信线路工程{
while(--num);
}
//...............................................
//初始化DS18B20
//...............................................
uchar Init_DS18B20()
{
uchar status;
DQ=1;Delay(8);
DQ=0;Delay(90);
DQ=1;Delay(8);
status=DQ;
Delay(100);
DQ=1;
return status; //初始化成功时返回0
}
//...............................................
//读一节
//...............................................
uchar ReadOneByte()
{
uchar i,dat=0;
DQ=1;_nop_();
男生什么发型好看 for(i=0;i<8;i++)
{
DQ=0;dat>>=1;DQ=1;_nop_(); _nop_();
if(DQ) dat |=0x80;Delay(30);DQ=1;
}
return dat;
}
//...............................................
//写一字节
//...............................................
void WriteOneByte(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
DQ=0;DQ=dat&0x01;Delay(5);DQ=1;dat>>=1;
}
}
//...............................................
//读取温度值
//...............................................
void Read_Temperature()
{
if(Init_DS18B20()==1) //DS18B20故障
DS18B20_IS_OK=0;
el
{
WriteOneByte(0xCC); //跳过序列号
WriteOneByte(0x44); //启动温度转换
expands Init_DS18B20();
WriteOneByte(0xCC); //跳过序列号