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 support@ccsinfo.com

LCD.C library

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



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

LCD.C library
PostPosted: Fri May 29, 2009 2:21 am     Reply with quote

Hello all,

I have recently purchased a TRI-T 20x4 LCD Display and I am trying to interface a 16f877 to it. I am using the LCD.C library to control the LCD, using the lcd_init() functions etc.
I am unfortunately unable to initialise the screen and display anything on it. I have not controlled an LCD before and do not know where to start checking for errors.
I have connected the PIC pins (D0 - D7) to the LCD lines
D0 - Enable
D1 - RS
D2 - R/W
D4>D7 - D4>D7

The screen is TMBC20443B
datasheet 1 http://3t-lcd.com/TMBC20433B-XX.pdf
datasheet 2 http://www.zxstevefiles.yolasite.com/resources/pdf1.pdf
Any help would be most appreciated

SHarris
Ttelmah
Guest







PostPosted: Fri May 29, 2009 2:39 am     Reply with quote

Have you also connected the power as shown in figure 5.1, on the first sheet. You _need_ the Vcl or Vee connection, before anything will be 'seen'. The GND connection for the display, needs to be the same line as the 0v for the PIC.

Best Wishes
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Fri May 29, 2009 3:31 am     Reply with quote

Gnd connection is same as PIC (it comes from same VRegulator)
I have connected as in 5.1
+5 ----[res]------[res]-----GND
....................|
................VCI tap

(Ignore the dots, the bulletin board script ignores whote space!!)

Its about 3V going into VCI.
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Fri May 29, 2009 4:11 am     Reply with quote

Looking at the lcd.c source (with CCS install) should this library work with this screen, I dont know what to look for in the source to ensure that it is working?

Thanks
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Fri May 29, 2009 8:58 am     Reply with quote

I have now got to the point where I am trying to understand the lcd_init() function. I am trying to re-write it in my code with the timings / settings needed to control the LCD.
Reading the LCD controller http://www.lcdshop.uk.com/dpdf/S6A0073.pdf it seems that if I want to talk to the LCD in 4 bit mode I need to send each string twice.
Is this correct for control bits??

(The only function I am trying to change from lcd.c is the lcd_init)

Here is what I am doing: (TAKEN FROM PG 13 of Datasheet from
http://www.zxstevefiles.yolasite.com/resources/pdf1.pdf)

Code:

set_tris_d(LCD_WRITE);
lcd.rs=0;
lcd.rw=0;
lcd.enable=0;
delay_ms(10);
lcd_send_nibble(2);                4 bit interface
delay_ms(5);
lcd_send_nibble(2);                4 bit interface
delay_ms(5);
lcd_send_nibble(2);                4 bit interface
delay_ms(5);
lcd_send_nibble(2);                4 bit interface
delay_ms(5);

lcd_send_nibble(8);                2 line mode
delay_ms(5);
lcd_send_nibble(8);                2 line mode
delay_ms(5);

lcd_send_nibble(0);
delay_ms(5);
lcd_send_nibble(0);
delay_ms(5);

lcd_send_nibble(12);                Display On
delay_ms(5);
lcd_send_nibble(12);                Display On
delay_ms(5);

lcd_send_nibble(0);
delay_ms(5);
lcd_send_nibble(0);
delay_ms(5);

lcd_send_nibble(1);                  Display Clear
delay_ms(5);
lcd_send_nibble(1);                  Display Clear
delay_ms(5);

lcd_send_nibble(0);
delay_ms(5);
lcd_send_nibble(0);
delay_ms(5);
lcd_send_nibble(6);                  Increment Mode / Entire Shift Off
delay_ms(5);
lcd_send_nibble(6);                  Increment Mode / Entire Shift Off
delay_ms(5);

output_high(PIN_A0);               Turn on LED to show OK





is there something wrong here?? Or have I mis-understood this completely??
Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 29, 2009 11:52 am     Reply with quote

According to your link here, the LCD has a solder-bridge jumper option
on the back. It can be jumpered for SPI mode or the normal 4/8 bit
parallel interface. Look on the back of your LCD to see which way it's
jumpered:
http://3t-lcd.com/TMBC20433B-XX.pdf

Your LCD can probably be used with the Flex lcd 4x20 driver:
http://www.ccsinfo.com/forum/viewtopic.php?t=28268

On page 11 of the following link, in the Extended Function Set section,
it shows there is a bit to enable 4-line mode. That bit needs to be set = 1
for your LCD.
http://www.zxstevefiles.yolasite.com/resources/pdf1.pdf
I think you can do this by modifying the init table in the Flex driver.
Change the number of elements to 5, and add one line, as shown in
bold below:
Quote:

int8 const LCD_INIT_STRING[5] =
{
0x20 | (lcd_type << 2), // Set mode: 4-bit, 2+ lines, 5x8 dots
0xc, // Display on
1, // Clear display
6, // Increment cursor
0x09 // Enable 4-line display
};
SteveyG



Joined: 11 May 2009
Posts: 1

View user's profile Send private message

PostPosted: Fri May 29, 2009 3:21 pm     Reply with quote

3V on Vee is a bit high, you'll probably see nothing on the LCD. The typical range is usually more like 0.8V to 1.6V.
Guest








PostPosted: Thu Jun 04, 2009 3:46 am     Reply with quote

After I have added the extra line
Quote:
int8 const LCD_INIT_STRING[5] =
{
0x20 | (lcd_type << 2), // Set mode: 4-bit, 2+ lines, 5x8 dots
0xc, // Display on
1, // Clear display
6, // Increment cursor
0x09 // Enable 4-line display
};

Do I need to add to increase the count on the lcd_init() LCD_INIT_STRING[i]]?
Code:

