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

📄 i2c_demo.as

📁 用PIC16F73编写的SMBUS通信测试程序
💻 AS
📖 第 1 页 / 共 2 页
字号:
	global	?_WriteByte
	global	?_i2c_GetString
	global	?_i2c_Open
	global	?_i2c_PutString
	global	?_i2c_SendAddress
	global	?a_DelayMs
	global	?a_ReadByte
	global	?a_WriteByte
	global	?a_i2c_Free
	global	?a_i2c_GetByte
	global	?a_i2c_GetString
	global	?a_i2c_Open
	global	?a_i2c_PutByte
	global	?a_i2c_PutString
	global	?a_i2c_ReadAcknowledge
	global	?a_i2c_ReadByte
	global	?a_i2c_Restart
	global	?a_i2c_SendAcknowledge
	global	?a_i2c_SendAddress
	global	?a_i2c_SendByte
	global	?a_i2c_Stop
	global	?a_i2c_WaitForSCL
	global	?a_i2c_read
	global	?a_main
	global	_DelayMs
	signat	_DelayMs,4216
	FNSIZE	_DelayMs,3,0
	global	_ReadByte
	signat	_ReadByte,4194
	FNSIZE	_ReadByte,1,0
	FNCALL	_ReadByte,_i2c_Open
	FNCALL	_ReadByte,_i2c_PutByte
	FNCALL	_ReadByte,_flashled
	FNCALL	_ReadByte,_i2c_GetByte
	global	_WriteByte
	signat	_WriteByte,8312
	FNSIZE	_WriteByte,1,1
	FNCALL	_WriteByte,_i2c_Open
	FNCALL	_WriteByte,_i2c_PutByte
	FNCALL	_WriteByte,_flashled
	global	_flashled
	signat	_flashled,88
	FNCALL	_flashled,_DelayMs
	global	_i2c_Free
	signat	_i2c_Free,88
	FNSIZE	_i2c_Free,2,0
	global	_i2c_GetByte
	signat	_i2c_GetByte,4194
	FNSIZE	_i2c_GetByte,3,0
	FNCALL	_i2c_GetByte,_i2c_ReadByte
	FNCALL	_i2c_GetByte,_i2c_SendAcknowledge
	global	_i2c_GetString
	signat	_i2c_GetString,8297
	FNSIZE	_i2c_GetString,3,1
	FNCALL	_i2c_GetString,_i2c_GetByte
	global	_i2c_Open
	signat	_i2c_Open,8297
	FNSIZE	_i2c_Open,1,1
	FNCALL	_i2c_Open,_i2c_Restart
	FNCALL	_i2c_Open,_i2c_SendAddress
	FNCALL	_i2c_Open,_i2c_ReadAcknowledge
	global	_i2c_PutByte
	signat	_i2c_PutByte,4193
	FNSIZE	_i2c_PutByte,1,0
	FNCALL	_i2c_PutByte,_i2c_SendByte
	FNCALL	_i2c_PutByte,_i2c_ReadAcknowledge
	global	_i2c_PutString
	signat	_i2c_PutString,8290
	FNSIZE	_i2c_PutString,1,3
	FNCALL	_i2c_PutString,_i2c_PutByte
	FNCALL	_i2c_PutString,string_table
	global	_i2c_ReadAcknowledge
	signat	_i2c_ReadAcknowledge,65
	FNSIZE	_i2c_ReadAcknowledge,2,0
	FNCALL	_i2c_ReadAcknowledge,_i2c_WaitForSCL
	global	_i2c_ReadByte
	signat	_i2c_ReadByte,66
	FNSIZE	_i2c_ReadByte,3,0
	FNCALL	_i2c_ReadByte,_i2c_WaitForSCL
	global	_i2c_Restart
	signat	_i2c_Restart,88
	FNSIZE	_i2c_Restart,1,0
	global	_i2c_SendAcknowledge
	signat	_i2c_SendAcknowledge,4216
	FNSIZE	_i2c_SendAcknowledge,2,0
	global	_i2c_SendAddress
	signat	_i2c_SendAddress,8297
	FNSIZE	_i2c_SendAddress,1,1
	FNCALL	_i2c_SendAddress,_i2c_SendByte
	global	_i2c_SendByte
	signat	_i2c_SendByte,4201
	FNSIZE	_i2c_SendByte,3,0
	FNCALL	_i2c_SendByte,_i2c_WaitForSCL
	global	_i2c_Stop
	signat	_i2c_Stop,88
	FNSIZE	_i2c_Stop,1,0
	global	_i2c_WaitForSCL
	signat	_i2c_WaitForSCL,73
	FNSIZE	_i2c_WaitForSCL,1,0
	global	_i2c_read
	signat	_i2c_read,4201
	FNSIZE	_i2c_read,2,0
	FNCALL	_i2c_read,_i2c_Open
	FNCALL	_i2c_read,_i2c_GetByte
	FNCALL	_i2c_read,_i2c_Stop
	global	_main
	signat	_main,88
	FNSIZE	_main,2,0
	FNCALL	_main,_ReadByte
	FNCALL	_main,_DelayMs
	global	clear_bank0
	global	code_ptr
	global	start
	global	string_table
	global	used_btemp0
	global	used_btemp1
	global	used_btemp2
	global	used_btemp3
	global	used_code_ptr
	processor	16C76
	psect	__Z11111RS_,global
	psect	text0,local,class=CODE,delta=2
	psect	text1,local,class=CODE,delta=2
	psect	text2,local,class=CODE,delta=2
	psect	text3,local,class=CODE,delta=2
	psect	text4,local,class=CODE,delta=2
	psect	text5,local,class=CODE,delta=2
	psect	text6,local,class=CODE,delta=2
	psect	text7,local,class=CODE,delta=2
	psect	text8,local,class=CODE,delta=2
	psect	text9,local,class=CODE,delta=2
	psect	text10,local,class=CODE,delta=2
	psect	text11,local,class=CODE,delta=2
	psect	text12,local,class=CODE,delta=2
	psect	text13,local,class=CODE,delta=2
	psect	text14,local,class=CODE,delta=2
	psect	text15,local,class=CODE,delta=2
	psect	text16,local,class=CODE,delta=2
	psect	text17,local,class=CODE,delta=2
	psect	text18,local,class=CODE,delta=2
	psect	text19,local,class=CODE,delta=2
	psect	text20,local,class=CODE,delta=2
	psect	rbss_0,global,class=BANK0,space=1
	psect	temp,global,ovrld,class=BANK0,space=1
	file	"C:\DOCUME~1\ww\LOCALS~1\Temp\_294.AAB"


	psect	__Z11111RS_

	psect	text0
