TI-H: I2C Virtural Hub


[Prev][Next][Index][Thread]

TI-H: I2C Virtural Hub



This only took me ~10 minutes, so don't make a remark on how much of a life
I have.  :)

Site location:

Code is very simple to read.  I didn't use macros, interupts, just be bappy
its easy to read.  :)  Some of my advanced I2C projects are a nightmare to
read.  :)

Code (Also attached):
;***************************************************************************
;*     C O D E  F O R  T H E  I 2 C  R O U T I N E  C O L L E C T I O N
;*
;* Number              :ACI2CVHUB004
;* File Name           :ACI2CVHUB004.asm
;* Title               :ECP MAS3507D Parallel Port Player
;* Date:	Version:				Status:
;* 10.30.98	1a	Grant Stockly	Started project of making a device
;*					that blinks an LED (or any thing)
;*					when the I2C network acts up.  There
;*					is a Transmit and Data light...
;* 10.30.98	1bR1	Grant Stockly	Program finished.  Made TI-H people
;*					happy.  Now they have an I2C hub. :)
;*
;* Support telephone    :1-907-345-1529
;* Support email	:gussie@alaska.net
;* Target		:AT90Sxxxx (any AVR device)
;*
;* DESCRIPTION
;* This code will blinks an LED (or any thing) when the I2C network acts
up.  There
;* is a Transmit and Data light...
;*
;* -Transmit LED
;*  Blinks when ever there is a clock transition, and stays on for a few us
;*  afterwards.
;* -Data LED
;*  Blinks when ever there is data presented on the I2C line.  Blinking
;*  has been slowed down.  :)
;*
;***************************************************************************

;Only one set of these "Include and define" sets can be used at a time.
;You use the correct set for the correct processor.  I know atmel makes
;more parts than what I have here and I will add them soon...

.include "1200def.inc"	;Include files for the AT90S1200
.device AT90S1200		;Tells the assembler what part we are using

;.include "2313def.inc"	;Include files for the AT90S2313
;.device AT90S2313		;Tells the assembler what part we are using

;.include "4414def.inc"	;Include files for the AT90S4414
;.device AT90S4414		;Tells the assembler what part we are using

;.include "8515def.inc"	;Include files for the AT90S8515
;.device	AT90S8515	;Tells the assembler what part we are using


;*****Global Registers
.def	cblink		=r16	;This is the register where the number of
							;Clock transitions
are stored.
.def	dblink		=r17	;This is the register where the number of
							;Data transitions
are stored.
.def	temp		=r18	;Temp storage register

;*****Pin Definitions:
.equ	SDA			=0		;PB0 - I2C SDA line
.equ	SDC			=1		;PB1 - I2C SDC line
.equ	TRANSMIT	=2		;PB2 - Light that represents a transmit
.equ	DATA		=3		;PB3 - Light that represents a data
xmit

;*****Reset Handler
.org 0
	rjmp	Main


;***************************************************************************
;*
;* "Main"
;*
;***************************************************************************
.cseg
Main:
;*****Clear Registers
	clr		cblink			;Load %00000000 to cblink
	clr		dblink			;Load %00000000 to dblink
	clr		temp			;Load %00000000 to temp
;*****Set data direction
	ldi		temp, 0b00001100
	out		DDRB, init		;Set Port B Data direction
register
;*****Load registers
	ldi		cblink, $FF		;Load 255 to cblink
	ldi		dblink, $FF		;Load 255 to dblink
;*****Flash the two lights for a second or so...
A:	dec		cblink
	cpi		$00
	brne	B
	rjmp	D
B:	ldi		dblink, $FF
C:	dec		dblink
	cpi		$00
	brne	C
	rjmp	A
;*****Prepare registers/leds
D:	ldi		cblink, $FF
	ldi		dblink, $FF
	sbi		PORTB, TRANSMIT
	sbi		PORTB, DATA
;*****Flash lights
AA:	dec		cblink
	cpi		$00
	brne	BB
	rjmp	DD
BB:	ldi		dblink, $FF
CC:	dec		dblink
	cpi		$00
	brne	CC
	rjmp	AA
DD:	sbis	PINB, SDA
	cbi		PORTB, DATA
	sbic	PINB, SDA
	sbi		PORTB, DATA
	sbis	PINB, SDC
	cbi		PORTB, TRANSMIT
	sbic	PINB, SDC
	sbi		PORTB, TRANSMIT
	ldi		cblink, $FF
	ldi		dblink, $FF
	rjmp	AA














ACI2CVHUB004.asm


Follow-Ups: