How to pilot an pcf8574 as input??? How to get a button pressed?

lestroso

New Member
Dear friends,

i'm working with pcf8574a , but i'm not be able to run properly this device.....i have 4 pcf8574 as input and i want to test the input when a button is pressed....

ok i give my example program...but this does.t work.....can you help me please??

i'm using also a picaxe18m2......Thanks a lot in advance Lestroso.

Code:
  #picaxe 18m2 
  setfreq m16

;
i2cslave %01111000, i2cslow, i2cbyte
pause 1000
writei2c (%11111111)

i2cslave %011110010, i2cslow, i2cbyte
pause 1000
writei2c (%11111111)

i2cslave %01111100, i2cslow, i2cbyte
pause 1000
writei2c (%11111111)

i2cslave %01111110, i2cslow, i2cbyte
pause 1000
writei2c (%11111111)

start:
;read from first chip pcf8574...if a button is pressed then go to uno
pause 1000
readi2c %01111001,(b0)  
IF pin0=0 THEN  uno

;PAUSE 500
GOTO  start

  uno: 
;make a music
tune c.1,12,(7,9,5,37,192)
GOTO start
 
Last edited by a moderator:

westaust55

Moderator
For the "first" PCF8574A in your program you are using the slave address as %01111001
from the NXP datasheet, the slave address must be %0111aaad, where aaa is the address set by the adressing pins and d is the direction (read/write).

For the address portion you have aaa = 100 thus I presume that you have addressing pin A2 pulled high.


For the second chip you are addressing, you have:
i2cslave %011110010, i2cslow, i2cbyte​
Which has 9 bits for the slave address whereas the correct number of bits is 8.
Should that be: i2cslave %01111010, i2cslow, i2cbyte ?

There is no need to change the direction bit as the PICAXE will look after the lsb for read and write control.

Note that with the newer PICAXE chips, you should use the Hi2cSETUP, Hi2cIN and Hi2cOUT commands.
 

lestroso

New Member

Dear westaust55, i thank you very much.... i have made an transcription error for the bits...are9 but in true are 8 bit...ok but can some
one give me a piece of code???
because i don't know how to pilot in input via software these chip... Thanks a lot in advance to everybody....best regards,lestroso:eek:






For the "first" PCF8574A in your program you are using the slave address as %01111001
from the NXP datasheet, the slave address must be %0111aaad, where aaa is the address set by the adressing pins and d is the direction (read/write).

For the address portion you have aaa = 100 thus I presume that you have addressing pin A2 pulled high.


For the second chip you are addressing, you have:
i2cslave %011110010, i2cslow, i2cbyte​
Which has 9 bits for the slave address whereas the correct number of bits is 8.
Should that be: i2cslave %01111010, i2cslow, i2cbyte ?

There is no need to change the direction bit as the PICAXE will look after the lsb for read and write control.

Note that with the newer PICAXE chips, you should use the Hi2cSETUP, Hi2cIN and Hi2cOUT commands.
 

lestroso

New Member
Dear friend!!!!! I MAKE IT!!!!ahhahh


i have succefully created my new piece of code for pilot the pcf8754 as input like buttons analog or digital.....i want to share my software very clear and useful with you...i have also enclose many comments to my code....

thanks a lot to everybody

best regards,
lestroso
http://www.fasasoftware.com

Here The Code.........



setfreq m16 ;I SET THIS BECAUSE I HAVE MANY DEVICES WORKING AT THIS FREQ

i2cslave %01111111, i2cslow, i2cbyte ;I DECLARE MY PCF8574 DEVICE
writei2c 0, (%11111111) ; I RESET THE PIN TO HIGH AS REQUESTED ON THE MANUAL
pause 1000; A LITTLE WAIT


start:
i2cslave %01111110, i2cslow, i2cbyte ;I DECLARE MY PCF AS INPUT...NOTE THE ENDING ZERO TO READ!!!!
readi2c (b0); I PUT IN MEMORY THE DATA INPUT OF THE BUTTON!!!

IF b0=%01111111 THEN uno ; I COMPARE THE DATA WITH MY INPUT OF MY CHOICE THE BIT 0!!IF IS THE SAME GO TO UNO
PAUSE 1000
GOTO start



uno:

tune c.1,12,(7,9,5,37,192); MAKE THE CLOSE ENCOUNTER MUSIC!!!
GOTO start
 
Top