_DelayMs
;delay.c: 20: unsigned char i;
;	_i assigned to ?a_DelayMs+0
_DelayMs$i	set	?a_DelayMs
;delay.c: 21: do {
;	_cnt assigned to ?a_DelayMs+1
_DelayMs$cnt	set	?a_DelayMs+1
;_cnt stored from w
	clrf	3	;select bank 0
	movwf	?a_DelayMs+1
l4
;delay.c: 22: i = 4;
	movlw	4
	movwf	?a_DelayMs
;delay.c: 23: do {
l7
;delay.c: 24: { unsigned char _dcnt; _dcnt = (250)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_DelayMs+2
_DelayMs$_dcnt	set	?a_DelayMs+2
	movlw	83
	movwf	?a_DelayMs+2
l9
	bcf	3,5
	bcf	3,6	;carry unused
	decfsz	?a_DelayMs+2
	goto	l9
;delay.c: 25: } while(--i);
	decfsz	?a_DelayMs
	goto	l7
;delay.c: 26: } while(--cnt);
	decfsz	?a_DelayMs+1
	goto	l4
	return

	psect	text1
;delay.h: 50: extern void DelayMs(unsigned char);
;i2c.c: 19: void
;i2c.c: 20: i2c_Stop(void)
;i2c.c: 21: {
_i2c_Stop
;i2c.c: 24: TRISC4 = 0;
	bsf	3,5
	bcf	3,6	;carry unused
	bcf	7,4
;i2c.c: 25: TRISC3 = 1;
	bsf	7,3
;i2c.c: 27: { unsigned char _dcnt; _dcnt = (1)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_Stop+0
_i2c_Stop$_dcnt	set	?a_i2c_Stop
	bcf	3,5
	clrf	?a_i2c_Stop
	incf	?a_i2c_Stop
l12
	decfsz	?a_i2c_Stop
	goto	l12
;i2c.c: 28: TRISC3 = 1;
	bsf	3,5
	bsf	7,3
;i2c.c: 29: { unsigned char _dcnt; _dcnt = (4)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_Stop+0
_i2c_Stop$_dcnt	set	?a_i2c_Stop
	bcf	3,5
	clrf	?a_i2c_Stop
	incf	?a_i2c_Stop
l16
	decfsz	?a_i2c_Stop
	goto	l16
;i2c.c: 30: TRISC4 = 1;
	bsf	3,5
	bsf	7,4
;i2c.c: 31: { unsigned char _dcnt; _dcnt = (5)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_Stop+0
_i2c_Stop$_dcnt	set	?a_i2c_Stop
	bcf	3,5
	clrf	?a_i2c_Stop
	incf	?a_i2c_Stop
l19
	decfsz	?a_i2c_Stop
	goto	l19
;i2c.c: 32: TRISC4 = 1;
	bsf	3,5
	bsf	7,4
;i2c.c: 34: return;
;i2c.c: 35: }
	clrf	3	;select bank 0
	return

	psect	text2
;i2c.c: 43: void
;i2c.c: 44: i2c_Restart(void)
;i2c.c: 45: {
_i2c_Restart
;i2c.c: 46: TRISC3 = 0;
	bsf	3,5
	bcf	3,6	;carry unused
	bcf	7,3
;i2c.c: 47: TRISC4 = 1;
	bsf	7,4
;i2c.c: 49: { unsigned char _dcnt; _dcnt = (1)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_Restart+0
_i2c_Restart$_dcnt	set	?a_i2c_Restart
	bcf	3,5
	clrf	?a_i2c_Restart
	incf	?a_i2c_Restart
l22
	decfsz	?a_i2c_Restart
	goto	l22
;i2c.c: 51: TRISC3 = 1;
	bsf	3,5
	bsf	7,3
;i2c.c: 52: { unsigned char _dcnt; _dcnt = (4)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_Restart+0
_i2c_Restart$_dcnt	set	?a_i2c_Restart
	bcf	3,5
	clrf	?a_i2c_Restart
	incf	?a_i2c_Restart
l26
	decfsz	?a_i2c_Restart
	goto	l26
;i2c.c: 54: TRISC4 = 0;
	bsf	3,5
	bcf	7,4
;i2c.c: 55: { unsigned char _dcnt; _dcnt = (4)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_Restart+0
_i2c_Restart$_dcnt	set	?a_i2c_Restart
	bcf	3,5
	clrf	?a_i2c_Restart
	incf	?a_i2c_Restart
l29
	decfsz	?a_i2c_Restart
	goto	l29
;i2c.c: 56: return;
;i2c.c: 57: }
	return

	psect	text3
;i2c.c: 64: unsigned char
;i2c.c: 65: i2c_SendByte(unsigned char byte)
;i2c.c: 66: {
_i2c_SendByte
;i2c.c: 67: signed char i;
;	_i assigned to ?a_i2c_SendByte+0
_i2c_SendByte$i	set	?a_i2c_SendByte
;i2c.c: 69: for(i=7; i>=0; i--)
;	_byte assigned to ?a_i2c_SendByte+1
_i2c_SendByte$byte	set	?a_i2c_SendByte+1
;_byte stored from w
	clrf	3	;select bank 0
	movwf	?a_i2c_SendByte+1
	movlw	7
	movwf	?a_i2c_SendByte
	btfsc	?a_i2c_SendByte,7
	goto	l33
;i2c.c: 70: {
l32
;i2c.c: 71: TRISC3 = 0;
	bsf	3,5
	bcf	3,6	;carry unused
	bcf	7,3
;i2c.c: 73: TRISC4 = ((byte>>i)&0x01);
	bcf	3,5
	movf	?a_i2c_SendByte+1,w
	movwf	btemp
	movf	?a_i2c_SendByte,w
	movwf	btemp+1
	incf	btemp+1
	goto	u114
u115
	bcf	3,0
	rrf	btemp
u114
	decfsz	btemp+1
	goto	u115
	movf	btemp,w
	movwf	btemp
	rrf	btemp,w
	bsf	3,5
	btfss	3,0
	goto	L1
	bsf	7,4
	goto	u134
L1
	bcf	7,4
u134
;i2c.c: 74: if ((byte>>i)&0x01) {
	bcf	3,5
	bcf	3,6	;carry unused
	movf	?a_i2c_SendByte+1,w
	movwf	btemp
	movf	?a_i2c_SendByte,w
	movwf	btemp+1
	incf	btemp+1
	goto	u144
u145
	bcf	3,0
	rrf	btemp
u144
	decfsz	btemp+1
	goto	u145
	movf	btemp,w
	movwf	btemp
	btfss	btemp,0
	goto	l35
;i2c.c: 75: TRISC4 = 1;
	bsf	3,5
	bsf	7,4
;i2c.c: 76: }
;i2c.c: 77: else {
	goto	l36
l35
;i2c.c: 78: TRISC4 = 0;
	bsf	3,5
	bcf	3,6	;carry unused
	bcf	7,4
;i2c.c: 79: }
l36
;i2c.c: 80: { unsigned char _dcnt; _dcnt = (1)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_SendByte+2
_i2c_SendByte$_dcnt	set	?a_i2c_SendByte+2
	bcf	3,5
	bcf	3,6	;carry unused
	clrf	?a_i2c_SendByte+2
	incf	?a_i2c_SendByte+2
l38
	decfsz	?a_i2c_SendByte+2
	goto	l38
;i2c.c: 81: TRISC3 = 1;
	bsf	3,5
	bsf	7,3
;i2c.c: 83: if(i2c_WaitForSCL())
	fcall	_i2c_WaitForSCL
	iorlw	0
	btfsc	3,2
	goto	l40
;i2c.c: 84: return !0;
	movlw	1
	goto	l31
;i2c.c: 86: { unsigned char _dcnt; _dcnt = (4)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
l40
;	__dcnt assigned to ?a_i2c_SendByte+2
_i2c_SendByte$_dcnt	set	?a_i2c_SendByte+2
	bcf	3,5
	bcf	3,6	;carry unused
	clrf	?a_i2c_SendByte+2
	incf	?a_i2c_SendByte+2
l42
	decfsz	?a_i2c_SendByte+2
	goto	l42
;i2c.c: 87: }
	decf	?a_i2c_SendByte
	btfss	?a_i2c_SendByte,7
	goto	l32
l33
;i2c.c: 90: return 0;
	movlw	0
;i2c.c: 91: }
l31
	clrf	3	;select bank 0
	return

	psect	text4
_i2c_SendAddress
;i2c.c: 102: return i2c_SendByte(address | (rw?1:0));
;	_address assigned to ?a_i2c_SendAddress+0
_i2c_SendAddress$address	set	?a_i2c_SendAddress
;_address stored from w
	clrf	3	;select bank 0
	movwf	?a_i2c_SendAddress
	movf	?_i2c_SendAddress
	movlw	0
	btfss	3,2
	movlw	1
	iorwf	?a_i2c_SendAddress,w
	ljmp	_i2c_SendByte
;i2c.c: 103: }
	return

	psect	text5
;i2c.c: 110: signed char
;i2c.c: 111: i2c_ReadAcknowledge(void)
;i2c.c: 112: {
_i2c_ReadAcknowledge
;i2c.c: 113: unsigned char ack;
;	_ack assigned to ?a_i2c_ReadAcknowledge+0
_i2c_ReadAcknowledge$ack	set	?a_i2c_ReadAcknowledge
;i2c.c: 115: TRISC3 = 0;
	bsf	3,5
	bcf	3,6	;carry unused
	bcf	7,3
;i2c.c: 116: TRISC4 = 1;
	bsf	7,4
;i2c.c: 117: { unsigned char _dcnt; _dcnt = (4)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_ReadAcknowledge+1
_i2c_ReadAcknowledge$_dcnt	set	?a_i2c_ReadAcknowledge+1
	bcf	3,5
	clrf	?a_i2c_ReadAcknowledge+1
	incf	?a_i2c_ReadAcknowledge+1
l46
	decfsz	?a_i2c_ReadAcknowledge+1
	goto	l46
;i2c.c: 118: TRISC3 = 1;
	bsf	3,5
	bsf	7,3
;i2c.c: 119: { unsigned char _dcnt; _dcnt = (1)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_ReadAcknowledge+1
_i2c_ReadAcknowledge$_dcnt	set	?a_i2c_ReadAcknowledge+1
	bcf	3,5
	clrf	?a_i2c_ReadAcknowledge+1
	incf	?a_i2c_ReadAcknowledge+1
l50
	decfsz	?a_i2c_ReadAcknowledge+1
	goto	l50
;i2c.c: 120: ack = RC4;
	movlw	0
	btfsc	7,4
	movlw	1
	movwf	?a_i2c_ReadAcknowledge
;i2c.c: 123: if(i2c_WaitForSCL())
	fcall	_i2c_WaitForSCL
	iorlw	0
	btfsc	3,2
	goto	l52
;i2c.c: 124: return (-1);
	movlw	-1
	goto	l45
;i2c.c: 125: return ack;
l52
	bcf	3,5
	bcf	3,6	;carry unused
	movf	?a_i2c_ReadAcknowledge,w
;i2c.c: 126: }
l45
	clrf	3	;select bank 0
	return

	psect	text6
;i2c.c: 133: int
;i2c.c: 134: i2c_ReadByte(void)
;i2c.c: 135: {
_i2c_ReadByte
;i2c.c: 136: unsigned char i;
;	_i assigned to ?a_i2c_ReadByte+0
_i2c_ReadByte$i	set	?a_i2c_ReadByte
;i2c.c: 137: unsigned char byte = 0;
;	_byte assigned to ?a_i2c_ReadByte+1
_i2c_ReadByte$byte	set	?a_i2c_ReadByte+1
	clrf	3	;select bank 0
	clrf	?a_i2c_ReadByte+1
;i2c.c: 139: for(i=0; i<8; i++)
	clrf	?a_i2c_ReadByte
	movlw	8
	subwf	?a_i2c_ReadByte,w
	btfsc	3,0
	goto	l55
;i2c.c: 140: {
l54
;i2c.c: 141: TRISC3 = 0;
	bsf	3,5
	bcf	3,6	;carry unused
	bcf	7,3
;i2c.c: 142: { unsigned char _dcnt; _dcnt = (5)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
;	__dcnt assigned to ?a_i2c_ReadByte+2
_i2c_ReadByte$_dcnt	set	?a_i2c_ReadByte+2
	bcf	3,5
	clrf	?a_i2c_ReadByte+2
	incf	?a_i2c_ReadByte+2
l58
	decfsz	?a_i2c_ReadByte+2
	goto	l58
;i2c.c: 143: TRISC4 = 1;
	bsf	3,5
	bsf	7,4
;i2c.c: 145: TRISC3 = 1;
	bsf	7,3
;i2c.c: 146: if(i2c_WaitForSCL())
	fcall	_i2c_WaitForSCL
	iorlw	0
	btfsc	3,2
	goto	l60
;i2c.c: 147: return (-1);
	movlw	255
	movwf	btemp
	movwf	btemp+1
	return
;i2c.c: 148: { unsigned char _dcnt; _dcnt = (4)/((12*1000L)/(4*1000L))|1; while(--_dcnt != 0) continue; };
l60
;	__dcnt assigned to ?a_i2c_ReadByte+2
_i2c_ReadByte$_dcnt	set	?a_i2c_ReadByte+2
	bcf	3,5
	bcf	3,6	;carry unused
	clrf	?a_i2c_ReadByte+2
	incf	?a_i2c_ReadByte+2
l62
	decfsz	?a_i2c_ReadByte+2
	goto	l62
;i2c.c: 149: byte = byte << 1;
	bcf	3,0
	bcf	3,5
	bcf	3,6	;carry unused
	rlf	?a_i2c_ReadByte+1
;i2c.c: 150: byte |= RC4;
	movlw	0
	btfsc	7,4
	movlw	1
	iorwf	?a_i2c_ReadByte+1
;i2c.c: 151: }
	incf	?a_i2c_ReadByte
	movlw	8
	subwf	?a_i2c_ReadByte,w
	btfss	3,0
	goto	l54
l55
;i2c.c: 152: return (int)byte;
	movf	?a_i2c_ReadByte+1,w
	movwf	btemp
	clrf	btemp+1

⌨️ 快捷键说明

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