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();
}
LM75A数字温度 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)