|
|
------------------------------------------------------------------------------- From : Dima Orlov 2:461/27 Чтв 31 Окт 96 21:18 To : Andrey Kulyapin Чтв 07 Hоя 96 02:35 Subj : I2C -------------------------------------------------------------------------------- Hello, Andrey Kulyapin !
> DG> И мне тоже хочется , в свою очеpедь могу помочь с доками > DG> по этим микpосхемам. Ведь не сложно для знающих людей. > DG> Сам не могу , не умею я , не пpогpаммеp , так - пpимуса > DG> починяю. > Огласите список, pls Ж;-)
> Если есть дока по SAA5243 отмыль мне, pls. > В свою очередь могу отмылить пpогpамму для i8051 для > упpавления TV. В этой пpогpамме есть пpимеp использования I2C.
А вот программа для работв с 24с16 по i2c через lpt uses CRT; var LPT1: Word; A: Word; Mode: (mError, mRead, mWrite); FileName: String[80]; Buf : Array[0..2047] of byte; F: File;
{ 24C16 LPT 1┌---┬---┬---┐8 ┌-----┤A0 │ E │Vcc├-----┬---->D1 (Pin 3) │ 2│ │ E │ │7 ┌┴┐ │┌----┤A1 │ P │ WP├- 0 │\\│15k ││ 3│ │ R │ │6 │\\│ ││┌---┤A2 │ O │SCL├---┐└┬┘ ┌->D2 (Pin 4) │││ 4│ │ M │ │5 └-┼--┘ │││ ┌-┤GND│ │SDA├--┬--┴---->ACK (Pin 10) │││ │ └---┴---┴---┘ │ │││ │ │/ к │││ │ ┌-┤ │││ │ ┌┴┐│\\ э │││ │ │\\│ │ │││ │ 1k│\\│ │ ┌->D0 (Pin 1) │││ │ └┬┘ │ │ │││ │ └---┼-----┘ │││ └----------------┴------->GND (Pin 25) │││ ││└-------------------------->D3 (Pin 5) ││ │└--------------------------->D4 (Pin 6) │ └---------------------------->D5 (Pin 7) } const Digits : array[0..$F] of Char = '0123456789ABCDEF';
function HexB(B : Byte) : string; {-Return hex string for byte} begin HexB[0] := #2; HexB[1] := Digits[B shr 4]; HexB[2] := Digits[B and $F]; end;
procedure Pause; assembler; asm push ax @@0: jmp @@1 @@1: in al, dx pop ax end;
procedure Start; assembler; asm mov dx, lpt1 mov al, 00000110b {Vcc = 1, SCL = 1, SDA = 1} out dx, al call Pause mov al, 00000111b {Vcc = 1, SCL = 1, SDA = 0} out dx, al call Pause mov al, 00000011b {Vcc = 1, SCL = 0, SDA = 0} out dx, al call Pause end;
procedure Stop; assembler; asm mov dx, lpt1 mov al, 00000111b {Vcc = 1, SCL = 1, SDA = 0} out dx, al call Pause mov al, 00000110b {Vcc = 1, SCL = 1, SDA = 1} out dx, al call Pause end;
function PutByte(B: Byte): boolean; assembler; asm mov dx, lpt1 mov ah, B mov cx, 8 @@0: rcl ah,1 jc @@1 mov al, 00000011b {Vcc = 1, SCL = 0, SDA = 0} out dx, al call Pause mov al, 00000111b {Vcc = 1, SCL = 1, SDA = 0} out dx, al call Pause mov al, 00000011b {Vcc = 1, SCL = 0, SDA = 0} out dx, al
jmp @@2 @@1: mov al, 00000010b {Vcc = 1, SCL = 0, SDA = 1} out dx, al call Pause mov al, 00000110b {Vcc = 1, SCL = 1, SDA = 1} out dx, al call Pause mov al, 00000010b {Vcc = 1, SCL = 0, SDA = 1} out dx, al @@2: loop @@0 call Pause mov al, 00000110b {Vcc = 1, SCL = 1, SDA = 1} out dx, al call Pause inc dx in al, dx dec dx and al, 01000000b mov ah, 1 je @@3 mov ah, 0 @@3: mov al, 00000010b {Vcc = 1, SCL = 0, SDA = 1} out dx, al mov al, ah end;
function GetByte: byte; assembler; asm mov dx, lpt1 mov cx, 8 @@0: mov al, 00000110b {Vcc = 1, SCL = 1, SDA = 1} out dx, al call Pause inc dx in al, dx dec dx and al, 01000000b shl al,1 shl al,1 rcl ah, 1 mov al, 00000010b {Vcc = 1, SCL = 0, SDA = 1} out dx, al call Pause loop @@0 mov al, 00000110b {Vcc = 1, SCL = 1, SDA = 1} out dx, al call Pause mov al, 00000010b {Vcc = 1, SCL = 0, SDA = 1} out dx, al call Pause mov al, ah end;
procedure WriteByte(Addr:Word; B : Byte); begin Start; PutByte($A0 or ((Hi(Addr) shl 1) and $0e)); PutByte(Lo(Addr)); PutByte(B); Stop; Delay(5); end;
function ReadByte(Addr:Word): Byte; begin Start; PutByte($A0 or ((Hi(Addr) shl 1) and $0e)); PutByte(Lo(Addr)); Start; PutByte($A1 or ((Hi(Addr) shl 1) and $0e)); ReadByte := GetByte; Stop; end;
procedure ComStr; var PCStr : ^String; i: Byte;
begin PCStr := Ptr(PrefixSeg, $80); for i := 0 to length(PCStr^) -1 do if PCStr^[i] in ['-', '/'] then begin case PCStr^[i+1] of 'r', 'R' : Mode := mRead; 'w', 'W' : Mode := mWrite; else Mode := mError; end; Delete(PCStr^, i, 2); Break; end; if ParamCount = 0 then Mode := mError else FileName := ParamStr(1); end;
begin
LPT1 := $378; asm mov dx, lpt1 mov al, 00000110b out dx, al end;
ComStr; Assign(F, FileName);
case Mode of mRead: begin for A:= 0 to 2047 do Buf[A] := ReadByte(A); Rewrite(F, 1); if IOResult = 0 then begin BlockWrite(F, Buf, SizeOf(Buf)); Close(F); end; end; mWrite: begin Reset(F, 1); if IOResult = 0 then begin BlockRead(F, Buf, SizeOf(Buf)); Close(F); for A:= 0 to 2047 do WriteByte(A, Buf[A]); end; end; mError: begin WriteLn('24c16 fileName -r|-w'); WriteLn(' -r Read'); WriteLn(' -w Write'); end; end; end.
С уважением, Дима Орлов
--- [CONNECT Team] * Origin: Electric BBS (0572) 477-177 (2:461/27)
| |
| |