Topic I2C from HARDW FAQ base
Ïîæàëóéñòà, îáðàòèòå âíèìàíèå íà äàòó ïðåäñòàâëåííîãî çäåñü ñîîáùåíèÿ! Èíôîðìàöèÿ îá àäðåñàõ, òåëåôîíàõ, îðãàíèçàöèÿõ è ëþäÿõ íàâåðíÿêà óñòàðåëà è ïîòåðÿëà ïðàêòè÷åñêóþ öåííîñòü, îáðåòÿ, îäíàêî, öåííîñòü èñòîðè÷åñêóþ, çàðàäè êîòîðîé äî ñèõ ïîð è õðàíèòñÿ...
— SU.HARDW.OTHER (2:5020/299) ———————————————————————————————— SU.HARDW.OTHER — From : Dima Orlov 2:461/27 Sun 11 May 97 08:30 Subj : i2c ———————————————————————————————————————————————————————————————————————————————— > Åñòü ëè ó Âàñ õîòü êàêèå-íèáóäü èñõîäíèêè äëÿ ðàáîòû ñ ~93cÕÕ è > 24ñÕÕ ÷åðåç LPT? Ïðîãðàììàòîð çàäîëáàë ìåíÿ ñâîåé êðèâèçíîé è > íåãèáêîñòüþ. Åñòü äëÿ 24ñ16 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 2) ³³³ ³ ÀÂÙ ³ ³ ³³³ ³ À———Å—————Ù ³³³ À————————————————Á———————>GND (Pin 25) ³³³ ³³À——————————————————————————>D3 (Pin 5) ³³ ³À———————————————————————————>D4 (Pin 6) ³ À————————————————————————————>D5 (Pin 7) } 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)
Return to the main HARDW FAQ page