您的位置:首页 > 其它

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);


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: