⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yt_temep.lst

📁 完成数据的采集
💻 LST
📖 第 1 页 / 共 2 页
字号:
###############################################################################
#                                                                             #
#                                                       04/Dec/2008  16:07:56 #
# IAR ARM ANSI C/C++ Compiler V5.11.0.20622/W32 EVALUATION                    #
# Copyright 1999-2007 IAR Systems. All rights reserved.                       #
#                                                                             #
#    Cpu mode     =  thumb                                                    #
#    Endian       =  little                                                   #
#    Source file  =  E:\ELE\yten\pro\app\yt_TemEp.c                           #
#    Command line =  E:\ELE\yten\pro\app\yt_TemEp.c -D EMB_FLASH -lcN         #
#                    E:\ELE\yten\pro\Release\List\ -o                         #
#                    E:\ELE\yten\pro\Release\Obj\ --no_cse --no_unroll        #
#                    --no_inline --no_code_motion --no_tbaa --no_clustering   #
#                    --no_scheduling --debug --endian little --cpu Cortex-M3  #
#                    -e --fpu None --dlib_config "C:\Program Files\IAR        #
#                    Systems\Embedded Workbench 5.0                           #
#                    Evaluation\ARM\INC\DLib_Config_Normal.h" -I              #
#                    E:\ELE\yten\pro\ -I E:\ELE\yten\pro\..\LIBRARY\INC\ -I   #
#                    "C:\Program Files\IAR Systems\Embedded Workbench 5.0     #
#                    Evaluation\ARM\INC\" -On                                 #
#    List file    =  E:\ELE\yten\pro\Release\List\yt_TemEp.lst                #
#    Object file  =  E:\ELE\yten\pro\Release\Obj\yt_TemEp.o                   #
#                                                                             #
#                                                                             #
###############################################################################

