谁有msp430f5529检测频率 的DS18B20测温度的程序 跪求 重谢

msp430单片机的ds18b20测温度c程序
&msp430x16x.h&&&&&&&
DS18B20_DIR&&&&
DS18B20_IN&&&&&
DS18B20_OUT&&&&
DS18B20_DQ&&&&&
BIT3&&&&&&&
//定义DS18B20的接口&&&
DS18B20_DQ_2&&&&&&&
BIT4&&&&&&&
//定义另一个DS18B20的接口&&&
// DS18B20
ROM命令宏定义&&&
ReadRom&&&&&&&&
MatchRom&&&&&&&
SearchRom&&&&&&
AlertSearch&&&&
CopyScratchpad&&&&&
SkipRom&&&&&&&&
ReadPower&&&&&&
// DS18B20
功能命令宏定义&&&
#define ConvertTemperature&
ReadScratchpad&&&&&
WriteScratchpad&&&&
RecallE&&&&&&&&
SMCLK&&&&&&&&&&
2000&&&&&&&
//(KHz)用于系统延时&&&
温度的十进制编码(查表用)&&&
unsigned char
decimalH[16]={00,06,12,18,25,31,37,43,50,56,62,68,75,81,87,93};&&
unsigned char
decimalL[16]={00,25,50,75,00,25,50,75,00,25,50,75,00,25,50,75};&&
// 变量定义&&&
unsigned char
GetScratchpad[9];&&
unsigned char
GetScratchpad_2[9];&&
ResultTemperatureH;&&&&&&
//温度的整数部分&&&
ResultTemperatureLH;&&&&&
//温度的小数部分(高位)&&&
ResultTemperatureLL;&&&&&
//温度的小数部分(低位)&&&
ResultTemperatureH_2;&&&&
//温度的整数部分&&&
ResultTemperatureLH_2;&&&&&&&
//温度的小数部分(高位)&&&
ResultTemperatureLL_2;&&&&&&&
//温度的小数部分(低位)&&&
ResultT&&&&&&&&&&&&&&
//温度的真实值&&&
ResultTemperature_2;&&&&&&&&&&&&
//温度的真实值&&&
T&&&&&&&&&&&&&
//温度的真实值差&&&
OilP&&&&&&&&&&&&&&&&&&
//油相含率&&&
void DS18B20_WriteBit(unsigned char
oww_dat);&&
void DS18B20_WriteBit_2(unsigned char
oww_dat);&&
void DS18B20_WriteByte(unsigned char
oww_dat);&&
void DS18B20_WriteByte_2(unsigned char
oww_dat);&&
DS18B20_ReadTemp(void);&&
DS18B20_ReadTemp_2(void);&&
unsigned char
DS18B20_Init(void);&&
unsigned char
DS18B20_Init_2(void);&&
unsigned char
DS18B20_ReadBit(void);&&
unsigned char
DS18B20_ReadBit_2(void);&&
unsigned char
DS18B20_ReadByte(void);&&
unsigned char
DS18B20_ReadByte_2(void);&&
void Delay10us(void);&&
void DelayX10us(unsigned char
void main(void) {&&
&&& volatile
unsigned int i,j;&&
&&& WDTCTL =
WDTHOLD;&&&&&&
//停止看门狗&&&
&&& BCSCTL1
~XT2OFF;&&&&&&&&
//XT2 = HF
~OFIFG;&&&&&&&&
//Clear OSCFault
(i=0xFF;i&0;i--);&&&&&&&
//Time for flag to
}while((IFG1&OFIFG));&&&&&&&&&&
//OSCFault flag still
&&& BCSCTL2 |=
SELS);&&&&&
//MCLK = SMCLK =
DS18B20_Init();&&&&&&&&&&&&
//初始化DS18B20&&&
DS18B20_Init_2();&&&&&&&&&&&&&&
//初始化DS18B20.2&&&
//Z7289_Init();&&&
&&& while(1)
DS18B20_ReadTemp();&&
i=ResultTemperatureH/10;&&
j=ResultTemperatureH-(i*10);&&
//Z7289_Show(7,1,i);&&&
//Z7289_Show(6,1,j);&&&
//Z7289_Show(5,1,0x0C);&&&
i=ResultTemperatureLH/10;&&
j=ResultTemperatureLH-(i*10);&&
//Z7289_Show(4,1,i);&&&
//Z7289_Show(3,1,j);&&&
i=ResultTemperatureLL/10;&&
j=ResultTemperatureLL-(i*10);&&
//Z7289_Show(2,1,i);&&&
//Z7289_Show(1,1,j);&&&
&&&&&&&&&&&&&&&
ResultTemperature=ResultTemperatureH+ResultTemperatureLH/100+ResultTemperatureLL/10000;&&
&&&&&&&&&&&&&&&
ResultTemperature_2=ResultTemperatureH_2+ResultTemperatureLH_2/100+ResultTemperatureLL_2/10000;&&
&&&&&&&&&&&&&&&
Temperaturefromtwo=ResultTemperature_2-ResultT&&
&&&&&&&&&&&&&&&
OilPercentage=1.0/T&&
&&&&&&&&&&&
功能函数定义&&&
unsigned char
DS18B20_Init(void){&&
& unsigned char
& DS18B20_DIR |=
DS18B20_DQ;&&&&&&
& DS18B20_OUT &=
~DS18B20_DQ;&&&&&
DS18B20_DQ=0;&&&
DelayX10us(48);&&&&&&
// Bus master pulling low 480us
& DS18B20_OUT |=
DS18B20_DQ;&&&&&&
DS18B20_DQ=1;&&&
DelayX10us(6);&&&&&&&
// Resister pull up
& DS18B20_DIR &=
~DS18B20_DQ;&&&&&
& result = DS18B20_IN &
DS18B20_DQ;&&
& DS18B20_DIR |=
DS18B20_DQ;&&&&&&
DelayX10us(48);&&&&&&
// End of timeslot total
return(result);&&&&&&
// any 1 wire device ?result:=1 ?result:=0 have
}//Intialization the 1-wire
unsigned char
DS18B20_Init_2(void){&&
& unsigned char
& DS18B20_DIR |=
DS18B20_DQ_2;&&&&&&
& DS18B20_OUT &=
~DS18B20_DQ_2;&&&&&
DS18B20_DQ=0;&&&
DelayX10us(48);&&&&&&
// Bus master pulling low 480us
& DS18B20_OUT |=
DS18B20_DQ_2;&&&&&&
DS18B20_DQ=1;&&&
DelayX10us(6);&&&&&&&
// Resister pull up
& DS18B20_DIR &=
~DS18B20_DQ_2;&&&&&
& result = DS18B20_IN &
DS18B20_DQ_2;&&
& DS18B20_DIR |=
DS18B20_DQ_2;&&&&&&
DelayX10us(48);&&&&&&
// End of timeslot total
return(result);&&&&&&
// any 1 wire device ?result:=1 ?result:=0 have
}//Intialization the 1-wire
unsigned char
DS18B20_ReadBit(void){&&
& unsigned char
& DS18B20_DIR |=
DS18B20_DQ;&&&&&&
& DS18B20_OUT &=
~DS18B20_DQ;&&&&&
DS18B20_DQ=0;&&&
_NOP();&&&&&&&&&&&&&&
// Start of
& DS18B20_OUT |=
DS18B20_DQ;&&&&&&
DS18B20_DQ=1;&&&
_NOP();_NOP();_NOP();_NOP();&&
&&&&&&&&&&&&&&&
// Wait from the
& DS18B20_DIR &=
~DS18B20_DQ;&&&&&
& result = DS18B20_IN &
DS18B20_DQ;&&
& DS18B20_DIR |=
DS18B20_DQ;&&&&&&
return(result);&&&&&&
// return the result of the 1-wire
}//Read a bit on the 1-wire
unsigned char
DS18B20_ReadBit_2(void){&&
& unsigned char
& DS18B20_DIR |=
DS18B20_DQ_2;&&&&&&
& DS18B20_OUT &=
~DS18B20_DQ_2;&&&&&
DS18B20_DQ=0;&&&
_NOP();&&&&&&&&&&&&&&
// Start of
& DS18B20_OUT |=
DS18B20_DQ_2;&&&&&&
DS18B20_DQ=1;&&&
_NOP();_NOP();_NOP();_NOP();&&
&&&&&&&&&&&&&&&
// Wait from the
& DS18B20_DIR &=
~DS18B20_DQ_2;&&&&&
& result = DS18B20_IN &
DS18B20_DQ_2;&&
& DS18B20_DIR |=
DS18B20_DQ_2;&&&&&&
return(result);&&&&&&
// return the result of the 1-wire
}//Read a bit on the 1-wire
void DS18B20_WriteBit(unsigned char
oww_dat){&&
& DS18B20_DIR |=
DS18B20_DQ;&&&&&&
& DS18B20_OUT &=
~DS18B20_DQ;&&&&&
DS18B20_DQ=0;&&&
& if (1 ==
oww_dat)&&&
&&& DS18B20_OUT
DS18B20_DQ;&&&&
DS18B20_DQ=1;&&&
DelayX10us(10);&&&&&&
// Remain the state for
& DS18B20_OUT |=
DS18B20_DQ;&&&&&&
DS18B20_DQ=1;&&&
}//Write a bit to the 1-wire
void DS18B20_WriteBit_2(unsigned char
oww_dat){&&
& DS18B20_DIR |=
DS18B20_DQ_2;&&&&&&
& DS18B20_OUT &=
~DS18B20_DQ_2;&&&&&
DS18B20_DQ=0;&&&
& if (1 ==
oww_dat)&&&
&&& DS18B20_OUT
DS18B20_DQ_2;&&&&
DS18B20_DQ=1;&&&
DelayX10us(10);&&&&&&
// Remain the state for
& DS18B20_OUT |=
DS18B20_DQ_2;&&&&&&
DS18B20_DQ=1;&&&
}//Write a bit to the 1-wire
unsigned char
DS18B20_ReadByte(void){&&
& unsigned char
& unsigned char
result=0;&&
& for(i = 0; i& 8;
if(DS18B20_ReadBit())&&
result |= 0x01 &
DelayX10us(12);&&&&
return(result);&&&&&&
// return the result of the 1-wire
}//Read a byte from the 1-wire
unsigned char
DS18B20_ReadByte_2(void){&&
& unsigned char
& unsigned char
result=0;&&
& for(i = 0; i& 8;
if(DS18B20_ReadBit_2())&&
result |= 0x01 &
DelayX10us(12);&&&&
return(result);&&&&&&
// return the result of the 1-wire
}//Read a byte from the 1-wire
void DS18B20_WriteByte(unsigned char
oww_dat){&&
& unsigned char
& for(i = 0; i& 8;
&&& temp =
oww_dat &&
&= 0x01;&&
DS18B20_WriteBit(temp);&&
DelayX10us(7);&&&&&&&
}//Write a byte to the 1-wire
void DS18B20_WriteByte_2(unsigned char
oww_dat){&&
& unsigned char
& for(i = 0; i& 8;
&&& temp =
oww_dat &&
&= 0x01;&&
DS18B20_WriteBit_2(temp);&&
DelayX10us(7);&&&&&&&
}//Write a byte to the 1-wire
DS18B20_ReadTemp(void)&&
{&& unsigned char
tempH,tempL,tempH_2,tempL_2;&&
DS18B20_Init();&&
DS18B20_Init_2();&&
DS18B20_WriteByte(SkipRom);&&
DS18B20_WriteByte_2(SkipRom);&&
//There is just one DS1820 on the
DS18B20_WriteByte(ConvertTemperature);&&
DelayX10us(10);&&
DS18B20_WriteByte_2(ConvertTemperature);&&
DelayX10us(10);&&
//Start to convert
DS18B20_Init();&&
DS18B20_Init_2();&&
DS18B20_WriteByte(SkipRom);&&
DS18B20_WriteByte_2(SkipRom);&&
DS18B20_WriteByte(ReadScratchpad);&&
DS18B20_WriteByte_2(ReadScratchpad);&&
GetScratchpad[0]=DS18B20_ReadByte();&&
//Master samples the LSB temperature from the
GetScratchpad[1]=DS18B20_ReadByte();&&
//Master samples the MSB temperature from the
GetScratchpad[2]=DS18B20_ReadByte();&&
//Master samples the Th register or userbyte1 from the
GetScratchpad[3]=DS18B20_ReadByte();&&
//Master samples the Tl register or userbyte0 from the
GetScratchpad[4]=DS18B20_ReadByte();&&
//Master samples the configuration register from the
GetScratchpad[5]=DS18B20_ReadByte();&&
//Master samples the reservedbyte from the
GetScratchpad[6]=DS18B20_ReadByte();&&
//Master samples the reservedbyte from the
GetScratchpad[7]=DS18B20_ReadByte();&&
//Master samples the reservedbyte from the
GetScratchpad[8]=DS18B20_ReadByte();&&
//Master samples the CRC from the
tempH=(GetScratchpad[1] & 4) | (GetScratchpad[0]
tempL=(GetScratchpad[0] &
DS18B20_Init();&&
&&&&&&&&&&
GetScratchpad_2[0]=DS18B20_ReadByte_2();&&
//Master samples the LSB temperature from the
GetScratchpad_2[1]=DS18B20_ReadByte_2();&&
//Master samples the MSB temperature from the
GetScratchpad_2[2]=DS18B20_ReadByte_2();&&
//Master samples the Th register or userbyte1 from the
GetScratchpad_2[3]=DS18B20_ReadByte_2();&&
//Master samples the Tl register or userbyte0 from the
GetScratchpad_2[4]=DS18B20_ReadByte_2();&&
//Master samples the configuration register from the
GetScratchpad_2[5]=DS18B20_ReadByte_2();&&
//Master samples the reservedbyte from the
GetScratchpad_2[6]=DS18B20_ReadByte_2();&&
//Master samples the reservedbyte from the
GetScratchpad_2[7]=DS18B20_ReadByte_2();&&
//Master samples the reservedbyte from the
GetScratchpad_2[8]=DS18B20_ReadByte_2();&&
//Master samples the CRC from the
tempH_2=(GetScratchpad_2[1] & 4) |
(GetScratchpad_2[0] &&
tempL_2=(GetScratchpad_2[0] &
DS18B20_Init_2();&&
//Issue a reset to terminate left
&&& //if(tempH
tempH=~tempH;&&&
tempL=~tempL+1;&&&
ResultSignal=1;&&&
//& //Negative
ResultTemperatureH=tempH;&&
ResultTemperatureLL=decimalL[tempL];&&
ResultTemperatureLH=decimalH[tempL];&&
&&&&&&&&&&
ResultTemperatureH_2=tempH_2;&&
ResultTemperatureLL_2=decimalL[tempL_2];&&
ResultTemperatureLH_2=decimalH[tempL_2];&&
//Result of
}//Read the byte0 and byte1 from
void Delay10us(void){&&
& unsigned char
& for (i=0; i&(SMCLK/500-3);
//& Time is accurately
void DelayX10us(unsigned char
& unsigned int
& for (i=0; i&x10
msp430单片机:
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。我现在就点过一个灯,处于入门阶段,各位有经验的能帮帮我么?,
在线时间1116 小时
威望11154分
芯币19347枚
TA的帖子TA的资源
很简单,慢慢来就可以了、430读18B20的程序有很多,控制LCD的程序也有很多,先找一个慢慢练就行了。
在线时间567 小时
威望1895分
芯币1987枚
TA的帖子TA的资源
纯净的硅(高级), 积分 1895, 距离下一级还需 105 积分
纯净的硅(高级), 积分 1895, 距离下一级还需 105 积分
就楼主目前的水平,建议不能一口吃成一个胖子,学习需要渐近,比如:
3.LED的PWM调光
4.点亮数码管或电子钟
5.1602液晶
6.12864液晶
7.段式LCD屏
8.蜂鸣器和步进电机
10.串口通信,I2C通信,SPI等
11.ADC模数转换电压,电流检测显示
基本大概就是这些,DS18B20驱动有固定的写法,网上很多例程大同小异,如果非要一上来就温度检测LCD显示估计有点吃力……
在线时间31 小时
TA的帖子TA的资源
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
就楼主目前的水平,建议不能一口吃成一个胖子,学习需要渐近,比如:
3.LED的PWM调 ...
如果现在急着做DS18B20的温度显示,其实百度一下有很多关于DS18B20的例程,还有楼主是准备用什么LCD&
在线时间31 小时
TA的帖子TA的资源
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
很简单,慢慢来就可以了、430读18B20的程序有很多,控制LCD的程序也有很多,先找一个慢慢练就行了。
去哪里找呀
在线时间567 小时
威望1895分
芯币1987枚
TA的帖子TA的资源
纯净的硅(高级), 积分 1895, 距离下一级还需 105 积分
纯净的硅(高级), 积分 1895, 距离下一级还需 105 积分
如果现在急着做DS18B20的温度显示,其实百度一下有很多关于DS18B20的例程,还有楼主是准备用什么LCD
在线时间31 小时
TA的帖子TA的资源
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
如果现在急着做DS18B20的温度显示,其实百度一下有很多关于DS18B20的例程,还有楼主是准备用什么LCD
在线时间31 小时
TA的帖子TA的资源
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
如果现在急着做DS18B20的温度显示,其实百度一下有很多关于DS18B20的例程,还有楼主是准备用什么LCD
是很着急的
在线时间963 小时
威望1660分
TA的帖子TA的资源
上逻辑分析仪别敲我。。。
最简单的办法就是用逻辑分析仪读取管脚时序,并修改程序进行调整。等到它与DS18B20的Datasheet时序一致之后,你就成功了。至少读18B20成功了。
1602也是一样,如果你的逻辑分析仪通道数足够,可以全读,如果通道数不够,可以抽几个数据位读,看是否与程序描述的时序一致。又是否与1602液晶模块要求的时序一致。
在线时间9 小时
TA的帖子TA的资源
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
就楼主目前的水平,建议不能一口吃成一个胖子,学习需要渐近,比如:
3.LED的PWM调 ...
能给个430F5529 的I2C跟 类似adc1115诸如adc或者eeprom的通信吗?
在线时间9 小时
TA的帖子TA的资源
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
一粒金砂(中级), 积分 6, 距离下一级还需 194 积分
能给个430F5529 的I2C跟 类似adc1115诸如adc或者eeprom的通信吗?
求点例程,百度到的都没有f5529的。。。。 自己调了好久也没调出来&&io模拟的也是
EEWORLD 官方微信
Powered byMSP430F149例程-资料共享-电子开发网资料共享
&nbsp&nbsp
当前位置: &&
MSP430F149例程
MSP430F149例程
资料格式:&&zip
作者/开发商:&&
资料大小:&&737.33 KB
资料语言:&&简体中文
资料平台:&&Windows
软件类别:&&源码
相关地址:&&
评分等级:&&★★★★★
发布人:&&&
下载次数:&&1813
MSP430F149 GSM基本控制,初始化接收短息,解读短信MSP430F149+1602数码显示和实时时钟MSP430F149+DS1302+UART程序可以用MSP430F149,IAR,ADC采样之后对太阳点光源进行跟踪MSP430F149--485串行通信MSP430F149-SHT15传感器例程(,随时调用,含注释) (1)MSP430F149-SHT15传感器例程(,随时调用,含注释)MSP430F149单片机定时器A的PWM输出程序MSP430F149单片机对1602液晶进行的简单测试MSP430F149单片机对1604液晶进行的简单操作MSP430F149单片机对PS2键盘的控制程序和源码MSP430F149单片机对继电器的控制程序和源码MSP430F149单片机控制LED全彩显示屏的某一行列数据传输控制显示程序MSP430F149单片机模拟IIC和DS18B20通信进行测试温度代码MSP430F149单片机的Flash程序MSP430F149的无线模块24L01程序MSP43F149的USB测试程序
&(需要下载点0点)()

我要回帖

更多关于 msp430f5529 的文章

 

随机推荐