Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PICF452 I2C routine in microchip C

Status
Not open for further replies.

barfly

New Member
Hey,

does any of you have a C routine i can start with for displaying some characters on an I2C display (maxtrix orbital 2041)

Thanks,

K
 

kinjalgp

Active Member
You can find I2C related routines in this C file.
https://www.phanderson.com/PIC/PICC/CCS_PCM/24_256_1.html

You will require following routines from this file.
byte i2c_in_byte(void);
void i2c_out_byte(byte o_byte);
void i2c_nack(void);
void i2c_ack(void);
void i2c_start(void);
void i2c_stop(void);
void i2c_high_sda(void);
void i2c_low_sda(void);
void i2c_high_scl(void);
void i2c_low_scl(void);

Don't forget to change the I2C port pin definitions.

Now that you have all I2C routines, you just need to send command and data to your display driver using them.
 

barfly

New Member
Thank,

i have this file you mention.
Still, the microchip C-compiler has all the commands 'embedded'.
I want to start writing with the microchip C-compiler commands.

ex.

void main (void)
{

//i2c_start();
//i2c_out_byte(0xa0 | (dev_adr << 1));
//i2c_nack();
//i2c_out_byte((mem_adr >> 8) & 0xff); // high byte of memory address
//i2c_nack();
//i2c_out_byte(mem_adr & 0xff); // low byte of mem address
//i2c_nack();
//i2c_out_byte(dat); // and finally the data
//i2c_nack();
//i2c_stop();



OpenI2C(MASTER, SLEW_ON);
StartI2C();
WriteI2C(0xB8); //B8 = display adress
NotAckI2C();
WriteI2C(0xFE); // command prefix
NotAckI2C();
WriteI2C(0x46); // Turn backlight off
NotAckI2C();
StopI2C();
CloseI2C();

}
 

barfly

New Member
Well, why is this routine not doing what it should do.
address the display, and turn the backlight off.

OpenI2C(MASTER, SLEW_ON);
StartI2C();
WriteI2C(0xB8); //B8 = display adress
NotAckI2C();
WriteI2C(0xFE); // command prefix
NotAckI2C();
WriteI2C(0x46); // Turn backlight off
NotAckI2C();
StopI2C();
CloseI2C();
 
Status
Not open for further replies.

Latest threads

Top