raycao88124
Newbie level 2
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?
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?