Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with I2C on PIC18F4550

Status
Not open for further replies.

raycao88124

Newbie level 2
Joined
Jun 11, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,302
Hello everyone

I just started learning programming PIC microcontroller, and I am trying to display a string on an LCD from PIC18F4550, using I2C protocol. I wrote the code and compiled, programmed it using ICD3. But it doesnt work. I use a USB demoboard.
I am using C18 compiler and MPLAB 8.85
The LCD supports I2C protocol and has a default slave address of 0x50. It supports baud rate up to 100KHZ (It is a new haven LCD)
Here is the code I wrote

char string[]="My name";

ADCON1 = 0x0F;
OSCCON = 0x72; //set 8Mhz internal clock rate
SSPADD = 0x13; //set 100 khz baud rate
TRISB = 1;
OpenI2C(MASTER,SLEW_OFF);
IdleI2C();
StartI2C();
IdleI2C();
WriteI2C(0x50); // send address
IdleI2C();
putsI2C(string);
IdleI2C();
StopI2C();
While(1);

In my code, I want to use internal clock with 8M hz clock rate, so the corresponding value for SSPADD should be 0x13.... Is that correct? Is my set up for OSCCON and SSPADD right?

Is there anything wrong with the code? Please help. Also, when in master mode, should both data line and clock line be output?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top