LF: I2C Routine Port...Anyone up to it?
[Prev][Next][Index][Thread]
LF: I2C Routine Port...Anyone up to it?
-
Subject: LF: I2C Routine Port...Anyone up to it?
-
From: Tim Gerla <timg@climax.polaristel.net>
-
Date: Fri, 15 Nov 1996 23:02:56 GMT
-
In-Reply-To: <>
Does anyone want to try and port Per Finander's ZShell I2C routines to
68k/Fargo? I don't know Z80 asm, and my 68k asm is weak, so I really
don't know where to start. There are many cool things for I2C, such a
temperate sensor (oh wow, now I have a $200 thermometer!), EEPROMs, IR
devices, etc... I would like to design hardware, but I need software
too! <g> Well, thanks!
-Tim
BTW, here's the code, it's not too long.
; ------------------------------------------
; 2
; I C routines for ZShell 4.0
;
; Per Finander, 1996
; e-mail: pfimdt93@tufvan.hv.se
;
; +--------
; /-- --- ---|
; < | To TI85
; \-- --- ---|
; | | | +--------
; | | |
; SDA SCL Gnd
;
; ------------------------------------------
; (updated 31 May 1996)
;
; Send I2C Start pulse
;
I2CStart: ld a,$C0 ; SDA 1 ""\
CALL_(I2CDT) ; 0 \_____
ld a,$C4
CALL_(I2CDT) ; SCL 1 """""\
jr I2CDT ; 0 \__
;
; Send I2C Stop pulse
;
I2CStop: ld a,$CC ; SDA 1 /""
CALL_(I2CDT) ; 0 _____/
CALL_(I2CDT)
ld a,$C0 ; SCL 1 /"""""
jr I2CDT ; 0 __/
; Send A to I2C bus
;
; In : A - Byte to send
; Out: CF - =1 if no acknowledge was returned (error)
I2CSend: push bc
ld b,$08
I2CNextB: rlca
push af
ld a,$CC
jr nc,I2CNotS
xor $04
I2CNotS: CALL_(I2CPulse)
pop af
djnz I2CNextB
ld a,$C8
CALL_(I2CPulse)
rr c
pop bc
ret
; Read byte from I2C bus, Send an acknowledge
;
; Out: A = byte
I2CReadA: ld a,$CC
jr I2CRead1
; Read byte from I2C bus, Don't send an acknowledge
;
; Out: A = byte
I2CRead: ld a,$C8
I2CRead1: push bc
push af
ld b,$08
xor a
I2CGetB: push af
ld a,$C8
CALL_(I2CPulse)
pop af
rr c
rla
djnz I2CGetB
ld b,a
pop af
CALL_(I2CPulse)
ld a,b
pop bc
ret
I2CPulse: CALL_(I2CDT)
CALL_(I2CDT)
ld c,$07
in c,(c)
I2CDT: out ($07),a
xor $08
ret
<pre>
--
Tim Gerla | timg@climax.polaristel.net
Tyball@irc | www.geocities.com/SiliconValley/Park/1691
Tyball Dragon| -==<UDIC>==-
Fargo Program Archive: www.geocities.com/SiliconValley/Park/1691/ti.html
</pre>