LM75A是PHILPS公司出产的数字温度传感器及看门狗。经过片内集成的带隙温度传感器和∑-△数摸转化器来完成数字温度的丈量,并经过该温度传感器为用户供给温度超限报警输出。LM75A内部包括多个数据寄存器:(1)装备寄器(Conf):用来存储器材的装备,如:器材作业形式、OS作业形式、OS极性和OS毛病行列;(2)温度寄存器(Temp):用于存储读取的数字温度;(3)设定点寄存器(Tos&Thyst):用来存储可编程的过热关断和滞后约束。器材经过2线的串行I2C总线接口与控制器通讯。LM75A包括一个开漏输出(OS),当温度超越编程约束的值时该输出有用。LM75A有3个可选的逻辑地址管脚,使得同一总线上可一起挂8个LM75A而无需其他硬件的支撑
CPU:STC89C54RD+
晶震:11.0592M
A0 A1 A2 均接地 地址设置为0 OS脚和INT0相连并经过10K上拉到VCC;当转化温度超越极限温度,输出中止蜂鸣器报警;改写数码管显现温度 共5位前一位表明正负温度后三位为温度125 – -55 最终一位为0.1度 最高可准确到0.125 数码管图略定时器100MS收集温度一次
#include
#include
#include
sbit xiaoshu=P2^0;
sbit ge=P2^1;
sbit shi=P2^3;
sbit bai=P2^4;
sbit fh=P2^5;
sbit SDA_LM75=P1^0;
sbit SCL_LM75=P1^1;
sbit BP=P2^1;
bit dp=0;
unsigned char JS=0;
#define
#define CONF
#define TEMP
#define ALARM
#define DELAY
#define WADDR
#define RADDR
unsigned int tempdata=0; //全局变量声明温度
unsigned char code tab[]={ 0x3f,0x30,0x6d,0x79,0x72,0x5b,0x5f,0x31,0x7f,0x7b,0x40};//共阴
//unsigned char tab[]={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共阳
unsigned char code tabdp[]={ 0xbf,0xb0,0xed,0xf9,0xf2,0xdb,0xdf,0xb1,0xff,0xfb,0xc0};//共阴带小数点
//unsigned char tabdp[]={ 0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10};//共阳
void delay_xms(unsigned int count) //延时函数
{
register unsigned char j;
while (count –)
{
for (j=0;j<125;j++) //约1MS
{
}
}
}
void Led_Display(unsigned int i,bit mode)
{
}
void delay(void) //延时函数
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void start_lm75(void)//开始
{
SDA_LM75=1;
SCL_LM75=1;
delay();
SDA_LM75=0;
delay();
SCL_LM75=0;
}
void stop_lm75(void)//中止
{
SDA_LM75=0;
SCL_LM75=1;
delay();
SDA_LM75=1;
delay();
SCL_LM75=0;
}
void Check_Ack(void) //查看应对信号
{
SDA_LM75=1;
SCL_LM75=1;
F0=0;
delay();
if(SDA_LM75) //假如数据为高 置位非应对标志FO
F0=1;
SCL_LM75=0;
}
void Ack(void) //发呼应信号
{
SDA_LM75=0;
delay();
SCL_LM75=1;
delay();
SCL_LM75=0;
}
void no_Ack(void) //发非呼应信号
{
SDA_LM75=1;
SCL_LM75=0;
delay();
SCL_LM75=1; //迫使数据传输完毕
delay();
}
void send_byte(unsigned char temp) //发送一字节数据
{
unsigned char i=8;
while(i–)
{
}
SCL_LM75=0;
delay();
SDA_LM75=1; //开释SDA数据线
}
unsigned char read_byte(void) //读一字节数据
{
unsigned char i=8;
unsigned char temp;
while(i–)
{
}
SCL_LM75=0;
delay();
SDA_LM75=1; //开释SDA数据线
return (temp);
}
void Write_chardata(unsigned char addr,unsigned char tempdata)//写装备寄存器
{
start_lm75();
send_byte(WADDR);
Check_Ack();
if(F0)
{
}
Ack();
send_byte(addr);
Check_Ack();
if(F0)
{
}
Ack();
send_byte(tempdata);
Check_Ack();
if(F0)
{
}
Ack();
delay();
stop_lm75();
}
void Write_intdata(unsigned char addr,unsigned int tempdata)//写16位寄存器
{
unsigned char datahigh;
unsigned char datalow;
datahigh=(unsigned char)(tempdata>>8);
datalow=(unsigned char)(tempdata&0x00FF);
start_lm75();
send_byte(WADDR);
Check_Ack();
if(F0)
{
}
Ack();
send_byte(addr);
Check_Ack();
if(F0)
{
}
Ack();
send_byte(datahigh);
send_byte(datalow);
Check_Ack();
if(F0)
{
}
Ack();
delay();
stop_lm75();
}
unsigned char read_chardata(unsigned char addr) //读8位寄存器
{
unsigned char temp;
start_lm75();
send_byte(WADDR);
Check_Ack();
if(F0)
{
}
Ack();
send_byte(addr);
Check_Ack();
if(F0)
{
}
Ack();
send_byte(RADDR);
Check_Ack();
if(F0)
{
}
Ack();
temp=read_byte();
stop_lm75();
return (temp);
}
unsigned int read_intdata(unsigned char addr) //读16位寄存器
{
unsigned char temphigh,templow;
start_lm75();
send_byte(WADDR);
Check_Ack();
if(F0)
{
}
Ack();
send_byte(addr);
Check_Ack();
if(F0)
{
}
Ack();
send_byte(RADDR);
Check_Ack();
if(F0)
{
}
Ack();
temphigh=read_byte();
templow=(read_byte())&0xe0;
stop_lm75();
if(!(temphigh&0x80))
{
return (((temphigh<<8)|templow)>>5);
}
else
{
return (0x800-((temphigh<<8)|templow)>>5);
}
}
void initial() // 初始化LM75A
{
Write_chardata(CONF,0X20); //0S中止形式,温度转化正常形式
Write_intdata(ALARM,0x3300); //100度极限 由高9位有用位组成 BIT15为1表明为负为0表明为正超越100度 触发外部中止0
Write_intdata(DELAY,0X4A80); // 95度后不报警
}
void int0_int() interrupt 0 using 1 // 外部中止0服务函数
{
BP=0;
delay_xms(1000);
BP=1;
delay_xms(1000);
}
void t0_int() interrupt 1 using 1 //定时器0中止服务函数
{
}
void main() // 进口函数
{
IP=0X01;
TMOD=0X01;
TH0=0xdc;
TL0=0xff;
IT0=0;
ET0=1;
TR0=1;
EX0=1;
EA=1;
initial();
while(1)
{
}
}