CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC to PIC controling a LCD using I2C

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PhilWinder



Joined: 16 Apr 2005
Posts: 23

View user's profile Send private message

PIC to PIC controling a LCD using I2C
PostPosted: Mon Apr 18, 2005 7:27 pm     Reply with quote

hi,
ive recently been look about at using I2C to make a LCD driver, since all my pins on one chip are used up and i dont have a serial LCD. I have successfully already used a I2C RTC, but this is proving to be somewhat more difficult.

basically I want to be able to send strings to be put onto the LCD and i would like to use I2C rather than the Serial port because that is for communication to the PC/debugging, plus i already have my RTC on the I2C. might as well use it.

The many I2C examples have definatly baffled me, its taking quite a long time for all of them to sink in, but one thing i have noticed that all of these I2c routines/examples use "commands" or bytes of information. is it even possible to use I2C to do what i want???

thanks for any thoughts,

Phil
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Apr 18, 2005 8:15 pm     Reply with quote

Most certainly. We do it everyday. In some of our products, there is an embedded PC104 card (586) that speaks to other devices, one of which is a keyboard with LCD. The data is send via I2C.
PhilWinder



Joined: 16 Apr 2005
Posts: 23

View user's profile Send private message

PostPosted: Mon Apr 18, 2005 8:42 pm     Reply with quote

ok thanks mark, any hints Smile ????

im guessing that i could still use the printf function, but i dont know what i would need to make the passing function or whatever you call it. i.e.

printf(sendmycharbyI2C,"Hello World!!!");

cheers,

phil
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Apr 18, 2005 9:37 pm     Reply with quote

Go look in the code archive. I posted some Master/Slave code there.

Send the data as a command. This will give you some error checking.

We send the data as ansi escape sequences. This will allow you to control the location and some aspects of the display.
PhilWinder



Joined: 16 Apr 2005
Posts: 23

View user's profile Send private message

PostPosted: Tue Apr 19, 2005 4:00 am     Reply with quote

hi again mark,
i bet you must have said that a thousand times now Smile
yeah ive already come accross your work and its not exactly what i want. You have seemed to re-write CCS' I2C routines, and that looks a bit complicated at the mo, all i want to do for now is send a character and display on an LCD. Heres the code that doesnt work so far:

Slave:
Code:

   #include <16f88.h>
   #fuses INTRC_IO,NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP, NOWRT, NOMCLR

#use delay(clock=4000000)
#use i2c(SLAVE,SCL = PIN_B4, SDA = PIN_B1, ADDRESS = 0XA0, fast, Force_Hw)

   #include "LCD.C"
   #include <stdio.h>
   #include <stddef.h>
int i;

#int_SSP
SSP_isr(){
i=0;
if(i2c_poll()==FALSE)
return;
else
{

i=i2c_read();
delay_ms(10);

printf(lcd_putc,"\fData= %U",i);}

return 0;

}

main()
{
   int temp;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

enable_interrupts(INT_SSP);
enable_interrupts(global);

   lcd_init();
   lcd_putc('\f');
   lcd_putc('a');
   delay_ms(1000);
   lcd_putc('\f');


delay_ms(6);
while(TRUE)
{
delay_ms(10);
}

}


and Master:

Code:

#include <18F458.h>   
#device *=16
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#fuses HS, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP, NOWRT
#use I2C(MASTER, SCL = PIN_C3, SDA = PIN_C4, FAST, Force_HW)
#use delay(clock=20000000)

setup_adc_ports(all_digital);
setup_comparator(all_digital);
Setup_CCP1(CCP_OFF);
Setup_CCP2(CCP_OFF);
Setup_CCP3(CCP_OFF);
Setup_CCP4(CCP_OFF);
Setup_CCP5(CCP_OFF);

main() {

delay_ms(6);
while(TRUE)
{

i2c_start();
i2c_write(0xa0);
i2c_write(0x49);
i2c_stop();
delay_ms(500);

}
}


cheers, phil
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Apr 19, 2005 6:17 am     Reply with quote

PhilWinder wrote:
hi again mark,
i bet you must have said that a thousand times now Smile
yeah ive already come accross your work and its not exactly what i want. You have seemed to re-write CCS' I2C routines, and that looks a bit complicated at the mo, all i want to do for now is send a character and display on an LCD. Heres the code that doesnt work so far:

Slave:
Code:

   #include <16f88.h>
   #fuses INTRC_IO,NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP, NOWRT, NOMCLR

#use delay(clock=4000000)
#use i2c(SLAVE,SCL = PIN_B4, SDA = PIN_B1, ADDRESS = 0XA0, fast, Force_Hw)

   #include "LCD.C"
   #include <stdio.h>
   #include <stddef.h>
int i;

#int_SSP
SSP_isr(){
i=0;
if(i2c_poll()==FALSE)
return;
else
{

i=i2c_read();
delay_ms(10);

printf(lcd_putc,"\fData= %U",i);}

return 0;

}

main()
{
   int temp;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

enable_interrupts(INT_SSP);
enable_interrupts(global);

   lcd_init();
   lcd_putc('\f');
   lcd_putc('a');
   delay_ms(1000);
   lcd_putc('\f');


delay_ms(6);
while(TRUE)
{
delay_ms(10);
}

}


and Master:

Code:

#include <18F458.h>   
#device *=16
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#fuses HS, NOWDT, NOPROTECT, PUT, NOBROWNOUT, NOLVP, NOWRT
#use I2C(MASTER, SCL = PIN_C3, SDA = PIN_C4, FAST, Force_HW)
#use delay(clock=20000000)

setup_adc_ports(all_digital);
setup_comparator(all_digital);
Setup_CCP1(CCP_OFF);
Setup_CCP2(CCP_OFF);
Setup_CCP3(CCP_OFF);
Setup_CCP4(CCP_OFF);
Setup_CCP5(CCP_OFF);

main() {

delay_ms(6);
while(TRUE)
{

i2c_start();
i2c_write(0xa0);
i2c_write(0x49);
i2c_stop();
delay_ms(500);

}
}


cheers, phil


That code is pretty much a skeleton of the I2C routines that I use in a large portion all of our projects. As far as being a rewrite of the CCS routines, not exactly. Yeah, I have my own I2C_Write, I2C_Read and such but those aren't really all that complicated. It's the messaging and interrupt handling that is the real key here. That is missing from CCS and that is what you need. The real key is the SSP interrupt. Multiple things can cause that int to occur and you are not checking for those conditions. Most of the I2C stuff is for transmitting anyway. You can carve out the SSP int and message processor for the slave side and then do the master side like your are doing now.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group