Hi
> Has anyone written any general-purpose routines for SDCC to deal
> with the on-chip I2C controller in the 87C751 that they'd be willing
> to share?
Attached are the routines I use for my p89c668 devices. The I2C seems to be
equivalent to the 87C751 one.
Here is an application note from philips with more error detection that I will
switch to myself.
http://www.nxp.com/acrobat_download/applicationnotes/AN10155_1.pdf
Hope it helps
Gudjon
#include "i2clib.h"
void i2c_init(unsigned char addr)
{
S1CON=0xE4;
while(!SI);
S1DAT=addr;
S1CON=0xC4;
while(!SI);
}
void i2c_write_byte(unsigned char out_byte)
{
S1DAT=out_byte;
S1CON=0xC4;
while (!SI);
}
unsigned char i2c_read_ibyte() // Read all but the last byte
{
S1CON=0xC4;
while (!SI);
return S1DAT;
}
unsigned char i2c_read_lbyte() // Read the last byte
{
S1CON=0xC0;
while (!SI);
return S1DAT;
}
void i2c_stop()
{
S1CON=0xD4;
while (!STO);
}
#ifndef __I2CLIB__
#define __I2CLIB__
#include <p89c66x.h>
void i2c_init(unsigned char addr);
void i2c_write_byte(unsigned char out_byte);
unsigned char i2c_read_ibyte(); // Read all but the last byte
unsigned char i2c_read_lbyte(); // Read the last byte
void i2c_stop();
#endif
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user