E:\ELE\yten\pro\app\yt_TemEp.c
      1          #include"includes.h"
      2          #include"ytep.h"
      3          #include"ytepfunction.h"
      4          #define  yt_TemEp_file
      5          
      6          
      7          u8	FM_TAB[]={0,0,0,0,55,3,10,10,65,1,
      8          				1,1,1,1,0,0,0,0,0,0,0,146};
      9          ///////////////////////////////////
     10          void  GPIO_InOut(GPIO_TypeDef* GPIOx,Int16U GPIO_Bit,Int8U GPIO_Speed_value,Int16U GPIO_InOut)
     11          {
     12          	GPIO_InitTypeDef GPIO_InitStructure;
     13          	GPIO_InitStructure.GPIO_Pin =GPIO_Bit;
     14            GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)GPIO_Speed_value;
     15            GPIO_InitStructure.GPIO_Mode=(GPIOMode_TypeDef)GPIO_InOut;  //GPIO_Mode_Out_PP;
     16            GPIO_Init(GPIOx, &GPIO_InitStructure);  //setion output
     17          }
     18           
     19          ////////////////////////////////////////////////
     20          void START_SHT(Tem *IO_Tem)
     21          {
     22          	GPIO_InOut(IO_Tem->IOD,1<<IO_Tem->IO_D,1,GPIO_Mode_Out_PP);//IO_I2CD,GPIO_Pin_I2CD,1,GPIO_Mode_Out_PP
     23          	GPIO_InOut(IO_Tem->IOC,1<<IO_Tem->IO_C,1,GPIO_Mode_Out_PP);
     24          
     25          	Set_bit((IO_Tem->IOD)->ODR,IO_Tem->IO_D); 
     26          	delay(20);
     27          	Set_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);  
     28          	delay(20);
     29          	Clr_bit((IO_Tem->IOD)->ODR,IO_Tem->IO_D);   
     30          	delay(20);
     31          	Clr_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);  
     32          	delay(20);	
     33          	Set_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C); 
     34          	delay(20);
     35          	Set_bit((IO_Tem->IOD)->ODR,IO_Tem->IO_D);
     36          	delay(20);
     37          	Clr_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);  	
     38            delay(20);
     39          }
     40          Int8U	SHTA_ack(Tem *IO_Tem)
     41          {
     42            Int8U z=0;
     43          	GPIO_InOut(IO_Tem->IOD,1<<IO_Tem->IO_D,0,GPIO_Mode_IN_FLOATING);
     44          	delay(20);
     45          	Set_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);
     46          	delay(20);
     47          	z=GPIO_ReadInputDataBit(IO_Tem->IOD,1<<IO_Tem->IO_D);	
     48          	Clr_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);  	
     49          	GPIO_InOut(IO_Tem->IOD,1<<IO_Tem->IO_D,1,GPIO_Mode_Out_PP);
     50          	Set_bit((IO_Tem->IOD)->ODR,IO_Tem->IO_D);
     51            return z;
     52          }
     53          ////////////////////////////////
     54          Int8U Write_SHT(const Int8U	data,Tem *IO_Tem)
     55          {
     56          	Int8U x,y,x1;
     57          	y=data;
     58          	for(x1=0;x1<3;x1++)
     59          	{
     60          	 	for(x=0;x<8;x++)
     61          	 	{
     62          			if(y&0x80)Set_bit((IO_Tem->IOD)->ODR,IO_Tem->IO_D);
     63          			else      Clr_bit((IO_Tem->IOD)->ODR,IO_Tem->IO_D);
     64          			y<<=1;
     65          			Set_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);
     66          			delay(20);
     67          			Clr_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);
     68          			delay(20);
     69          	 	}
     70          	  	y=SHTA_ack(IO_Tem);
     71          	  	if(y==0)return 0;
     72          	  	y=data;
     73          	  	START_SHT(IO_Tem);
     74          	 }
     75          	 return 1;	
     76          }
     77          Int8U	Read_SHT(Tem *IO_Tem,Int8U xyz)//xyz=0 is temperature,xyz=1 is humidity
     78          {
     79          	Int8U x,x1,y;
     80          	Int32U x1_data=0;
     81          	
     82          	for(x1=0;x1<3;x1++)
     83          	{
     84             	GPIO_InOut(IO_Tem->IOD,1<<IO_Tem->IO_D,0,GPIO_Mode_IN_FLOATING);
     85             	for(x=0;x<8;x++)
     86             	{
     87             		x1_data<<=1;
     88             		delay(20);
     89             		Set_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);
     90             		delay(20);
     91             		y=GPIO_ReadInputDataBit(IO_Tem->IOD,1<<IO_Tem->IO_D);
     92             		if(y!=0)x1_data|=1;
     93             		Clr_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);
     94             	}
     95             	GPIO_InOut(IO_Tem->IOD,1<<IO_Tem->IO_D,1,GPIO_Mode_Out_PP);
     96             	Clr_bit((IO_Tem->IOD)->ODR,IO_Tem->IO_D);
     97             	delay(20);
     98             	Set_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);
     99             	delay(20);
    100             	Clr_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);
    101             	delay(20);
    102          	}
    103          		GPIO_InOut(IO_Tem->IOD,1<<IO_Tem->IO_D,1,GPIO_Mode_Out_PP);
    104          	  delay(20);
    105          	  Set_bit((IO_Tem->IOD)->ODR,IO_Tem->IO_D);
    106          	  delay(20);
    107          	  Set_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);
    108             	delay(20);
    109             	Clr_bit((IO_Tem->IOC)->ODR,IO_Tem->IO_C);
    110             	x=0x80;                   //如是8位x=0x80,12位则x=0
    111             	if(xyz==0)x=crc8(3,x);  //Tempertion
    112             	else			x=crc8(5,x);  //RH
    113             	y=(Int8U)(x1_data>>16);
    114             	x=crc8(y,x);//第一字节,命令字节
    115             	y=(Int8U)(x1_data>>8);//
    116             	x=crc8(y,x);
    117             	x=swapcrc(x); 
    118             	y=(Int8U)(x1_data&0xff);	
    119             	if(x==y)
    120             	{
    121             		x1_data=x1_data>>8;
    122             		if(xyz==0)IO_Tem->Temperature=account_Temp((Int16U)x1_data,0);
    123          	  	else      IO_Tem->Humidity=account_RH((Int16U)x1_data,0);
    124          	  	return 0;
    125             	}else
    126             	 return  0XFF;
    127          }
    128          /////////////////////////////////
    129          //-----------------------------------------------
    130          // crc caculate
    131          //-----------------------------------------------
    132          Int8U crc8(Int8U byte,Int8U crc8)
    133          {
    134           Int8U i;
    135           volatile Int8U temp;
    136           crc8^=byte;
    137           for(i=0;i<8;i++)
    138           {
    139            temp=crc8;
    140            crc8<<=1;
    141            if((temp&0x80)!=0)
    142             crc8^=0x31;
    143           }
    144           return crc8;
    145          }
    146          //-----------------------------------------------
    147          // swap crc byte
    148          //-----------------------------------------------
    149          Int8U swapcrc(Int8U byte)
    150          {
    151           Int8U i;
    152           Int8U temp=0;
    153           
    154           for (i=0x80;i>0;i/=2)
    155           {
    156            if((byte&i)!=0)
    157             temp|=0x80;
    158            if(i==0x01)
    159             break;
    160            temp>>=1;
    161            temp&=0x7f;
    162           }
    163           return temp;
    164          }
    165          ////////////////////////////////xb is 12bit or 8bit
    166          Int8U account_Temp(Int16U xa,Int8U xb)
    167          {
    168          	if(xb==1)             //14bit
    169          		xa&=0x3fff;
    170          	else
    171          		xa&=0x0fff;
    172          	if(xb==0)
    173          		xa<<=2;
    174          	xa=xa/100;    //t=d1+d2*0.04 d1=-40
    175          	xa&=0x00ff;
    176          	return xa;
    177          }
    178          ////////////////////////////////
    179          Int8U account_RH(Int16U xa,Int8U xb)
    180          {
    181          	if(xb==1)
    182          	xa>>=4;
    183          	xa&=0x00ff;            //8bit
    184          	if(xa<=107)
    185          	{
    186          		xa=xa*143;
    187          	  if(xa<512)return 2;
    188          	  xa=xa-512; 	
    189          	}
    190          	else
    191          	{
    192          		xa=xa*111;
    193          		xa+=2893;
    194          	}
    195          	 xa>>=8;
    196          	 xa&=0x00ff;
    197          	 return xa;
    198          }
    199          ///////////////////////////////////////////////
    200          void		Test_error(const	Int8U x,Tem *IO_Tem)
    201          {
    202          	if(x==0)IO_Tem->counter_error=0,IO_Tem->Error=0;
    203          	else
    204          		{
    205          			if(++(IO_Tem->counter_error)>=10)
    206          			IO_Tem->Error=TRUE;	
    207          		}
    208          }
    209          ///////////////////////////////////////////////
    210          void read_SHT_data()
    211          {
    212          	volatile Int8U a_sht;
    213          	static 	 Int8U  Timecounter;
    214          	if(++Timecounter>=20)Timecounter=0;
    215          	switch(Timecounter)
    216          	{
    217          		case 0:
    218          			a_sht=Read_SHT(&TemRHA,1);
    219          			Test_error(a_sht,&TemRHA);
    220          			START_SHT(&TemRHA);			
    221          			a_sht=Write_SHT(6,&TemRHA);
    222          			a_sht=Write_SHT(1,&TemRHA);	
    223          			a_sht=Write_SHT(3,&TemRHA);
    224          			Test_error(a_sht,&TemRHA);							 				
    225          		break;
    226          		case 1:
    227          			a_sht=Read_SHT(&TemRHA,0);
    228          			Test_error(a_sht,&TemRHA);
    229          			break;
    230          		case 19:
    231          			START_SHT(&TemRHA);
    232          			a_sht=Write_SHT(5,&TemRHA);		 
    233          			Test_error(a_sht,&TemRHA);		 			
    234          			break;
    235          	
    236          				
    237          	 }
    238          	 if(TemRHA.Error==0)
    239                   {
    240                     A_RHbuf=TemRHA.Humidity;
    241                     //A_Tembuf=TemRHA.Temperature;
    242                     A_Tembuf=TemRHA.Temperature;
    243                     //if(TemRHA.Temperature>=40)
    244                     //A_Tembuf=TemRHA.Temperature-40;
    245                     //else     A_Tembuf=0;
    246                   }
    247          	 else	    A_Tembuf=TemRHA.Temperature=A_RHbuf=TemRHA.Humidity=0xff;
    248          }	
    249          /////////////////////////////////////////////////////////
    250          
    251          
    252          void sta( )/*启动I2C总线*/
    253          {
    254           Set_bit(IO_I2CD->ODR,I2CD);//SDA_S;
    255           Set_bit(IO_I2CC->ODR,I2CC);//SCL_S ;
    256           delay(20);
    257           Clr_bit(IO_I2CD->ODR,I2CD);//SDA_C;
    258           delay(20);
    259           Clr_bit(IO_I2CC->ODR,I2CC);//SCL_C;
    260           delay(20);
    261          }
    262          
    263          void stop( ) /*stop i2c*/
    264          {
    265          	Clr_bit(IO_I2CD->ODR,I2CD);//SDA_C;
    266          	Set_bit(IO_I2CC->ODR,I2CC);//SCL_S;
    267          	delay(20);
    268          	Set_bit(IO_I2CD->ODR,I2CD);//SDA_S;
    269          	delay(20);
    270          	Clr_bit(IO_I2CC->ODR,I2CC);//SCL_C;
    271            delay(20);
    272          }
    273          
    274          void mack()/*发送应答位*/
    275          {
    276          	Clr_bit(IO_I2CD->ODR,I2CD);//SDA_C;
    277          	Set_bit(IO_I2CC->ODR,I2CC);//SCL_S;
    278          	delay(20);
    279          	Clr_bit(IO_I2CC->ODR,I2CC);//SCL_C;
    280          	Set_bit(IO_I2CD->ODR,I2CD);//SDA_S;
    281            delay(20);
    282          }
    283          
    284          void mnack()/*发送非应答位*/
    285          {
    286          	Set_bit(IO_I2CD->ODR,I2CD);//SDA_D;
    287          	Set_bit(IO_I2CC->ODR,I2CC);//SCL_S;
    288          	delay(20);
    289          	Clr_bit(IO_I2CC->ODR,I2CC);//SCL_C;
    290          	Clr_bit(IO_I2CD->ODR,I2CD);//SDA_C;
    291            delay(20);
    292          }
    293          
    294          Int8U cack()/*应答位检查*/
    295          {
    296           Int8U c;
    297           	GPIO_InOut(IO_I2CD,GPIO_Pin_I2CD,0,GPIO_Mode_IN_FLOATING);//SDA_IN;
    298          	delay(20);
    299          	Set_bit(IO_I2CC->ODR,I2CC);//SCL_S;
    300          	c=0;
    301            delay(20);
    302          	if(Get_bit(IO_I2CD->IDR,I2CD)!=0)    //check sda
    303            c=1;
    304          	Clr_bit(IO_I2CC->ODR,I2CC);//SCL_C;
    305          	GPIO_InOut(IO_I2CD,GPIO_Pin_I2CD,1,GPIO_Mode_Out_PP);//SDA_OUT;
    306          	delay(20);
    307          	return c;
    308          }
    309          /*向虚拟I2C总线上发送1个数据字节*/
    310          void WRBYT(Int8U z)
    311          {
    312          	Int8U i;
    313          	for(i=0;i<8;i++)
    314          	{
    315          	if((z&0x80)>0)Set_bit(IO_I2CD->ODR,I2CD);//SDA_S;
    316          	else					Clr_bit(IO_I2CD->ODR,I2CD);//SDA_C;
    317          	Set_bit(IO_I2CC->ODR,I2CC);//SCL_S;
    318          	delay(20);
    319          	Clr_bit(IO_I2CC->ODR,I2CC);//SCL_C;
    320          	z=z<<1;
    321          	delay(20);
    322            }
    323          }
    324          /*从I2C总线上读取1个数据字节*/
    325          Int8U RDBYT()
    326          {
    327          	Int8U nn=0;
    328          	Int8U j;
    329          	GPIO_InOut(IO_I2CD,GPIO_Pin_I2CD,0,GPIO_Mode_IN_FLOATING);//SDA_IN;
    330          	for(j=0;j<8;j++)
    331          	{
    332          		Set_bit(IO_I2CC->ODR,I2CC);///SCL_S;
    333          		delay(20);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -