6.22 温度传感器LM95071的使用
2007-06-22 07:58
281 查看
通过两天的时间,终于通过串口通讯,可以读取温度传感器的值了
注意点:
1,读取的顺序
其他的好像就没什么了,还有就是焊接,要小心,以免损坏吧。
给上程序:
/**//*
************************************************************************
* 関数 : short temp_in( char sel ) ; 33751-V217-XXXX *
* -------------------------------------------------------------------- */
/**//* 名称 : 温度制御処理 */
/**//* 機能 : 温度制御処理 */
/**//* 説明 : 温度センサーの入出力を制御する。 */
/**//* : CS,SC,SI/O信号により温度を制御する。 */
/**//* : 温度とセンサー ID データ取得処理 */
/**//* 引数 : char (0~1まで使用) */
/**//* 戻り値 : short( この値が温度とセンサー ID データ値) */
/**//* : 1: ID データ値 */
/**//* : 0: 温度データ値 */
/**//* 使用関数: set_imask_ccr(unsigned char); 割込み 0:禁止解除1:禁止*/
/**//* : void port_cnt( char ,char ); P7ポート制御処理 */
/**//* 備考 : */
/**//* : */
/**//************************************************************************
*/
short temp_in( char sel )
...{
short temp_val; //07.06.20 zhu 温度取得存放変数 sensor temperature
// short temp_add; //07.06.20 zhu
short temp_id; //07.06.20 zhu sensor ID
short ii;
dr_lm95071 = 0x70; //CS SC SI set 1;いらない?
ddr_lm95071 = 0x70;//CS SC SI OUTPUT FOR CPU
set_imask_ccr(1);
port_cnt(0,1); /**//* CS "High" */
port_cnt(0,0); /**//* CS "Low" */
temp_val = 0;
/**//* read the temperature 07.06.20 zhu */
for( ii=0 ; ii<=15 ; ii++ )
...{
port_cnt(1,1); /**//* CLK "High" */
port_cnt(1,0); /**//* CLK "Low" */
if( port_lm95071_so )/**//*port_data ==1*/
...{ temp_val |= 0x0001;}
else
...{ temp_val &= 0xFFFE;}
if(ii<=14)
...{ temp_val= temp_val<<1; }
}
// port_cnt(1,0);
// port_cnt(1,0);
/**//* write the shutdown mode 07.06.20 zhu */
for( ii=0; ii<=15; ii++ )
...{
port_cnt(1,0); /**//* CLK "Low" */
port_cnt(1,1); /**//* CLK "High" */
port_cnt(2,1); /**//* DATA OUT 1*/
}
port_cnt(0,1); /**//* CS "High" */
port_cnt(0,0); /**//* CS "Low" */
temp_id = 0;
/**//* read the sensor id 07.06.20 zhu */
for( ii=0; ii<=15; ii++)
...{
port_cnt(1,1); /**//* CLK "High" */
port_cnt(1,0); /**//* CLK "Low" */
if( port_lm95071_so )/**//*port_data ==1*/
...{ temp_id |= 0x0001;}
else
...{ temp_id &= 0xFFFE;}
if(ii<=14)
temp_id = temp_id<<1;
}
/**//* write the conversion mode 07.06.20 zhu */
for( ii=0; ii<=15; ii++)
...{
port_cnt(1,0); /**//* CLK "Low" */
port_cnt(1,1); /**//* CLK "High" */
port_cnt(2,0);
}
switch( sel )
...{
case 0:
return( temp_val );//return the temperature
case 1:
return( temp_id );//return the sensor ID
default:
return( temp_val );//return the temperature;
}
set_imask_ccr(0);
}
注意点:
1,读取的顺序
其他的好像就没什么了,还有就是焊接,要小心,以免损坏吧。
给上程序:
/**//*
************************************************************************
* 関数 : short temp_in( char sel ) ; 33751-V217-XXXX *
* -------------------------------------------------------------------- */
/**//* 名称 : 温度制御処理 */
/**//* 機能 : 温度制御処理 */
/**//* 説明 : 温度センサーの入出力を制御する。 */
/**//* : CS,SC,SI/O信号により温度を制御する。 */
/**//* : 温度とセンサー ID データ取得処理 */
/**//* 引数 : char (0~1まで使用) */
/**//* 戻り値 : short( この値が温度とセンサー ID データ値) */
/**//* : 1: ID データ値 */
/**//* : 0: 温度データ値 */
/**//* 使用関数: set_imask_ccr(unsigned char); 割込み 0:禁止解除1:禁止*/
/**//* : void port_cnt( char ,char ); P7ポート制御処理 */
/**//* 備考 : */
/**//* : */
/**//************************************************************************
*/
short temp_in( char sel )
...{
short temp_val; //07.06.20 zhu 温度取得存放変数 sensor temperature
// short temp_add; //07.06.20 zhu
short temp_id; //07.06.20 zhu sensor ID
short ii;
dr_lm95071 = 0x70; //CS SC SI set 1;いらない?
ddr_lm95071 = 0x70;//CS SC SI OUTPUT FOR CPU
set_imask_ccr(1);
port_cnt(0,1); /**//* CS "High" */
port_cnt(0,0); /**//* CS "Low" */
temp_val = 0;
/**//* read the temperature 07.06.20 zhu */
for( ii=0 ; ii<=15 ; ii++ )
...{
port_cnt(1,1); /**//* CLK "High" */
port_cnt(1,0); /**//* CLK "Low" */
if( port_lm95071_so )/**//*port_data ==1*/
...{ temp_val |= 0x0001;}
else
...{ temp_val &= 0xFFFE;}
if(ii<=14)
...{ temp_val= temp_val<<1; }
}
// port_cnt(1,0);
// port_cnt(1,0);
/**//* write the shutdown mode 07.06.20 zhu */
for( ii=0; ii<=15; ii++ )
...{
port_cnt(1,0); /**//* CLK "Low" */
port_cnt(1,1); /**//* CLK "High" */
port_cnt(2,1); /**//* DATA OUT 1*/
}
port_cnt(0,1); /**//* CS "High" */
port_cnt(0,0); /**//* CS "Low" */
temp_id = 0;
/**//* read the sensor id 07.06.20 zhu */
for( ii=0; ii<=15; ii++)
...{
port_cnt(1,1); /**//* CLK "High" */
port_cnt(1,0); /**//* CLK "Low" */
if( port_lm95071_so )/**//*port_data ==1*/
...{ temp_id |= 0x0001;}
else
...{ temp_id &= 0xFFFE;}
if(ii<=14)
temp_id = temp_id<<1;
}
/**//* write the conversion mode 07.06.20 zhu */
for( ii=0; ii<=15; ii++)
...{
port_cnt(1,0); /**//* CLK "Low" */
port_cnt(1,1); /**//* CLK "High" */
port_cnt(2,0);
}
switch( sel )
...{
case 0:
return( temp_val );//return the temperature
case 1:
return( temp_id );//return the sensor ID
default:
return( temp_val );//return the temperature;
}
set_imask_ccr(0);
}
相关文章推荐
- Microduino中LM75温度传感器的使用
- CC26xx之内置温度传感器的使用
- STM32的ADC及内部温度传感器的使用
- 基于S3C2440的嵌入式Linux驱动——DS18B20温度传感器(添加使用platform总线机制)
- 基于stc15芯片的温度传感器DS18B20的使用
- DS18b20温度传感器的使用
- 8.内部温度传感器的使用—基于CT117E开发板的STM32库函数编程
- Arduino使用模拟温度传感器
- 【Arduino】使用LM35传感器实时测量温度
- android 传感器使用与开发---温度传感器
- 通过PIC单片机使用DHT21温度传感器
- DS18B20温度传感器在90c51上的使用
- AD590温度传感器的使用
- 基于S3C2440的嵌入式Linux驱动——DS18B20温度传感器(添加使用platform总线机制)
- 基于S3C2440的嵌入式Linux驱动——DS18B20温度传感器(添加使用platform总线机制)
- DS18B20温度传感器使用简介
- AD590温度传感器的使用
- 温度传感器--DS18B20的使用
- 使用 Arduino 和 LM35 温度传感器监测温度
- linux下使用sqlite3记录温度传感器的数据