Hi all
For the interested electronic enginieering developers:
Datasheet IC : PCF8574
The book is : PC-Ports Under Windows ELEKTOR
$USE "Inpout32.lib"
$USE "i2c_lpt.lib" 'see the other posts
$INCLUDE "i2c_lpt.inc" 'see the other posts
$MAIN
OPENCONSOLE
DEF s AS STRING
DEF Ausgabe AS CHAR
DO
INPUT "Schrijven: ",s : Ausgabe = VAL(s)
Parallel_Output(Ausgabe)
PRINT "Lezen = " ,STR$(Parallel_Input())
UNTIL Ausgabe = 0
CLOSECONSOLE
END
SUB Parallel_Output(DataWoord AS CHAR)
i2c_Start()
i2c_Write(0x32 * 0x02 + 0x00)
i2c_Write(DataWoord)
i2c_Stop()
ENDSUB
SUB Parallel_Input(), CHAR
DEF ret : CHAR
i2c_Start()
i2c_Write(0x32 * 0x02 + 0x01)
ret = i2c_Read()
RETURN ret
i2c_Ack()
i2c_Stop()
ENDSUB
Hi all
When I try to build it files in the second step. An fatal error in the linker .a file. What wrong here. I try to find an solution but I can't find any solution for this linker error
The library i2c_lpt.dll + i2c_lpt.lib
$USE "inpout32.lib"
$INCLUDE "i2c_lpt.inc"
DECLARE IMPORT, Inp32(PortAddr : WORD), WORD '
DECLARE IMPORT, Out32(PortAddr : WORD, PortData : WORD) '
'============================================================================================================'
'============================================================================================================'
' MSVC70.dll '
DECLARE EXTERN _sscanf(STRING buf, STRING format,...),INT '
DECLARE EXTERN sprintf(POINTER p, POINTER p, ...), INT '
DECLARE EXTERN ReadKey alias __getch(),INT '
DECLARE EXTERN KeyPressed alias __kbhit(),INT '
'============================================================================================================'
'============================================================================================================'
' kernel32.dll '
DECLARE IMPORT, Sleep(int time) '
'============================================================================================================'
EXPORT i2c_Init
EXPORT i2c_Start
EXPORT i2c_Stop
EXPORT i2c_Ack
EXPORT i2c_NoAck
EXPORT i2c_Write
EXPORT i2c_Read
SUB i2c_Init()
Out32 ((LPT1 + 0x02), 0x00) 'SCL = 1, SDA = 1 (0000 0000)
RETURN
ENDSUB
SUB i2c_Start()
Out32 ((LPT1 + 0x02), 0x01) 'SCL = 1, SDA = 0 (0000 0001)
Out32 ((LPT1 + 0x02), 0x03) 'SCL = 0, SDA = 0 (0000 0011)
RETURN
ENDSUB
SUB i2c_Stop()
Out32 ((LPT1 + 0x02), 0x03) 'SCL = 0, SDA = 0 (0000 0011)
Out32 ((LPT1 + 0x02), 0x01) 'SCL = 1, SDA = 0 (0000 0001)
Out32 ((LPT1 + 0x02), 0x00) 'SDA = 1, SDA = 1 (0000 0000)
RETURN
ENDSUB
SUB i2c_Ack()
Out32 ((LPT1 + 0x02), 0x03) 'SCL = 0, SDA = 0 (0000 0011)
Out32 ((LPT1 + 0x02), 0x01) 'SCL = 1, SDA = 0 (0000 0001)
'FOR m = 1 TO 5 : NEXT m
Sleep(5)
Out32 ((LPT1 + 0x02), 0x03) 'SCL = 0, SDA = 0 (0000 0011)
RETURN
ENDSUB
SUB i2c_NoAck()
Out32 ((LPT1 + 0x02), 0x02) 'SCL = 0, SDA = 1 (0000 0010)
Out32 ((LPT1 + 0x02), 0x00) 'SCL = 1, SDA = 1 (0000 0000)
'FOR m = 1 TO 5 : NEXT m
Sleep(5)
Out32 ((LPT1 + 0x02), 0x02) 'SCL = 0, SDA = 1 (0000 0010)
RETURN
END SUB
SUB i2c_Write(DataWoord AS CHAR)
DEF BitWoord : CHAR
DEF PortWoord : CHAR
DEF n : CHAR
BitWoord = 0x80
FOR n = 1 TO 8
IF (DataWoord & BitWoord) = BitWoord THEN
PortWoord = 0x02 '(0000 0010)
ELSE
PortWoord = 0x03 '(0000 0011)
END IF
Out32 ((LPT1 + 0x02), PortWoord) ' SDA = setten
Out32 ((LPT1 + 0x02), PortWoord - 0x02) ' SCL = HOOG
Sleep(5)
'FOR m = 1 TO 5 : NEXT m ' delay loop
Out32 ((LPT1 + 0x02), PortWoord) ' SCL = reset
Out32 ((LPT1 + 0x02), BitWoord >> 0x01) '
NEXT n
Out32 ((LPT1 + &H02), 0x02) 'SCL = 0, SDA = 1 (0000 0010)
Out32 ((LPT1 + &H02), 0x00) 'SCL = 1, SDA = read (0000 0000)
Sleep(5)
'FOR m = 1 TO 5 : NEXT m ' delay loop
IF (Inp32(LPT1 + 0x02) & 0x01) = 0 THEN PRINT "IC Antwoord niet"
Out32 ((LPT1 + &H02), 0x02) 'SCL = 0, SDA = 1 (0000 0010)
RETURN
END SUB
SUB i2c_Read(), CHAR
DEF BitWoord : CHAR
DEF DataWoord : CHAR
DEF n : CHAR
Out32 ((LPT1 + 0x02), 0x02) 'SCL = 0, SDA = 1 (0000 0010)
BitWoord = 0x80
DataWoord = 0x00
FOR n = 1 TO 8
Out32 ((LPT1 + 0x02), 0x00) 'SCL = 1, SDA = 1 (0000 0000)
Sleep(5)
'FOR m = 1 TO 5 : NEXT m ' delay loop
IF (Inp32(LPT1 + 0x02) & 0x01) = 0 THEN
DataWoord += BitWoord
END IF
Out32 ((LPT1 + 0x02), 0x02) 'SCL = 0, SDA = 1 (0000 0010)
BitWoord = BitWoord >> 0x01
NEXT n
RETURN DataWoord
ENDSUB
DECLARE i2c_Init()
DECLARE i2c_Start()
DECLARE i2c_Stop()
DECLARE i2c_Ack()
DECLARE i2c_NoAck()
DECLARE i2c_Write(DataWoord AS CHAR)
DECLARE i2c_Read(), CHAR
CONST LPT1 = 0x378
CONST LPT2 = 0x278
CONST LPT3 = 0x3BC
CONST STROBE = 0x01
CONST AUTO_FEED = 0x02
'CONST INIT = 0x04
CONST SLCTIN = 0x08
CONST ERROR = 0x08
CONST SELECTS = 0x10
CONST PE = 0x20
CONST ACK = 0x40
CONST BUSY = 0x80
The Application LPT port communication with I2C protocol with the PCF8574 chip
$USE "Inpout32.lib"
$USE "i2c_lpt.lib" 'see the other posts
$INCLUDE "i2c_lpt.inc" 'see the other posts
$MAIN
OPENCONSOLE
DEF s AS STRING
DEF Ausgabe AS CHAR
DO
INPUT "Schrijven: ",s : Ausgabe = VAL(s)
Parallel_Output(Ausgabe)
PRINT "Lezen = " ,STR$(Parallel_Input())
UNTIL Ausgabe = 0
WAITCON()
CLOSECONSOLE
END
SUB Parallel_Output(DataWoord AS CHAR)
i2c_Start()
i2c_Write(0x32 * 0x02 + 0x00)
i2c_Write(DataWoord)
i2c_Stop()
ENDSUB
SUB Parallel_Input(), CHAR
DEF ret : CHAR
i2c_Start()
i2c_Write(0x32 * 0x02 + 0x01)
ret = i2c_Read()
RETURN ret
i2c_Ack()
i2c_Stop()
ENDSUB
did you put all the support files in the required locations?
Quote from: LarryMc on May 27, 2015, 10:18:49 AM
did you put all the support files in the required locations?
Larry
Yes I did
to get it to compile without errors change the 1st 7 lines of the i2c_lpt.inc file to look like this:
DECLARE import, i2c_Init()
DECLARE import, i2c_Start()
DECLARE import, i2c_Stop()
DECLARE import, i2c_Ack()
DECLARE import, i2c_NoAck()
DECLARE import, i2c_Write(DataWoord AS CHAR)
DECLARE import, i2c_Read(), CHAR
To get it to run copy the 2 .dll files to the same folder as the exe file.
Quote from: LarryMc on May 27, 2015, 07:39:26 PM
to get it to compile without errors change the 1st 7 lines of the i2c_lpt.inc file to look like this:
DECLARE import, i2c_Init()
DECLARE import, i2c_Start()
DECLARE import, i2c_Stop()
DECLARE import, i2c_Ack()
DECLARE import, i2c_NoAck()
DECLARE import, i2c_Write(DataWoord AS CHAR)
DECLARE import, i2c_Read(), CHAR
To get it to run copy the 2 .dll files to the same folder as the exe file.
Thank you, It build and runs fine
Larry