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

📄 i2c.s

📁 AVR单片机C语言程序设计实例精粹
💻 S
📖 第 1 页 / 共 2 页
字号:
	.dbsym r ack 20 c
	.dbend
	.dbfunc e I2C_Send_Data_without_SubAddress _I2C_Send_Data_without_SubAddress fc
;          bData -> R20
;        bDevice -> R22
	.even
_I2C_Send_Data_without_SubAddress::
	xcall push_gset2
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 182
; 
; //***************************************************************
; // Function    : I2C_Send_Data_without_SubAddress
; // Input       : bDevice - Slave Device with a I2C Address,
; //               bData   - Data to be transmitted 
; // Output      : I2C Operation Status - Success(1)/Fail(0)
; // Description : Transmit a data to Slave without SubAddress
; //***************************************************************
; INT8U I2C_Send_Data_without_SubAddress(INT8U bDevice,INT8U bData)
; {
	.dbline 183
; 	I2C_Start_Condition();
	xcall _I2C_Start_Condition
	.dbline 184
; 	I2C_Send_Byte(bDevice);
	mov R16,R22
	xcall _I2C_Send_Byte
	.dbline 185
; 	if(bI2C_Ack == 0)
	lds R2,_bI2C_Ack
	tst R2
	brne L33
	.dbline 186
; 	{
	.dbline 187
; 		return(0);
	clr R16
	xjmp L32
L33:
	.dbline 189
; 	}
; 	I2C_Send_Byte(bData);
	mov R16,R20
	xcall _I2C_Send_Byte
	.dbline 190
; 	if(bI2C_Ack == 0)
	lds R2,_bI2C_Ack
	tst R2
	brne L35
	.dbline 191
; 	{
	.dbline 192
; 		return(0);
	clr R16
	xjmp L32
L35:
	.dbline 194
; 	}
; 	I2C_Stop_Condition();
	xcall _I2C_Stop_Condition
	.dbline 195
; 	return(1);
	ldi R16,1
	.dbline -2
L32:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r bData 20 c
	.dbsym r bDevice 22 c
	.dbend
	.dbfunc e I2C_Send_Data_with_SubAddress _I2C_Send_Data_with_SubAddress fc
;          bData -> y+4
;       bAddress -> R20
;        bDevice -> R22
	.even
_I2C_Send_Data_with_SubAddress::
	xcall push_gset2
	mov R20,R18
	mov R22,R16
	.dbline -1
	.dbline 207
; }
; 
; //***************************************************************
; // Function    : I2C_Send_Data_with_SubAddress
; // Input       : bDevice  - Slave Device with a I2C Address,
; //               bAddress - SubAddress of the Slave,
; //               bData    - Data to be transmitted 
; // Output      : I2C Operation Status - Success(1)/Fail(0)
; // Description : Transmit a data to Slave with SubAddress
; //***************************************************************
; INT8U I2C_Send_Data_with_SubAddress(INT8U bDevice,INT8U bAddress,INT8U bData)
; {
	.dbline 208
; 	I2C_Start_Condition();
	xcall _I2C_Start_Condition
	.dbline 209
;    	I2C_Send_Byte(bDevice);
	mov R16,R22
	xcall _I2C_Send_Byte
	.dbline 210
;    	if(bI2C_Ack == 0)
	lds R2,_bI2C_Ack
	tst R2
	brne L38
	.dbline 211
;    	{
	.dbline 212
;    		return(0);
	clr R16
	xjmp L37
L38:
	.dbline 214
;    	}
;    	I2C_Send_Byte(bAddress);
	mov R16,R20
	xcall _I2C_Send_Byte
	.dbline 215
;     if(bI2C_Ack == 0)
	lds R2,_bI2C_Ack
	tst R2
	brne L40
	.dbline 216
;     {
	.dbline 217
;     	return(0);
	clr R16
	xjmp L37
L40:
	.dbline 219
;     }
;     I2C_Send_Byte(bData);
	ldd R16,y+4
	xcall _I2C_Send_Byte
	.dbline 220
;     if(bI2C_Ack == 0)
	lds R2,_bI2C_Ack
	tst R2
	brne L42
	.dbline 221
;     {
	.dbline 222
;     	return(0);
	clr R16
	xjmp L37
L42:
	.dbline 224
;     }
;   	I2C_Stop_Condition();
	xcall _I2C_Stop_Condition
	.dbline 225
;   	return(1);
	ldi R16,1
	.dbline -2
L37:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym l bData 4 c
	.dbsym r bAddress 20 c
	.dbsym r bDevice 22 c
	.dbend
	.dbfunc e I2C_Send_String_with_SubAddress _I2C_Send_String_with_SubAddress fc
;            cnt -> R20
;        bLength -> R22
;            ptr -> R10,R11
;       bAddress -> R20
;        bDevice -> R12
	.even
_I2C_Send_String_with_SubAddress::
	xcall push_gset4
	mov R20,R18
	mov R12,R16
	ldd R10,y+8
	ldd R11,y+9
	ldd R22,y+10
	.dbline -1
	.dbline 237
; }
; 
; //***************************************************************
; // Function    : I2C_Send_String_with_SubAddress
; // Input       : bDevice  - Slave Device with a I2C Address,
; //               bAddress - SubAddress of the Slave,
; //               ptr      - Pointer to the data buffter 
; // Output      : I2C Operation Status - Success(1)/Fail(0)
; // Description : Transmit a data to Slave with SubAddress
; //***************************************************************
; INT8U I2C_Send_String_with_SubAddress(INT8U bDevice,INT8U bAddress,INT8U *ptr,INT8U bLength)
; {
	.dbline 239
; 	INT8U cnt;
; 	I2C_Start_Condition();																		
	xcall _I2C_Start_Condition
	.dbline 240
; 	I2C_Send_Byte(bDevice);																		
	mov R16,R12
	xcall _I2C_Send_Byte
	.dbline 241
; 	if(bI2C_Ack == 0)																		
	lds R2,_bI2C_Ack
	tst R2
	brne L45
	.dbline 242
; 	{																		
	.dbline 243
; 		return(0);																		
	clr R16
	xjmp L44
L45:
	.dbline 245
; 	}																		
; 	I2C_Send_Byte(bAddress);																		
	mov R16,R20
	xcall _I2C_Send_Byte
	.dbline 246
;   	if(bI2C_Ack == 0)																		
	lds R2,_bI2C_Ack
	tst R2
	brne L47
	.dbline 247
; 	{																		
	.dbline 248
; 		return(0);																		
	clr R16
	xjmp L44
L47:
	.dbline 250
; 	}	
; 	for(cnt = 0;cnt < bLength;cnt++)
	clr R20
	xjmp L52
L49:
	.dbline 251
; 	{
	.dbline 252
; 		I2C_Send_Byte(*ptr++);
	movw R30,R10
	ld R16,Z+
	movw R10,R30
	xcall _I2C_Send_Byte
	.dbline 253
; 		if(bI2C_Ack == 0)																		
	lds R2,_bI2C_Ack
	tst R2
	brne L53
	.dbline 254
; 		{																		
	.dbline 255
; 			return(0);																		
	clr R16
	xjmp L44
L53:
	.dbline 257
L50:
	.dbline 250
	inc R20
L52:
	.dbline 250
	cp R20,R22
	brlo L49
	.dbline 258
; 		}
; 	}
; 	I2C_Stop_Condition();
	xcall _I2C_Stop_Condition
	.dbline 259
; 	return(1);
	ldi R16,1
	.dbline -2
L44:
	xcall pop_gset4
	.dbline 0 ; func end
	ret
	.dbsym r cnt 20 c
	.dbsym r bLength 22 c
	.dbsym r ptr 10 pc
	.dbsym r bAddress 20 c
	.dbsym r bDevice 12 c
	.dbend
	.dbfunc e I2C_Receive_Data_without_SubAddress _I2C_Receive_Data_without_SubAddress fc
;            ptr -> R20,R21
;        bDevice -> R22
	.even
_I2C_Receive_Data_without_SubAddress::
	xcall push_gset2
	movw R20,R18
	mov R22,R16
	.dbline -1
	.dbline 270
; }
; 
; //***************************************************************
; // Function    : I2C_Receive_Data_without_Address
; // Input       : bDevice  - Slave Device with a I2C Address,
; //               ptr      - Pointer to the receive data buffter 
; // Output      : I2C Operation Status - Success(1)/Fail(0)
; // Description : Receive N data from Slave without SubAddress
; //***************************************************************
; INT8U I2C_Receive_Data_without_SubAddress(INT8U bDevice,INT8U *ptr)
; {
	.dbline 271
; 	I2C_Start_Condition();
	xcall _I2C_Start_Condition
	.dbline 272
; 	I2C_Send_Byte(bDevice | 0x01);
	mov R16,R22
	ori R16,1
	xcall _I2C_Send_Byte
	.dbline 273
;     if(bI2C_Ack == 0)
	lds R2,_bI2C_Ack
	tst R2
	brne L56
	.dbline 274
;     {
	.dbline 275
;     	return(0);
	clr R16
	xjmp L55
L56:
	.dbline 277
;     }
;     *ptr = I2C_Receive_Byte();
	xcall _I2C_Receive_Byte
	movw R30,R20
	std z+0,R16
	.dbline 278
;     I2C_Ack(1);
	ldi R16,1
	xcall _I2C_Ack
	.dbline 279
;     I2C_Stop_Condition();
	xcall _I2C_Stop_Condition
	.dbline 280
;     return(1);
	ldi R16,1
	.dbline -2
L55:
	xcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r ptr 20 pc
	.dbsym r bDevice 22 c
	.dbend
	.dbfunc e I2C_Recive_String_with_SubAddress _I2C_Recive_String_with_SubAddress fc
;            cnt -> R20
;        bLength -> R22
;            ptr -> R10,R11
;       bAddress -> R14
;        bDevice -> R12
	.even
_I2C_Recive_String_with_SubAddress::
	xcall push_gset5
	mov R14,R18
	mov R12,R16
	ldd R10,y+10
	ldd R11,y+11
	ldd R22,y+12
	.dbline -1
	.dbline 292
; }
; 
; //***************************************************************
; // Function    : I2C_Recive_String_with_AddressIRcvStr
; // Input       : bDevice  - Slave Device with a I2C Address,
; //               bAddress - SubAddress of the Slave,
; //               ptr      - Pointer to the receive data buffter 
; // Output      : I2C Operation Status - Success(1)/Fail(0)
; // Description : Receive N data from Slave with SubAddress
; //***************************************************************
; INT8U I2C_Recive_String_with_SubAddress(INT8U bDevice,INT8U bAddress,INT8U *ptr,INT8U bLength)
; {
	.dbline 293
; 	INT8U cnt = 0;
	clr R20
	.dbline 294
; 	I2C_Start_Condition();
	xcall _I2C_Start_Condition
	.dbline 295
; 	I2C_Send_Byte(bDevice);
	mov R16,R12
	xcall _I2C_Send_Byte
	.dbline 296
; 	if(bI2C_Ack == 0)
	lds R2,_bI2C_Ack
	tst R2
	brne L59
	.dbline 297
; 	{
	.dbline 298
; 		return(0);
	clr R16
	xjmp L58
L59:
	.dbline 300
; 	}
; 	I2C_Send_Byte(bAddress);
	mov R16,R14
	xcall _I2C_Send_Byte
	.dbline 301
;     if(bI2C_Ack == 0)
	lds R2,_bI2C_Ack
	tst R2
	brne L61
	.dbline 302
; 	{
	.dbline 303
; 		return(0);
	clr R16
	xjmp L58
L61:
	.dbline 305
; 	}
; 	I2C_Start_Condition();
	xcall _I2C_Start_Condition
	.dbline 306
; 	I2C_Send_Byte(bDevice | 0x01);
	mov R16,R12
	ori R16,1
	xcall _I2C_Send_Byte
	.dbline 307
; 	if(bI2C_Ack == 0)
	lds R2,_bI2C_Ack
	tst R2
	brne L63
	.dbline 308
; 	{
	.dbline 309
; 		return(0);
	clr R16
	xjmp L58
L63:
	.dbline 311
; 	}
; 	for(cnt = 0;cnt < bLength - 1;cnt++)
	clr R20
	xjmp L68
L65:
	.dbline 312
	.dbline 313
	xcall _I2C_Receive_Byte
	movw R30,R10
	st Z+,R16
	movw R10,R30
	.dbline 314
	clr R16
	xcall _I2C_Ack
	.dbline 315
L66:
	.dbline 311
	inc R20
L68:
	.dbline 311
	mov R24,R22
	subi R24,1
	cp R20,R24
	brlo L65
	.dbline 316
; 	{
; 		*ptr++ = I2C_Receive_Byte();
; 		I2C_Ack(0);
; 	}
; 	*ptr = I2C_Receive_Byte();
	xcall _I2C_Receive_Byte
	movw R30,R10
	std z+0,R16
	.dbline 317
; 	I2C_Ack(1);
	ldi R16,1
	xcall _I2C_Ack
	.dbline 318
; 	I2C_Stop_Condition();
	xcall _I2C_Stop_Condition
	.dbline 319
; 	return(1);
	ldi R16,1
	.dbline -2
L58:
	xcall pop_gset5
	.dbline 0 ; func end
	ret
	.dbsym r cnt 20 c
	.dbsym r bLength 22 c
	.dbsym r ptr 10 pc
	.dbsym r bAddress 14 c
	.dbsym r bDevice 12 c
	.dbend

⌨️ 快捷键说明

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