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

Help in programming Graphic LCD with 18F4520

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



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

Help in programming Graphic LCD with 18F4520
PostPosted: Wed Aug 28, 2013 12:27 am     Reply with quote

Hi,
I'm interfacing KS0108 GLCD with PIC18F4520 controller. Compiler: CCS C 4.114. I have read the datasheet of KS0108 GLCD. But still i feel difficult in writing the code. I want to display "Hellow" in GLCD.

As a newbie in Graphic LCD, i tried CCS example and it was working good.

All i want to do is, making my font size as flexible. In CCS C compiler, there are only 2 font sizes which are 5x7 and 10x14. There are some instances where i will display some big size characters than 10x14. Also in CCS, there are inbuilt commands to use the X and Y addresses.

Now I'm writing the code as mentioned in datasheet. I want to display a character 'H' in the display. Please check initialization is correct? how to define hex values for character 'H'? Please help.

Code:
unsigned char data[] = {127,127,8,8,127,127,0,0};  // H, 8x8

void GRAPHIC_LCD_INIT()
{
   output_high(RESET);   // RST connected to PIN_C0
   output_high(CS1);      // CS1 connected to PIN_B0
   output_high(CS2);     //  CS2 connected to PIN_B1
   
   glcd_cmd(0x3F);      // Display ON

    glcd_cmd(0xB8);      // Page selection - Page 1
    glcd_cmd(0x40);      // Column selection
         
}

void glcd_cmd(unsigned char c)
{
   output_d(c);
   output_low(RS);
   output_low(RW);
   output_high(EN);
   delay_ms(15);
   output_low(EN);
}

void glcd_data(unsigned char z)
{
   output_d(z);
   output_high(RS);
   output_low(RW);
   output_high(EN);
   delay_ms(15);
   output_low(EN);
}

void main()
{
        int i;
   GRAPHIC_LCD_INIT();

   while(1)
   {   
      glcd_cmd(0xC0);   // display start line
                for (i = 0; i < 8; i++)
                {
           glcd_data(data[i]);
                }
   }
}


Thanks in advance Smile
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Thu Aug 29, 2013 5:00 am     Reply with quote

After struggling a bit, i have finally displayed a character 'H' in the Graphic LCD.

Could anyone explain me a logic how to display a character 'H' with 15 x 15 height and width ???

Or do have any glcd library??

Please help!!!
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Fri Aug 30, 2013 4:19 am     Reply with quote

any help please!!! Totally lost.

How can i use "glcd.c" to display a font size of 15 x 15?

any help would be appreciated much Smile

Thanks in advance Smile
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Aug 30, 2013 6:35 am     Reply with quote

First place I'd go to is the manufacturer of the LCD Module and see what resources they offer.They may have a program that generates the required bit patterns for the pixel patterns for whatever you're looking for.
The datasheet for the module should have most if not all of the details you need.
If not, try 'Google' for 'pixel generator' program for your module.
Obviously you're not the first to use it, so odds are good someone else has done it and may have a 15x15 'driver ' for you.

hth
jay
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Aug 30, 2013 8:26 am     Reply with quote

Hi,

It's really not that hard! Study how the 5x7 character function works, and expand it! Each column of your font will require 2 bytes of data, by 15 rows, for a total of 30 bytes of data. I used 'GLCD Font Creator' to create my character data for this purpose.

I read in the data column by column, and then use 'Make16' to create a 16 bit word for the column data. Work thru the word using the 'bittest()' function to see of the bit is 0 or 1, and then set the pixel appropriately! Repeat for all columns, and you are done!

I'd share my routine, but I'm traveling in China now without my CCS code. If you are really still stuck, I can post my code in about 10 days when I return to the US.

John
hemnath



Joined: 03 Oct 2012
Posts: 242
Location: chennai

View user's profile Send private message

PostPosted: Fri Aug 30, 2013 9:48 pm     Reply with quote

Thanks temtronic & ezflyr for your kind reply.

I have used 'GLCD Font Creator' to create the character data.

For character 'H' size of 15 x 15, the data is,

const unsigned char data[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x7F, 0x3F, 0x7F, 0x3F, 0x7F, 0x3F, 0x7F, 0x3F, 0x7F, 0x3F, 0x7F, 0x3F, 0x7F, 0x3F, 0x7F, 0x3F, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

But the problem im facing is, for first 15 values, the page would be 0xB8 and for next 15values, the page would be 0xB9. Am i right???

@ezflyr: If you could post the sample code of yours, i could learn from your code. I have studied how 5 x 7 works and implemented. In the case of 5 x 7, i could use only one page. But for 15 x 15, in need of using 2 pages to display a character. I really don't find a logic. That's where i got stucked. Waiting for your reply guys.

Thanks you Smile
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Aug 30, 2013 10:25 pm     Reply with quote

Hi,

I'll post my code when I return from my travels. In the meantime I recommend you get some graph paper, and figure out how the data you've got represents a given character. Your 15x15 character is going to be two bytes "tall", by 15 2-byte groups wide. Just like the 5x7 character function, you need to loop thru all of the vertical bits, and all the horizontal byte groups. Seriously, do it with graph paper, and I'll bet you can see it yourself!

BTW, I'm confused about your reference to 'pages'? Can you please elaborate on this?

John
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Sat Aug 31, 2013 1:25 am     Reply with quote

On old compilers, and with PIC16's, you had to 'worry' about memory pages. However provided you compiler is within the last few years old, with the PIC18, you don't have to worry. The compiler will happily generate arrays several KB in size, and handle paging for you. However you need to be remembering just how much memory the font will use. Characters 32 to 127, in 15*15, will use 96*30bytes = 2880bytes of the ROM.

You can basically take the font array as generated by GLCD font creator, and just change the declaration line only to:

const int8 my_font[] {

and paste the data directly from the program. The syntax is correct for CCS.
Each character takes 30 bytes to store (15*2 bytes), versus the 5 bytes in the original font. Obviously 'no_chars' will depend on how many characters you encode.

The large amount of ROM needed, is why the demo, sticks to a font that can fit each line in a single byte. Remember the standard code can display the font multiple size if required, so set 'size' to 3, and it displays 15*21 text. The point about coding a larger font, is that it allows much finer detail.

Then 'PixelData' has to expand to 15*int16, instead of using bytes (simpler - see below).
The 'wrap' point has to test at +15, not +5.
The memcpy's, have to copy 30bytes into PixelData.
If you just use a single, single dimensional array, the copy becomes:
memcpy(pixelData, my_font+((*textptr - ' ')*30), 30);

Then j=0 j<15
Then k=0 k<15

Because you change 'PixelData' to an int16, rather than int8, each line in the array still holds the data for each line in the characters. Much simpler.

That is it.

Best Wishes
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