I2c Tool


how to check for the acknowledgement in i2c ?A: use this i2c tool!

I2c search circuit

This programm can be used to search the i2c device address from a i2c bus. The i2c address it's displayed on portb before transmission. The middle leds are blinking when the current address has no acknowlege.


Source code file for I2c Tool
;=======iic_tool / Version 2.0====================16/08/03==
;	cauta pe i2c adrese de lcd
;	ra0,ra1     sdata,sclock
;	rb0 to rb7
;	internal clock
;	standard crystal 4.000 MHz XT - 1us pe instructiune
;	 http://www.module.ro
;------------------------------------------------------------
	list	p=16f84A;f=inhx8m
_CP_OFF	equ	H'3FFF'		;code protect off
_PWRTE_ON	equ	H'3FFF' 		;Power on timer on
_WDT_OFF	equ	H'3FFB'		;watch dog timer off
_XT_OSC		equ	H'3FFD'	;crystal oscillator
	__CONFIG       _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
;------------------------------------------------------------
;      cpu init
status	equ	03
porta		equ	05
portb		equ	06
count1	equ	0C
count2	equ	0D
count3	equ	0E
transo	equ	0F
count4	equ	10
count5	equ	11
count6	equ	12
trisa		equ	85
trisb		equ	86
#DEFINE sclk	porta,1
#DEFINE sdta	porta,0
;------------------------------------------------------------
;      bit init
rp0	equ	5
w	equ	0
f	equ	1
;------------------------------------------------------------
	org	0
;
;------------------------------------------------------------
init	bsf	status,rp0  ;switch to bank 1
	movlw	0	;outputs
	movwf	trisb
	bcf	status,rp0	;switch back to bank 0
	movlw	0
	movwf	portb	
;***************************************************
start	movlw	0xFF
	movwf	portb
	call	pause
;***************************************************
scrie	movlw	0x80	; iic start seeking address (70 to 80h for lcd screen)
	movwf transo
act	bsf	status,rp0  ;ouput port a
	movlw	0	;outputs
	movwf	trisa
	bcf	status,rp0	;switch back to bank 0
	movlw	0
	movwf	porta
;***************************************************	
	movlw	0x00
	movwf	portb
;***************************************************
	bsf	sdta	;	start condition module
	bcf	sclk
	call	pause
	bsf	sclk
	call	pause
	bcf	sdta	;  start
	call	pause
	bcf	sclk
	call	pause
;***************************************************	
	movf	transo,w
	movwf	portb
	call	pausa
	movlw	0x00
	movwf	portb
	call	pause
	bcf	sclk
	call	pause
	bcf	sclk	;   varsa
	call	pause
	btfsc	transo,7	;bit0(MSB)
	bsf	sdta
	btfss transo,7
	bcf	sdta
	call	pause
	bsf	sclk
	call	pause
	bcf	sclk
	call	pause	
	btfsc	transo,6	;bit1
	bsf	sdta
	btfss	transo,6
	bcf	sdta
	call	pause
	bsf	sclk
	call	pause
	bcf	sclk
	call	pause
	btfsc	transo,5	;bit2
	bsf	sdta
	btfss	transo,5
	bcf	sdta
	call	pause
	bsf	sclk
	call	pause
	bcf	sclk
	call	pause
	btfsc	transo,4	;bit3
	bsf	sdta
	btfss	transo,4
	bcf	sdta
	call	pause
	bsf	sclk
	call	pause
	bcf	sclk
	call	pause
	btfsc	transo,3	;bit4
	bsf	sdta
	btfss	transo,3
	bcf	sdta
	call	pause
	bsf	sclk
	call	pause
	bcf	sclk
	call	pause
	btfsc	transo,2	;bit5
	bsf	sdta
	btfss	transo,2
	bcf	sdta
	call	pause
	bsf	sclk
	call	pause
	bcf	sclk
	call	pause
	btfsc	transo,1	;bit6
	bsf	sdta
	btfss	transo,1
	bcf	sdta
	call	pause
	bsf	sclk
	call	pause
	bcf	sclk
	call	pause
	btfsc	transo,0	;bit7(LSB)
	bsf	sdta
	btfss	transo,0
	bcf	sdta
	call	pause
	bsf	sclk
	call	pause
	bcf	sclk
	call	pause
;***************************************************
	bsf	status,rp0	;porta input
	movlw	0x01	;input
	movwf	trisa	; set sda as input
	bcf	status,rp0	;switch back to bank 0
;***************************************************	
	call	antwt	; response from iic device
	call	pause
	call	sout
	call	ahalt
	decfsz	transo,f
	goto	act
	nop	
homa	goto	homa
;***************************************************
sout	bsf	status,rp0	;switch to bank 1
	movlw	0	;outputs
	movwf	trisa
	bcf	status,rp0	;switch back to bank 0
	movlw	0
	movwf	porta
	retlw	00
;***************************************************
ahalt	bcf	sdta	; stop condition module
	call	pause
	bsf	sclk
	call	pause
	bsf	sdta	; comanda stop
	call	pause
	bcf	sclk
	call	pause
	retlw	00
;***************************************************
antwt	movlw	0x04	; wait for a ack
	movwf	count4
	bsf	sclk
	call	pause
ackts	btfss	sdta	;sda=0 ?
	goto	eprok 
	decfsz	count4,f  
	goto	ackts
	call	fails
eprok	bcf	sclk
	retlw	00
;***************************************************
fails	bsf	portb,2	; middle leds blinking when not ack
	bsf	portb,3
	call	pause
	bcf	portb,2
	bcf	portb,3
	call	pause
	bsf	portb,2
	bsf	portb,3
	call	pause
	bcf	portb,2
	bcf	portb,3
	call	pause
	retlw	00
;***************************************************
pause	movlw	0x01
	movwf	count3
d3	movlw	0xF0
	movwf	count1
d1	movlw	0xF0
	movwf	count2
d2	decfsz	count2,f
	goto 	d2		
	decfsz	count1,f
	goto	d1
	decfsz	count3,f
	goto	d3
	retlw	00
;***************************************************
pausa	movlw	0x06
	movwf	count3
r3	movlw	0xF0
	movwf	count1
r1	movlw	0xF0
	movwf	count2
r2	decfsz	count2,f
	goto	r2
	decfsz	count1,f
	goto	r1
	decfsz	count3,f
	goto	r3
	retlw	00
;------------------------------------------------------------
	end
;============================================================



Download project from here.


Back to my home page
Last updated September, 2003
© Copyright 2003 Bergthaller Iulian-Alexandru