Quoting "Laurent FAILLIE" <[email protected]>:
> Thanks Robert for your mail : I'll certainly use you code for my
> PICs haven't I2C hardware.
>
> Pic 16F88 have the needed hardware and I did notice those function
> in libio lib.
> But my question is more having a full example, from 0 to a workable
> tiny application :
> - initialization to do,
> - choregraphy
> - checks
>
> Thanks
>
> Laurent
Hello Laurent,
It's a long long time since I programmed all of this, but the
I2C-specific initialation that I used (for running a PIC16F886 as I2C
master) looks like this, some of it may be unnecessary, but I added
them to be on the safe side. I now regret not commenting the code more
thorougly... I do not, however, have any experience with the 16F88,
but as I understand it, it should be almost the same as 16F88X
series...? At least the registers seem to have the same names.
{
TRISC3=1;
TRISC4=1;
SMP=1;
WCOL=0;
SSPOV=0;
SSPEN=1;
CKP=1;
SSPCON=SSPCON&0xf0;
SSPCON=SSPCON|0x08;
GCEN=0;
ACKSTAT=0;
ACKDT=0;
ACKEN=0;
RCEN=0;
PEN=0;
RSEN=0;
SEN=0;
SSPADD=15;
}
Basicly what I did was just read the PIC datasheet really carefylly
and set all the relevant registers I could find, I never used any
library functions for anything.
For the 16F886:
SSPSTAT contains the various flags to check.
SSPCON contains the registers to set, and most stuff that follows
SSPCON in the above code are part of the SSPCON2 register.
Then I just sit and wait for an external interrupt that makes the
program read out one byte from the slave, in this case a 1Hz square
wave output from the RTC DS1337 which triggers the PIC to read out the
clocktime from the RTC.
void RTCputc(unsigned char addr, unsigned char c_data)
{
unsigned char c;
c=(RTC_ADDR<<1)&0xfe;; // recalculate the I2C address & write bit
I2Cstart();
I2Cwrite(c); // send the RTC address to the bus
I2Cwrite(addr); // send the RTC internal memory location
I2Cwrite(c_data); // send the data to that location
I2Cstop();
}
unsigned char RTCgetc(unsigned char addr)
{
unsigned char c;
c=(RTC_ADDR<<1)&0xfe; // recalculate the I2C address & write bit
I2Cstart();
I2Cwrite(c); // Send the RTC's I2C address
I2Cwrite(addr); // RTC internal memory location to be read
I2Crestart();
c=c|0x01; // swap the Read/write bit
I2Cwrite(c); // resend the address
c=I2Cread(0); // read one byte, passing the ACK/NAK bit
I2Cstop();
return(c);
}
I hope I answered the right question this time :o)
If you want, I could send the entire project as a .tar.gz, it's a
school project and contains no secrets, only perhaps bad ideas :o)
Best Regards, Robert
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Sdcc-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sdcc-user