void lcd_init()
.
.
.
for (i=0;[b]i<=4[/b];++i)
    lcd_send_byte(0, LCD_INIT_STRING[i]];
}

I would assume so as the number of strings in the array has increased to 5 but this does not work for some reason??
Also on my LCD the starting addressed for the lines are 0x00, 0x20, 0x40 and 0x60, but when I put these into the lcd_goto(x,y) string in the LCD420.c file the screen fills up with rubbish data!!
What can be the problem??
Thanks
Steve
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 04, 2009 4:08 am     Reply with quote

If you're using the Flex 4x20 lcd driver from here,
http://www.ccsinfo.com/forum/viewtopic.php?t=28268
then the for loop uses 'sizeof' to find the size of the array.
In other words, it's done for you, automatically.
Code:
for(i=0; i < sizeof(LCD_INIT_STRING); i++)

I suggest that you use the Flex driver from the link above.
Guest








PostPosted: Thu Jun 04, 2009 4:37 am     Reply with quote

I have now implemented the Flex driver code but I still cannot add the 5th INIT string (the LCD seems to freeze / not respond to putc etc commands).
Heres what I get:-
Without the Extended Function Control (Four Line Mode)
(I try to display 1, 2, 3 or four depending on what line it is)
Code:
lcd_goto(1,1)
lcd_putc('1')
shows 1 on line 1

Code:
lcd_goto(1,2)
lcd_putc('2')
shows 2 on line 3

Code:
lcd_goto(1,3)
lcd_putc('3')
does not show 3

Code:
lcd_goto(1,4)
lcd_putc('4')
does not show 4

Code:
lcd_goto(21,1)
lcd_putc('3')
shows 3 at 9 chars along on line 2

Code:
lcd_goto(21,2)
lcd_putc('4')
shows 4 at 9 chars along on line 4

What is going on??
Thanks
Steve
Guest








PostPosted: Thu Jun 04, 2009 9:04 am     Reply with quote

I have had a good re-read of the data sheet and it says that to use the Extended Function Set (on page 11) the RE pin has to pulled high, is this done from my uC??
Is the RE pin on the LCD the same as E (PIN 6)??
Thanks
Steve
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 04, 2009 11:39 am     Reply with quote

You're correct. There is an enable bit. Add the following changes:
Quote:

int8 const LCD_INIT_STRING[7] =
{
0x20 | (lcd_type << 2), // Set mode: 4-bit, 2+ lines, 5x8 dots
0xc, // Display on
1, // Clear display
6, // Increment cursor
0x2c, // Enable writing to Ext. register
0x09, // Enable 4-line display
0x28 // Disable writing to Ext. register

};

Make sure that the number of elements is set to 7.

When I first suggested this solution I thought there was an enable bit
but the data sheet wasn't that easy to read, so I didn't see it.
It didn't say "Extended Function Register Enable bit" or something like
that. It just said "RE" which wasn't very clear.
Guest








PostPosted: Fri Jun 05, 2009 1:17 am     Reply with quote

I had the same confusion,
I have spent the last number fo hours trying to find where that bit is set!!

Thanks for your help, I will attempt the changes today.
Steve
Guest








PostPosted: Fri Jun 05, 2009 1:48 am     Reply with quote

Hmm,
I thought that was it!!
Obviously not!!
I have added the extra lines into the LCD_INIT_STRING but the screen now displays
'1' on line 1
'2' on line 3 (in effect line 2)
'}}}}}}}}}}}}}}}' starting at 9 bytes along line 2
'}}}}}}}}}}}}}}}' starting at 9 bytes along line 4

Thanks
Steve
sjharris



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

PostPosted: Fri Jun 05, 2009 3:05 am     Reply with quote

When I return the LCD to two line mode (remove the extra LCD_INIT_STRING) and I try to print something to 17,1 it also copies the data to 1,2 (physical line 2, i.e. second line down). Does my LCD think its a 4 x 16??
Something is not right here, still cant work it out!!
Steve

edit edit edit:
ARGH Sorted it!!!!!

For some reason in four line mode the screen filled half of line 2 and 4 with funny data, when I cleared the screen, again, I was able to write successfully to all four lines.

THANKS ALL FOR YOUR HELP!!!
Steve
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