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

📄 i2c_demo.as

📁 用PIC16F73编写的SMBUS通信测试程序
💻 AS
📖 第 1 页 / 共 2 页
字号:
;i2c.c: 153: }
	return

	psect	text7
;i2c.c: 160: void
;i2c.c: 161: i2c_SendAcknowledge(unsigned char status)
;i2c.c: 162: {
_i2c_SendAcknowledge
;i2c.c: 163: TRISC3 = 0;
	bsf	3,5
	bcf	3,6	;carry unused
	bcf	7,3
;i2c.c: 164: if ( status & 0x01) {
;	_status assigned to ?a_i2c_SendAcknowledge+0
_i2c_SendAcknowledge$status	set	?a_i2c_SendAcknowledge
;_status stored from w
	bcf	3,5
	movwf	?a_i2c_SendAcknowledge
	btfss	?a_i2c_SendAcknowledge,0
	goto	l65
;i2c.c: 165: TRISC4 = 0;
	bsf	3,5
	bcf	7,4
;i2c.c: 166: }
;i2c.c: 167: else {
	goto	l66
l65
;i2c.c: 168: TRISC4 = 1;
	bsf	3,5
	bcf	3,6	;carry unused
	bsf	7,4
;i2c.c: 169: }
l66
;i2c.c: 170: { unsigned char _dcnt; _dcnt = (1)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_SendAcknowledge+1
_i2c_SendAcknowledge$_dcnt	set	?a_i2c_SendAcknowledge+1
	bcf	3,5
	clrf	?a_i2c_SendAcknowledge+1
	incf	?a_i2c_SendAcknowledge+1
l68
	decfsz	?a_i2c_SendAcknowledge+1
	goto	l68
;i2c.c: 171: TRISC3 = 1;
	bsf	3,5
	bsf	7,3
;i2c.c: 172: { unsigned char _dcnt; _dcnt = (4)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_SendAcknowledge+1
_i2c_SendAcknowledge$_dcnt	set	?a_i2c_SendAcknowledge+1
	bcf	3,5
	clrf	?a_i2c_SendAcknowledge+1
	incf	?a_i2c_SendAcknowledge+1
l71
	decfsz	?a_i2c_SendAcknowledge+1
	goto	l71
;i2c.c: 173: return;
;i2c.c: 174: }
	return

	psect	text8
;i2c.c: 181: signed char
;i2c.c: 182: i2c_PutByte(unsigned char data)
;i2c.c: 183: {
_i2c_PutByte
;i2c.c: 184: if(i2c_SendByte(data))
;	_data assigned to ?a_i2c_PutByte+0
_i2c_PutByte$data	set	?a_i2c_PutByte
;_data stored from w
	clrf	3	;select bank 0
	movwf	?a_i2c_PutByte
	fcall	_i2c_SendByte
	iorlw	0
	btfsc	3,2
	goto	l74
;i2c.c: 185: return (-1);
	movlw	-1
	goto	l73
;i2c.c: 186: return i2c_ReadAcknowledge();
l74
	fcall	_i2c_ReadAcknowledge
;i2c.c: 187: }
l73
	clrf	3	;select bank 0
	return

	psect	text9
;i2c.c: 194: int
;i2c.c: 195: i2c_GetByte(unsigned char more)
;i2c.c: 196: {
_i2c_GetByte
;i2c.c: 197: int byte;
;	_byte assigned to ?a_i2c_GetByte+0
_i2c_GetByte$byte	set	?a_i2c_GetByte
;i2c.c: 199: if((byte = i2c_ReadByte()) == (-1))
;	_more assigned to ?a_i2c_GetByte+2
_i2c_GetByte$more	set	?a_i2c_GetByte+2
;_more stored from w
	clrf	3	;select bank 0
	movwf	?a_i2c_GetByte+2
	fcall	_i2c_ReadByte
	movf	btemp,w
	movwf	?a_i2c_GetByte
	movf	btemp+1,w
	movwf	?a_i2c_GetByte+1
	incf	?a_i2c_GetByte,w
	btfsc	3,2
	incf	?a_i2c_GetByte+1,w
	btfss	3,2
	goto	l76
;i2c.c: 200: return (-1);
	movlw	255
	movwf	btemp
	movwf	btemp+1
	goto	l75
;i2c.c: 202: i2c_SendAcknowledge(more);
l76
	bcf	3,5
	bcf	3,6	;carry unused
	movf	?a_i2c_GetByte+2,w
	fcall	_i2c_SendAcknowledge
;i2c.c: 204: return byte;
	movf	?a_i2c_GetByte+1,w
	movwf	btemp+1
	movf	?a_i2c_GetByte,w
	movwf	btemp
;i2c.c: 205: }
l75
	clrf	3	;select bank 0
	return

	psect	text10
_i2c_PutString
;i2c.c: 215: signed char error;
;	_error assigned to ?a_i2c_PutString+0
_i2c_PutString$error	set	?a_i2c_PutString
;i2c.c: 217: while(length)
	goto	l78
l79
;i2c.c: 218: {
;i2c.c: 219: if((error = i2c_PutByte(*str)) == (-1))
	bcf	3,5
	bcf	3,6	;carry unused
	movf	?_i2c_PutString+1,w
	movwf	code_ptr+1
	movf	?_i2c_PutString,w
	fcall	string_table
	fcall	_i2c_PutByte
	movwf	?a_i2c_PutString
	incfsz	?a_i2c_PutString,w
	goto	l81
;i2c.c: 220: return -(int)length;
	movf	?_i2c_PutString+2,w
	movwf	btemp
	clrf	btemp+1
	comf	btemp
	comf	btemp+1
	incf	btemp
	btfsc	3,2
	incf	btemp+1
	goto	l77
;i2c.c: 221: else
l81
;i2c.c: 222: if(error)
	bcf	3,5
	bcf	3,6	;carry unused
	movf	?a_i2c_PutString
	btfsc	3,2
	goto	l83
;i2c.c: 223: return (int)length;
	movf	?_i2c_PutString+2,w
	movwf	btemp
	goto	L2
;i2c.c: 224: str++;
l83
	incf	?_i2c_PutString
	btfsc	3,2
	incf	?_i2c_PutString+1
;i2c.c: 225: length--;
	decf	?_i2c_PutString+2
;i2c.c: 226: }
l78
	bcf	3,5
	bcf	3,6	;carry unused
	movf	?_i2c_PutString+2
	btfss	3,2
	goto	l79
;i2c.c: 228: return 0;
	clrf	btemp
L2
	clrf	btemp+1
;i2c.c: 229: }
l77
	clrf	3	;select bank 0
	return

	psect	text11
_i2c_GetString
;i2c.c: 239: int byte;
;	_byte assigned to ?a_i2c_GetString+0
_i2c_GetString$byte	set	?a_i2c_GetString
;i2c.c: 241: while(number)
;	_str assigned to ?a_i2c_GetString+2
_i2c_GetString$str	set	?a_i2c_GetString+2
;_str stored from w
	clrf	3	;select bank 0
	movwf	?a_i2c_GetString+2
	goto	l85
l86
;i2c.c: 242: {
;i2c.c: 243: if((byte = i2c_GetByte(number-1)) == (-1))
	bcf	3,5
	bcf	3,6	;carry unused
	decf	?_i2c_GetString,w
	fcall	_i2c_GetByte
	movf	btemp,w
	movwf	?a_i2c_GetString
	movf	btemp+1,w
	movwf	?a_i2c_GetString+1
	incf	?a_i2c_GetString,w
	btfsc	3,2
	incf	?a_i2c_GetString+1,w
	btfss	3,2
	goto	l88
;i2c.c: 244: return number;
	movf	?_i2c_GetString,w
	goto	l84
;i2c.c: 245: else
l88
;i2c.c: 246: *str = (unsigned char)byte;
	bcf	3,5
	bcf	3,6	;carry unused
	movf	?a_i2c_GetString+2,w
	movwf	4
	bcf	3,7
	movf	?a_i2c_GetString,w
	movwf	0
;i2c.c: 247: str++;
	bcf	3,5
	bcf	3,6	;carry unused
	incf	?a_i2c_GetString+2
;i2c.c: 248: number--;
	decf	?_i2c_GetString
;i2c.c: 249: }
l85
	movf	?_i2c_GetString
	btfss	3,2
	goto	l86
;i2c.c: 251: return 0;
	movlw	0
;i2c.c: 252: }
l84
	clrf	3	;select bank 0
	return

	psect	text12
