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

📄 smbussubr.asm

📁 8051 ASM source code for MLX90614 tempture sensor
💻 ASM
字号:

 				
						SUBTITLE	"SMBus Comunication Subroutines"  


;**********************************************************************************************
;									START CONDITION ON SMBus	
;**********************************************************************************************
;Name:		START_bit
;Function:	Generate START condition on SMBus
;Input:		No
;Output:	No
;Comments:  Refer to "System Managment BUS(SMBus) specification Version 2.0" and
;			AN "SMBus communication with MLX90614"
;**********************************************************************************************
START_bit
	
	_SDA_HIGH			; Set _SDA line
	MOVLW 	TBUF		;
	CALL  	delay		; Wait a few us
	_SCL_HIGH			; Set _SCL line
	
	MOVLW 	TBUF		; Generate bus free time between Stop
	CALL  	delay		; and Start condition (Tbuf=4.7us min)
		
	_SDA_LOW			; Clear _SDA line
	MOVLW 	TBUF		; Hold time after (Repeated) Start
    CALL  	delay		; Condition. After this period, the first clock is generated.
    					;(Thd:sta=4.0us min)
    _SCL_LOW			; Clear _SCL line
    
	MOVLW	TBUF		;
	CALL	delay		; Wait a few us	
										
    RETLW 0													
;**********************************************************************************************
;									STOP CONDITION ON SMBus	
;**********************************************************************************************
;Name:		STOPbit
;Function:	Generate STOP condition on SMBus
;Input:		No
;Output:	No
;Comments:  Refer to "System Managment BUS(SMBus) specification Version 2.0" and
;			AN "SMBus communication with MLX90614"
;
;   _______         ___
; SDA      |_______|
;
;
;   __          _______
; SCL |________|
;
;**********************************************************************************************	
STOP_bit

	_SCL_LOW				; Clear _SCL line
	MOVLW 	TBUF			; 
	CALL  	delay			; Wait a few us
	_SDA_LOW				; Clear _SDA line
	
	MOVLW	TBUF			;
	CALL	delay			; Wait a few us
	
	_SCL_HIGH				; Set _SCL line			
	MOVLW	TBUF	    	; Stop condition setup time 
	CALL	delay	    	; (Tsu:sto=4.0us min)
	_SDA_HIGH				; Set _SDA line
	
;	MOVLW 	d'1'			; 
;	CALL  	delay			; Add delay 4us@4MHz
	
	RETLW 	0													
;**********************************************************************************************
;									TRANSMIT DATA ON SMBus	
;**********************************************************************************************
;Name:		TX_byte
;Function:	Send a byte on SMBus
;Input:		W
;Output:	W
;Comments:  If slave send acknowledge W=0, else W=1
;**********************************************************************************************
TX_byte
	MOVWF	TX_buffer
	MOVWF	TX_temp				; Tx_buffer -> Tx_temp
	
TX_again
	MOVLW	D'8'
	MOVWF	Bit_counter			; Load Bit_counter
tx_loop
	BCF		bit_out				; 0 -> bit_out
	RLF		TX_buffer,F			; Tx_buffer<MSb> -> C
	BTFSC	STATUS,C			; C is 0 or 1?	If C=0 don抰 set bit_out
	BSF		bit_out				; 1 -> bit_out
	CALL	Send_bit			; Send bit_out	 on _SDA line
	DECFSZ	Bit_counter,F		; All 8th bits are sent? If not, send next bit ,else check for 
              				    ; acknowledgement from the receiver
	GOTO	tx_loop				; Send next bit
	CALL	Receive_bit			; Check for acknowledgement from the receiver
	BTFSS	bit_in				; Receiver send ACK?
	RETLW 	0					; Yes,return 0
	RETLW	1					; No ,return 1
	   
Send_bit
 	BTFSC	bit_out				;|
 	GOTO	bit_high			;|
 	_SDA_LOW					;|
 	GOTO	clock				; > Send bit on _SDA line
bit_high						;|
	 _SDA_HIGH					;|
	 NOP						;|
	 
clock							
	_SCL_HIGH					;|
	NOP							;|
	NOP							;|
	NOP							;|
	NOP							;|
	NOP							;|
	NOP							;|
	NOP							;|
	NOP							; > Send clock pulse
	NOP							;|
	NOP							;|
	NOP							;|
	NOP							;| 
	NOP							;|
	_SCL_LOW					;|
	NOP							;|
	NOP							;|
	RETLW 	0	
;**********************************************************************************************
;									RECEIVE DATA ON SMBus	
;**********************************************************************************************
;Name:		RX_byte
;Function:	Receive a byte on SMBus
;Input:		No
;Output:	RX_buffer(Received byte)
;Comments:  
;**********************************************************************************************
RX_byte
	CLRF	RX_buffer		; Clear the receiving buffer
	MOVLW	D'8'
	MOVWF	Bit_counter		; Load Bit_counter
	BCF		STATUS,C		; C=0
RX_again
	RLF		RX_buffer,F		; RX_buffer< MSb> -> C
	CALL	Receive_bit		; Check bit on _SDA line	
	BTFSC	bit_in			; If received bit is 

⌨️ 快捷键说明

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