CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

i2c routines for dallas ds1624, philips pcf8574, and 24cXX
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
Dimlow



Joined: 24 Nov 2007
Posts: 9

View user's profile Send private message

PostPosted: Wed Jan 02, 2008 1:29 pm     Reply with quote

Just wanted to add that if you look close at the READ FROM PORT and WRITE TO PORT line in these figures it explains it all. Also the note on the bottom of figure 12
Quote:
Transfer of data can be stopped at any moment by a stop condition. When this occurs, data present
at the last acknowledge phase is valid (output mode). Input data is lost.



Regards

Gary
Dimlow



Joined: 24 Nov 2007
Posts: 9

View user's profile Send private message

PostPosted: Wed Jan 09, 2008 1:24 pm     Reply with quote

No Comments ?

Gary
scanan



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

View user's profile Send private message Visit poster's website

PCF8574
PostPosted: Wed Apr 09, 2008 9:22 am     Reply with quote

Here a code which run perfectly
I used 8 pcf8574 32 input and 32 output

Code:
#include <18F452.h>
#device adc=10
//#FUSES XT, NOPROTECT, NOOSCSEN, NOBROWNOUT, BORV45, NOPUT, STVREN, NODEBUG,NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#FUSES H4, NOPROTECT, NOOSCSEN, NOBROWNOUT, BORV45, NOPUT, STVREN, NODEBUG,NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
//#FUSES  XT,NOPROTECT, BROWNOUT, NOPUT, NODEBUG,NOLVP, NOWRT, NOCPD
//#use delay(clock=10000000)
#use delay(clock=40M, oscillator=10M)
#USE RS232(BAUD=9600, XMIT=PIN_C6, RCV=PIN_C7,PARITY=N, bITS=8,STOP=1)
//use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(master,sda=PIN_C4,scl=PIN_C3,FORCE_HW)
#define ON  1
#define OFF 0
#define PCF8574_BASE_ADDRESS 0x40;
#define PCF8574_OUT0_WRITE_ADDRESS 0x48
#define PCF8574_OUT1_WRITE_ADDRESS 0x4A
#define PCF8574_OUT2_WRITE_ADDRESS 0x4C
#define PCF8574_OUT3_WRITE_ADDRESS 0x4E
#define PCF8574_OUT0_READ_ADDRESS 0x49
#define PCF8574_OUT1_READ_ADDRESS 0x4B
#define PCF8574_OUT2_READ_ADDRESS 0x4D
#define PCF8574_OUT3_READ_ADDRESS 0x4F
#define PCF8574_IN0_READ_ADDRESS 0x41
#define PCF8574_IN1_READ_ADDRESS 0x43
#define PCF8574_IN2_READ_ADDRESS 0x45
#define PCF8574_IN3_READ_ADDRESS 0x47


#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)

void PCF8574_SendData(char writeaddress,char data)
{
//char writeadress,data;
   i2c_start();
   i2c_write(writeaddress);
   i2c_write(data);
   i2c_stop();
}

unsigned char PCF8574_GetData(char readaddress)
{
char data;
   i2c_start();
   i2c_write(readaddress);
   data=i2c_read(0);
   i2c_stop();
return data;
}

void main()
{
char data,i,addr;

   do{
   for(i=0;i<4;i++)
   {
   addr=0x40+2*i+1;
   data=PCF8574_GetData(addr);
   PCF8574_SendData(PCF8574_OUT0_WRITE_ADDRESS,0);
   printf("INPUT NUMBER %d DATA %u\r",i,data);
   }                 
     
   }while(1);
   
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group