_i2c_Open
;i2c.c: 263: i2c_Restart();
	fcall	_i2c_Restart
;i2c.c: 264: i2c_SendAddress(address, mode);
;	_address assigned to ?a_i2c_Open+0
_i2c_Open$address	set	?a_i2c_Open
;_address stored from w
	movwf	?a_i2c_Open
	movf	?_i2c_Open,w
	movwf	?_i2c_SendAddress
	movf	?a_i2c_Open,w
	fcall	_i2c_SendAddress
;i2c.c: 265: if(i2c_ReadAcknowledge())
	fcall	_i2c_ReadAcknowledge
	iorlw	0
	btfsc	3,2
	goto	l91
;i2c.c: 266: return !0;
	movlw	1
	goto	l90
;i2c.c: 268: return 0;
l91
	movlw	0
;i2c.c: 269: }
l90
	clrf	3	;select bank 0
	return

	psect	text13
;i2c.c: 278: unsigned char
;i2c.c: 279: i2c_WaitForSCL(void)
;i2c.c: 280: {
_i2c_WaitForSCL
;i2c.c: 283: if(!RC3)
	clrf	3	;select bank 0
	btfsc	7,3
	retlw	0
;i2c.c: 284: {
;i2c.c: 285: { unsigned char _dcnt; _dcnt = (10)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_WaitForSCL+0
_i2c_WaitForSCL$_dcnt	set	?a_i2c_WaitForSCL
	movlw	3
	movwf	?a_i2c_WaitForSCL
l95
	bcf	3,5
	bcf	3,6	;carry unused
	decfsz	?a_i2c_WaitForSCL
	goto	l95
;i2c.c: 287: if(!RC3)
	btfss	7,3
;i2c.c: 288: return !0;
	retlw	1
;i2c.c: 289: }
;i2c.c: 290: return 0;
	retlw	0

	psect	text14
;i2c.c: 292: void
;i2c.c: 293: i2c_Free()
;i2c.c: 294: {
_i2c_Free
;i2c.c: 295: unsigned char ucI;
;	_ucI assigned to ?a_i2c_Free+0
_i2c_Free$ucI	set	?a_i2c_Free
;i2c.c: 297: TRISC4=1;
	bsf	3,5
	bcf	3,6	;carry unused
	bsf	7,4
;i2c.c: 298: for(ucI=0;ucI!=9;ucI++)
	bcf	3,5
	clrf	?a_i2c_Free
	movf	?a_i2c_Free,w
	xorlw	9
	btfsc	3,2
	return
;i2c.c: 299: {
l99
;i2c.c: 300: TRISC3 = 1;
	bsf	3,5
	bcf	3,6	;carry unused
	bsf	7,3
;i2c.c: 301: { unsigned char _dcnt; _dcnt = (5)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_Free+1
_i2c_Free$_dcnt	set	?a_i2c_Free+1
	bcf	3,5
	clrf	?a_i2c_Free+1
	incf	?a_i2c_Free+1
l103
	decfsz	?a_i2c_Free+1
	goto	l103
;i2c.c: 302: TRISC3 = 0;
	bsf	3,5
	bcf	7,3
;i2c.c: 303: { unsigned char _dcnt; _dcnt = (5)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_Free+1
_i2c_Free$_dcnt	set	?a_i2c_Free+1
	bcf	3,5
	clrf	?a_i2c_Free+1
	incf	?a_i2c_Free+1
l106
	decfsz	?a_i2c_Free+1
	goto	l106
;i2c.c: 304: }
	incf	?a_i2c_Free
	movf	?a_i2c_Free,w
	xorlw	9
	btfsc	3,2
;i2c.c: 305: }
	return
	goto	l99

	psect	text15
;i2c.c: 307: unsigned char i2c_read(unsigned char ucAdr)
;i2c.c: 308: {
_i2c_read
;i2c.c: 309: unsigned char ucDat;
;	_ucDat assigned to ?a_i2c_read+0
_i2c_read$ucDat	set	?a_i2c_read
;i2c.c: 311: if (i2c_Open((ucAdr), 0x01)==0)
;	_ucAdr assigned to ?a_i2c_read+1
_i2c_read$ucAdr	set	?a_i2c_read+1
;_ucAdr stored from w
	clrf	3	;select bank 0
	movwf	?a_i2c_read+1
	clrf	?_i2c_Open
	incf	?_i2c_Open
	fcall	_i2c_Open
	movwf	btemp
	clrf	btemp+1
	iorwf	btemp+1,w
	btfss	3,2
	goto	l109
;i2c.c: 312: {
;i2c.c: 313: ucDat=i2c_GetByte(!0);
	movlw	1
	fcall	_i2c_GetByte
	movf	btemp,w
	movwf	?a_i2c_read
;i2c.c: 314: i2c_Stop();
	fcall	_i2c_Stop
;i2c.c: 316: }
;i2c.c: 318: return(ucDat);
l109
	bcf	3,5
	bcf	3,6	;carry unused
	movf	?a_i2c_read,w
;i2c.c: 319: }
	return

	psect	text16
;I2C_DEMO.C: 12: void flashled(void) {
_flashled
;I2C_DEMO.C: 13: while(1) {
l112
;I2C_DEMO.C: 14: RB0 = 1;
	clrf	3	;select bank 0
	bsf	6,0
;I2C_DEMO.C: 15: DelayMs(200);
	movlw	-56
	fcall	_DelayMs
;I2C_DEMO.C: 16: RB0 = 0;
	bcf	6,0
;I2C_DEMO.C: 17: DelayMs(200);
	movlw	-56
	fcall	_DelayMs
;I2C_DEMO.C: 18: }
	goto	l112

	psect	text17
_WriteByte
;I2C_DEMO.C: 23: i2c_Open((0x16), 0x00);
	clrf	3	;select bank 0
	clrf	?_i2c_Open
;	_addr assigned to ?a_WriteByte+0
_WriteByte$addr	set	?a_WriteByte
;_addr stored from w
	movwf	?a_WriteByte
	movlw	22
	fcall	_i2c_Open
;I2C_DEMO.C: 24: if (i2c_PutByte(addr)==(-1))
	movf	?a_WriteByte,w
	fcall	_i2c_PutByte
	movwf	btemp
	incfsz	btemp,w
	goto	l115
;I2C_DEMO.C: 25: flashled();
	fcall	_flashled
;I2C_DEMO.C: 26: if (i2c_PutByte(byte)==(-1))
l115
	bcf	3,5
	bcf	3,6	;carry unused
	movf	?_WriteByte,w
	fcall	_i2c_PutByte
	movwf	btemp
	incfsz	btemp,w
	goto	l116
;I2C_DEMO.C: 27: flashled();
	fcall	_flashled
;I2C_DEMO.C: 28: }
l116
	clrf	3	;select bank 0
	return

	psect	text18
;I2C_DEMO.C: 30: int ReadByte(unsigned char addr) {
_ReadByte
;I2C_DEMO.C: 31: i2c_Open((0x16), 0x00);
	clrf	3	;select bank 0
	clrf	?_i2c_Open
;	_addr assigned to ?a_ReadByte+0
_ReadByte$addr	set	?a_ReadByte
;_addr stored from w
	movwf	?a_ReadByte
	movlw	22
	fcall	_i2c_Open
;I2C_DEMO.C: 32: if (i2c_PutByte(addr)==(-1))
	movf	?a_ReadByte,w
	fcall	_i2c_PutByte
	movwf	btemp
	incfsz	btemp,w
	goto	l118
;I2C_DEMO.C: 33: flashled();
	fcall	_flashled
;I2C_DEMO.C: 34: i2c_Open((0x16), 0x01);
l118
	bcf	3,5
	bcf	3,6	;carry unused
	clrf	?_i2c_Open
	incf	?_i2c_Open
	movlw	22
	fcall	_i2c_Open
;I2C_DEMO.C: 35: return i2c_GetByte(0);
	movlw	0
	ljmp	_i2c_GetByte

	psect	text19
;I2C_DEMO.C: 38: static unsigned long remain,remain1;
;I2C_DEMO.C: 40: void main(void) {
_main
;I2C_DEMO.C: 41: unsigned char count,val;
;	_count assigned to ?a_main+0
_main$count	set	?a_main
;	_val assigned to ?a_main+1
_main$val	set	?a_main+1
;I2C_DEMO.C: 43: TRISB=0;
	bsf	3,5
	bcf	3,6	;carry unused
	clrf	6	;volatile
;I2C_DEMO.C: 44: PORTB=0;
	bcf	3,5
	clrf	6	;volatile
;I2C_DEMO.C: 45: RB0=0;
	bcf	6,0
;I2C_DEMO.C: 46: remain=0x0190;
	movlw	144
	movwf	_remain
	movlw	1
	movwf	_remain+1
	clrf	_remain+2
	clrf	_remain+3
;I2C_DEMO.C: 49: SSPCON &=0xF0; SSPCON|=(0B1011 & 0xf);
	movlw	-16
	andwf	20	;volatile
	movlw	11
	iorwf	20	;volatile
;I2C_DEMO.C: 50: SSPEN = 1;
	bsf	20,5
;I2C_DEMO.C: 51: CKP = 1;
	bsf	20,4
;I2C_DEMO.C: 60: while(1) {
l121
;I2C_DEMO.C: 68: remain=0;
	clrf	_remain
	clrf	_remain+1
	clrf	_remain+2
	clrf	_remain+3
;I2C_DEMO.C: 69: count=0x19;
	movlw	25
	movwf	?a_main
;I2C_DEMO.C: 70: remain=ReadByte(count);
	fcall	_ReadByte
	movf	btemp,w
	movf	btemp+1,w
	movlw	0
	btfsc	btemp+1,7
	movlw	255
	movwf	btemp+2
	movwf	btemp+3
	movf	btemp,w
	movwf	_remain
	movf	btemp+1,w
	movwf	_remain+1
	movf	btemp+2,w
	movwf	_remain+2
	movf	btemp+3,w
	movwf	_remain+3
;I2C_DEMO.C: 77: DelayMs(200);
	movlw	-56
	fcall	_DelayMs
;I2C_DEMO.C: 78: }
	goto	l121

	psect	text20

	psect	rbss_0
_remain
	ds	4

	psect	temp
btemp
	ds	4

⌨️ 快捷键说明

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