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

📄 measure.s

📁 ATmega128单片机对SHT7x温湿度传感器的驱动程序。编译环境:ICC AVR
💻 S
📖 第 1 页 / 共 3 页
字号:
	cpi R20,9
	brlo L43
X18:
	.dbline 310
;   { SCK_TO_1(); 
;     _NOP();
;     SCK_TO_0();
;     _NOP();
;   }
;   s_transstart();                   //transmission start
	xcall _s_transstart
	.dbline -2
L42:
	ld R21,y+
	ld R20,y+
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e s_measure _s_measure fc
;          error -> R20,R21
;              k -> R12,R13
;              i -> R14,R15
;              j -> R22,R23
;           mode -> R12
;     p_checksum -> R10,R11
	.even
_s_measure::
	xcall push_xgset5
	mov R12,R18
	movw R10,R16
	.dbline -1
	.dbline 317
; }  
; 
; 
; char s_measure(unsigned char *p_checksum, unsigned char mode)
; //----------------------------------------------------------------------------------
; // makes a measurement (humidity/temperature) with checksum
; { 
	.dbline 318
;   unsigned error=0;
	clr R20
	clr R21
	.dbline 321
;   unsigned int i,j,k;
; 
;   s_transstart();                   //transmission start
	xcall _s_transstart
	.dbline 322
;   switch(mode){                     //send command to sensor
	clr R13
	tst R12
	brne X19
	tst R13
	breq L51
X19:
	movw R24,R12
	cpi R24,1
	ldi R30,0
	cpc R25,R30
	breq L52
X20:
	xjmp L49
X21:
	.dbline 322
L51:
	.dbline 323
;     case TEMP	: error+=s_write_byte(MEASURE_TEMP); break;
	ldi R16,3
	xcall _s_write_byte
	mov R2,R16
	clr R3
	add R20,R2
	adc R21,R3
	.dbline 323
	xjmp L49
L52:
	.dbline 324
;     case HUMI	: error+=s_write_byte(MEASURE_HUMI); break;
	ldi R16,5
	xcall _s_write_byte
	mov R2,R16
	clr R3
	add R20,R2
	adc R21,R3
	.dbline 324
	.dbline 325
;     default     : break;	 
L49:
	.dbline 327
;   }
;   PORTF |=0x02;
	lds R24,98
	ori R24,2
	sts 98,R24
	.dbline 328
;   DDRF &=0xfd;
	lds R24,97
	andi R24,253
	sts 97,R24
	.dbline 329
;   for(k=0;k<65535u;k++)
	clr R12
	clr R13
	xjmp L56
L53:
	.dbline 330
;   {
	.dbline 331
;   for (i=0;i<65535u;i++)
	clr R14
	clr R15
	xjmp L60
L57:
	.dbline 332
;   {
	.dbline 333
;   	j=PINF&0x02;//DATA_status();//PORTF&0x02;
	in R22,0x0
	clr R23
	andi R22,2
	andi R23,0
	.dbline 334
	cpi R22,0
	cpc R22,R23
	brne L61
X22:
	.dbline 334
;   	 if(j==0) break;
	xjmp L59
L61:
	.dbline 335
L58:
	.dbline 331
	movw R24,R14
	adiw R24,1
	movw R14,R24
L60:
	.dbline 331
	movw R24,R14
	cpi R24,255
	ldi R30,255
	cpc R25,R30
	brlo L57
X23:
L59:
	.dbline 336
;   	} 
;   	if(j==0)
	cpi R22,0
	cpc R22,R23
	brne L63
X24:
	.dbline 337
;   	break;
	xjmp L55
L63:
	.dbline 338
L54:
	.dbline 329
	movw R24,R12
	adiw R24,1
	movw R12,R24
L56:
	.dbline 329
	movw R24,R12
	cpi R24,255
	ldi R30,255
	cpc R25,R30
	brlo L53
X25:
L55:
	.dbline 342
	cpi R22,0
	cpc R22,R23
	breq L65
X26:
	.dbline 342
;   }
;   	
;   
;   
;   if(j) error+=1;                // or timeout (~2 sec.) is reached
	subi R20,255  ; offset = 1
	sbci R21,255
L65:
	.dbline 343
;   cwendu1=s_read_byte(ACK);    //read the first byte (MSB)
	ldi R16,1
	xcall _s_read_byte
	sts _cwendu1,R16
	.dbline 344
;   cwendu2=s_read_byte(ACK);    //read the second byte (LSB)
	ldi R16,1
	xcall _s_read_byte
	sts _cwendu2,R16
	.dbline 345
;   uwendu =cwendu1*256+cwendu2;
	lds R18,_cwendu1
	clr R19
	ldi R16,256
	ldi R17,1
	xcall empy16s
	movw R2,R16
	lds R4,_cwendu2
	clr R5
	add R2,R4
	adc R3,R5
	sts _uwendu+1,R3
	sts _uwendu,R2
	.dbline 346
;   *p_checksum =s_read_byte(noACK);
	clr R16
	xcall _s_read_byte
	movw R30,R10
	std z+0,R16
	.dbline 348
;   
;   if(error>0)
	cpi R20,0
	cpc R20,R21
	breq L67
X27:
	.dbline 349
;   	 PORTA |=0x02;  //read checksum
	sbi 0x1b,1
L67:
	.dbline 350
;   return error;
	mov R16,R20
	.dbline -2
L47:
	xcall pop_xgset5
	.dbline 0 ; func end
	ret
	.dbsym r error 20 i
	.dbsym r k 12 i
	.dbsym r i 14 i
	.dbsym r j 22 i
	.dbsym r mode 12 c
	.dbsym r p_checksum 10 pc
	.dbend
	.dbfunc e calc_sth11 _calc_sth11 fV
;            t_C -> y+4
;              t -> y+0
;  p_temperature -> R10,R11
	.even
_calc_sth11::
	st -y,R10
	st -y,R11
	movw R10,R16
	sbiw R28,8
	.dbline -1
	.dbline 360
; } 
; void calc_sth11(float *p_temperature)
; //void calc_sth11(float *p_humidity ,float *p_temperature)
; //----------------------------------------------------------------------------------------
; // calculates temperature [癈] and humidity [%RH] 
; // input :  humi [Ticks] (12 bit) 
; //          temp [Ticks] (14 bit)
; // output:  humi [%RH]
; //          temp [癈]
; { 
	.dbline 363
; 
;   //float rh=*p_humidity;             // rh:      Humidity [Ticks] 12 Bit 
;   float t=*p_temperature;           // t:       Temperature [Ticks] 14 Bit
	movw R30,R10
	ldd R2,z+0
	ldd R3,z+1
	ldd R4,z+2
	ldd R5,z+3
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	.dbline 368
;   //float rh_lin;                     // rh_lin:  Humidity linear
;   //float rh_true;                    // rh_true: Temperature compensated humidity
;   float t_C;                        // t_C   :  Temperature [癈]
; 
;   t_C=t*0.01 - 40;//-327.68;                  //calc. temperature from ticks to [癈]
	ldi R16,<L70
	ldi R17,>L70
	xcall lpm32
	movw R24,R28
	st -y,R25
	st -y,R24
	xcall fpmule1
	movw R2,R16
	movw R4,R18
	ldi R16,<L71
	ldi R17,>L71
	xcall lpm32
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R2
	movw R18,R4
	xcall fpsub2
	std y+4,R16
	std y+5,R17
	std y+6,R18
	std y+7,R19
	.dbline 374
;   //rh_lin=C3*rh*rh + C2*rh + C1;     //calc. humidity from ticks to [%RH]
;   //rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;   //calc. temperature compensated humidity [%RH]
;   //if(rh_true>100)rh_true=100;       //cut if the value is outside of
;   //if(rh_true<0.1)rh_true=0.1;       //the physical possible range
; 
;   *p_temperature=t_C;               //return temperature [癈]
	ldd R2,y+4
	ldd R3,y+5
	ldd R4,y+6
	ldd R5,y+7
	movw R30,R10
	std z+0,R2
	std z+1,R3
	std z+2,R4
	std z+3,R5
	.dbline -2
L69:
	adiw R28,8
	ld R11,y+
	ld R10,y+
	.dbline 0 ; func end
	ret
	.dbsym l t_C 4 D
	.dbsym l t 0 D
	.dbsym r p_temperature 10 pD
	.dbend
	.dbfunc e main _main fV
;       checksum -> y+0
;          error -> R10
;              i -> R10,R11
	.even
_main::
	sbiw R28,1
	.dbline -1
	.dbline 401
;   //*p_humidity=rh_true;              //return humidity[%RH]
; }
; 
; /*float calc_dewpoint(float h,float t)
; //--------------------------------------------------------------------
; // calculates dew point
; // input:   humidity [%RH], temperature [癈]
; // output:  dew point [癈]
; { float logEx,dew_point;
;   logEx=0.66077+7.5*t/(237.3+t)+(log10(h)-2);
;   dew_point = (logEx - 0.66077)*237.3/(0.66077+7.5-logEx);
;   return dew_point;
; }
; */
; 
; 
; 
; void main()
; //----------------------------------------------------------------------------------
; // sample program that shows how to use SHT11 functions
; // 1. connection reset 
; // 2. measure humidity [ticks](12 bit) and temperature [ticks](14 bit)
; // 3. calculate humidity [%RH] and temperature [癈]
; // 4. calculate dew point [癈]
; // 5. print temperature, humidity, dew point  
; 
; { //value temp_val;//humi_val;
	.dbline 408
; 	//unsigned int temp_new;
;   //float dew_point;
;   unsigned char error,checksum;
;   unsigned int i;
;  
;   
;   DDRA |=0x07;
	in R24,0x1a
	ori R24,7
	out 0x1a,R24
	xjmp L74
L73:
	.dbline 423
;    //delay();
;    //delay();
;    //newdelay();
;   //init_uart();
;   //while(1)
;   
; 
;   
;   
;    //PORTA &=0xfb;
; 
;   
;  
;   while(1)
;   {
	.dbline 424
;   	shxx_config();
	xcall _shxx_config
	.dbline 425
;   	s_connectionreset();
	xcall _s_connectionreset
	.dbline 426
;    error=0;
	clr R10
	.dbline 429
;     //error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  //measure humidity
;     //error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  //measure temperature
;     error+=s_measure(&checksum,TEMP); 
	clr R18
	movw R16,R28
	xcall _s_measure
	add R10,R16
	.dbline 430
;     if(error!=0) 
	breq L76
X28:
	.dbline 431
;     s_connectionreset();
	xcall _s_connectionreset
	xjmp L77
L76:
	.dbline 433
;     else
;     {	
	.dbline 441
;      //for (i=0;i<60000;i++);	
;      
;     //PORTA &=0xfb;                //in case of an error: connection reset
;     
;      //PORTA &=0xfb;
;     	//PORTA =0x02;
;     	//humi_val.f=(float)humi_val.i;                   //converts integer to float
;       fwendu=(float)uwendu; 
	lds R2,_uwendu
	lds R3,_uwendu+1
	ldi R16,<L78
	ldi R17,>L78
	xcall lpm32
	movw R4,R16
	movw R6,R18
	movw R16,R2
	lsr R17
	ror R16
	xcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R4
	movw R18,R6
	xcall fpmule2
	movw R4,R16
	movw R6,R18
	movw R16,R2
	andi R16,1
	andi R17,0
	xcall int2fp
	st -y,R19
	st -y,R18
	st -y,R17
	st -y,R16
	movw R16,R4
	movw R18,R6
	xcall fpadd2
	sts _fwendu+1,R17
	sts _fwendu,R16
	sts _fwendu+2+1,R19
	sts _fwendu+2,R18
	.dbline 442
;       calc_sth11(&fwendu);                   //converts integer to float
	ldi R16,<_fwendu
	ldi R17,>_fwendu
	xcall _calc_sth11
	.dbline 446
;       //calc_sth11(&humi_val.f,&temp_val.f);            //calculate humidity, temperature
;       //dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point
;       //printf("temp:%5.1fC humi:%5.1f%% dew point:%5.1fC\n",temp_val.f,humi_val.f,dew_point);
;      }
L77:
	.dbline 447
;     if(fwendu>30.0)
	ldi R24,<_fwendu
	ldi R25,>_fwendu
	ldi R16,<L81
	ldi R17,>L81
	xcall lpm32
	st -y,R25
	st -y,R24
	xcall fpcmp1
	brge L79
X29:
	.dbline 448
;      PORTA |=0x01;
	sbi 0x1b,0
	xjmp L80
L79:
	.dbline 450
;      else
;      PORTA &=0xfe;
	in R24,0x1b
	andi R24,254
	out 0x1b,R24
L80:
	.dbline 453
	clr R10
	clr R11
	xjmp L85
L82:
	.dbline 453
L83:
	.dbline 453
	movw R24,R10
	adiw R24,1
	movw R10,R24
L85:
	.dbline 453
;     
;     //----------wait approx. 0.8s to avoid heating up SHTxx------------------------------      
;     for (i=0;i<40000;i++);     //(be sure that the compiler doesn't eliminate this line!)
	ldi R20,64
	ldi R21,156
	ldi R22,0
	ldi R23,0
	movw R2,R10
	clr R4
	clr R5
	cp R2,R20
	cpc R3,R21
	cpc R4,R22
	cpc R5,R23
	brlt L82
X30:
	.dbline 455
L74:
	.dbline 422
	xjmp L73
X31:
	.dbline -2
L72:
	adiw R28,1
	.dbline 0 ; func end
	ret
	.dbsym l checksum 0 c
	.dbsym r error 10 c
	.dbsym r i 10 i
	.dbend
	.area bss(ram, con, rel)
	.dbfile C:\DOCUME~1\xzy_bupt\桌面\measure_temp\measure.c
_fwendu::
	.blkb 4
	.dbsym e fwendu _fwendu D
_uwendu::
	.blkb 2
	.dbsym e uwendu _uwendu i
_cwendu2::
	.blkb 1
	.dbsym e cwendu2 _cwendu2 c
_cwendu1::
	.blkb 1
	.dbsym e cwendu1 _cwendu1 c
	.area lit(rom, con, rel)
L81:
	.word 0x0,0x41f0
L78:
	.word 0x0,0x4000
L71:
	.word 0x0,0x4220
L70:
	.word 0xd70a,0x3c23

⌨️ 快捷键说明

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