Home - Search - Members
Full Version: Help GLCD port from 8051
mhel
Dec 22 2007, 3:17 PM
Hi,
I'm new to arm and microcontrollers, played with pic before but I decided I want to learn arm.
I already have a working LCD driver for t6963c, but I kind of like the buffering technique used in the attached. The driver attached is not mine I found it before I can't remember where actually. I was wondering if any1 could help port the code to gcc arm as I don't have knowledge of 8051 and kind of lost in the code. Or if anyone could just explain how it works I will try to understand it.
EDIT:
Forgot to tell, I'm using LPc2138 with WinARM

TIA.
8051_glcd.zip
shyam
Dec 22 2007, 11:20 PM
hi mhel....
it is much easier to have glcd in LPC2138 than 51

only thing... u must know how to handle tje gpios

a thread in corresponding topic is going on i wud like u to go thru it....

cause it is a small issue u can easily do it......

mhel
Dec 23 2007, 9:05 AM
Thanks for reply Shyam,

Yes, I have learnt how to control GPIOs, I also have a working LCD but I want to learn how to do the offscreen buffering ( i think that's what it's called). Although from what I have found out, the code uses external memory. I'm hoping it could still be done on the 2138 using the 32k ram.

shyam
Dec 23 2007, 9:47 AM
of course it can be done......

u r not using fonts in ur code....

i have use 18 fonts with my lpc 2148... no problem with that......

try it out...
ne problem i'll be there
mhel
Dec 24 2007, 8:02 AM
hi Shyam,

The attached is my attempt to port the code, but I got stuck, some definitions are not included,
particularly the XBYTES[] array, it's probably in one of the header or it's specific to '51.
The low level routine for the LCD works I know that for sure. I tried to adapt it to the code.

Is your 2148 LCD driver available to download?


Thanks.
shyam
Dec 24 2007, 8:17 AM
well if u really in need...
ok
i'll have it for download here.......
do u only want to show image on lcd???
mhel
Dec 24 2007, 9:25 AM
Thanks,

Basically, what I want is to draw the font/image in a buffer before actually sending it to the lcd, as it is done the 8051 code, I want to understand how he did it the e.g the mask[]

I won't mind taking a peek at your lcd code tho, thanks again.
shyam
Dec 24 2007, 9:50 AM
well mhel i am gonna upload a code .. just see if it helps... otherwise we will surely resume the discussion...
watch out here i'll let u know as soon as the code is uploaded

shyam
Dec 24 2007, 10:23 AM
hi mhel
u can download the library from

http://www.8051projects.net/downloads197.html
mhel
Dec 24 2007, 10:52 AM
I'll look into it.

thanks.

Edit;

This looks like the same code I got from lpc2000 yahoo group. which I already have working too.
I'm just having a hard time modifying it to output one character at a time instead of drawing a string.
I wanted it to accept newline character and move to the next line too.
The reason I like to have a buffered display is I wanted to implement a vertical scrolling text and from what i've read that's how I could achieved it. Any help on this would be greatly appreciated.
shyam
Dec 25 2007, 9:44 PM
hmm ,,
well then i m gonna convert that 51 code that too as early as possible... just be with me....
shyam
Dec 26 2007, 9:18 AM
hi mhel,
cudnt find the following definitions....
CODE:

byte_basso(dato);
 byte_alto(dato);


plz.. check if u have them n which file.....
mhel
Dec 26 2007, 9:52 AM
I couldn't find that part too, I assumed it's sending the low byte first then high byte,
that's what I did in my attempt. I think it's in Italian.

I only got that zip file. There was no contact infor for the guy, else I would have asked him.
mhel
Jan 5 2008, 4:02 PM
Hi,
I'm making some progress , I manage to display something but it's not as expected.
I'm using 5x8 font only. The text display overlaps, characters are too close to each other or the mapping is incorrect, the graphics is chopped on the bottom. I think it's related to the current_addr_pointer().

Shyam: if you have time, maybe you could look at the attached. I can't figure out where the value 1024 came from, 128x8=1024, but the original author uses 128x128 lcd, mine is 240x128. Also perhaps you could make changes on the struct, it's tedious to add those brackets in the array, I get warnings/errors without them. If you do then wbm() would have to be changed too I think.

this is how test it, same as in the original
CODE:

  do
    {
      i = 0;
      do
        {
          gotoxy(i, i);
          box(239-4*i, 127-4*i);
          refresh_LCD(0);                                               //refresh for each box
          pause(QUARTER_SEC);
        }while (i++ < 16);
      set_display(F5x8, (flag) ? NORMAL : REVERSE);
      flag = !flag;
    }while (flag);
   
        pause(FIVE_SEC);

        //clearlcd (ALL);

        // test fonts
        set_display(F5x8, NORMAL);
        gotoxy(2,2); wrstr("5/8 FONT");

refresh_LCD(0);
 


Thanks.
mhel
Jan 5 2008, 4:05 PM
7zip files is not supported , I forgot about it.
lcdt.zip

Edit: how do I update the attachment I want to reupload a new one???
mhel
Jan 5 2008, 5:41 PM
the box routine is working ok, somehow I'm limited to 127x63 size of box. still trying to find which to hack in the font drawing is still the same.

EDIT: fixed the box, parameters in hline/vline were signed char changed to int16_t, there's still problems
some pixels on the right are not drawn/erased.
EDIT2: now, the box is really fixed
changed in clearfiled()
CODE:
const uint8_t blank[] ={ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };

to:
CODE:
const uint8_t blank[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };


the font drawing is really tough I need help on that one, but I'm kinda a glad I got this going
shyam
Jan 6 2008, 5:42 AM
hi mhel got this attatchment....
will lokk on to it....
Ajay
Jan 6 2008, 5:58 AM
mhel wrote ...

7zip files is not supported , I forgot about it.
lcdt.zip

Edit: how do I update the attachment I want to reupload a new one???


if you want then i can add 7z extention to be uploaded.. but the reason is.. its not supported by all..
post a screenshot of your LCD.. wanna see the gfx
mhel
Jan 6 2008, 8:18 AM
Thanks guys, but I freaking did it my bit rotation was wrong, I just have that cut and paste from post somewhere didn't really know it's inner working, I actually attempted it in assembly, but got lost.
I still don't know where the 1024 value came from tho.

Shyam: Thanks for the time, maybe you should look at this new attachment and see what I'm missing, although it seems to be working I'd like to be able to place bitmap graphic too.

Ajay: I actually just found out about 7zip, it's free why not support it?

I attached a screenshot.
BTW, this is just a home project, I'm just a hobbyist, that's why I'm glad I found this site, with lots of good tutorials and such, not to mention the knowledgeable people that are willing to help. Thank you.


080106lcdt.zip
shyam
Jan 6 2008, 10:18 AM
hi mhel...
i understand how excited u wud be for this project runnning in front of u...
u have done a lot of hard work....

i hve been out of my office for a long time... cud not look on the code...
to save time if u cud just sent us the complete application... it wud save time...
cause i dont know which machine i'll be working on....
plus i wud request ajay to put it in download section as soon as the scrolling thing is done...
BTW i ve started working on menuing...
wud post the tested application/code soon...
shyam
Jan 6 2008, 10:33 AM
@mhel
but the original author uses 128x128 lcd, mine is 240x128


well if u talking abt the following function u r right
CODE:

static uint32_t current_addr_pointer (void)
/**************************************************************/
{
  return 1024 * selected_page + yStart*Nmax + xStart/8;
}
 


ok see...
using 5x8 pixel... =>
8 pixel y direction

128 *8 = 1024

=>one page = 1024

now if i want to select page 2 coordinates 30,40
so the function will return 1024 *2 + 30*5 + 40*8

i guess that is what the function is doing...

bottom line...
wether it be 240x128 or 128x128...
for complete page scan we need to scan 128
so doesnt matter..
it wud be 1024 in both the cases...
not tested on board just a logical suggestion
mhel
Jan 6 2008, 11:53 AM
shyam:
I'll try to clean it first then I'll upload it.

thanks.
mhel
Jan 6 2008, 2:20 PM
Hi Shyam,

this is the simple setup I have, to test the lcd.
pinouts are in the config.h. this is taken from WinArm samples, I use CodeBlocks as
as my editor, I like it, not keil but better than programmer's notepad.



winarm_lcdt.zip
mhel
Jan 9 2008, 3:11 AM
bottom line...
wether it be 240x128 or 128x128...
for complete page scan we need to scan 128
so doesnt matter..
it wud be 1024 in both the cases...
not tested on board just a logical suggestion


I have verified the above to be correct, I have changed it to 3840, and changed it back to 1024 and the behaviour is the same. I assumed, since I was using 240x128 and fontwidth of 8 that I needed 3840 bytes according to a document I read. Although I think my math skills is skewed I have 30columns by 16rows, does this mean I only need 480bytes of ram per page? or this calculation only applicable to Text mode?

BTW, I attempted to to draw bitmaps, but it only draws part of the image, please tell me what I missed thanks. The structure for IMG is defined with height, width, and the actual data.
CODE:
uint8_t draw_img(uint8_t x1, uint8_t y1, IMG * img)
{
  uint8_t x, y;
  uint8_t *iptr=img->data;
//  set_display(F5x8, NORMAL);
  gotoxy(x1,y1);
  x = x1;
  y = y1;
  while (y < y1+img->height)
    {
      while (x < x1+img->width/8)
        {
          framebuffer[current_addr_pointer()]=*iptr;
          iptr++;
          x+=1;
        }
      x=x1;
      y+=1;
      if (Nmax != img->width/8)//Nmax = 30
        {
          gotoxy(x,y);
        }

    }
  refresh_LCD(0);
  return x1 + img->width + 1;
}


Shyam: I appreciate your time on doing the scroll thing, I'll wait for it 'cause I doubt I'd be able to hack it. Thanks.
mhel
Jan 16 2008, 10:23 AM
I got the image drawing working, I can't believe it's this simple I had to hit my head a couple of times
CODE:
uint8_t draw_img(uint8_t x1, uint8_t y1, IMG * img)
{
  gotoxy(x1,y1);
  wrbm(img->width, img->height, img->data);
  refresh_LCD(0);
  return xStart + 1;//returns next x position
}


I guess if you look at the code for a long time it will just pop up
shyam
Jan 16 2008, 11:33 AM
congratulations.. mhel!!!!...
enjoy your work!!

mhel
Jan 17 2008, 1:11 PM
thnx shyam,

one question, in the lcd code, what do you think would be the posible uses of the function copy_page(), right now I have it commented out since i limit my framebuffer pages to just 1.
mhel
Feb 4 2008, 8:45 AM
I managed to add blinking cursor to lcd driver:
CODE:
static void set_cursor(uint8_t row, uint8_t col, uint8_t cursor)
{
  uint16_t addr;
  addr =  GHOME + (row/8)  + (col*30);
  lcd_setaddr(0x24, addr);
  if (cursor)
    lcd_sendcmd(0xf8 | ((7-row%8)));
  else
    lcd_sendcmd(0xf0 | ((7-row%8)));
}

void set_curpos(void)
{
  uint8_t i, c;
  c = yStart+8;
  cursortoggle ^= 1;
  for (i=0; i<8;i++){
//    set_cursor(xStart, yStart+i, cursortoggle); /* set vertical cursor position */
set_cursor(xStart+i, c , cursortoggle); /* set horizontal cursor position */
  }
}


the code above is independent of the framebuffer, It is called after the lcd is refreshed. Actually, it is called from a timer interrupt every 500ms,
I place a flag in refresh_LCD() and is checked in the interrupt if the cursor is to be displayed. xStart and yStart is global and primarily used in the framebuffer. I can't remember why I had the cursortoggle global too tho. the code is basically turning on/off 8pixels following the xStart & yStart.
Ajay
Feb 4 2008, 9:39 AM
great going mhel (whats your real name )
adding blinking cursor to LCD will keep controller busy, is it? coz gfx LCD has to be updated after every half sec or something.. what you say?
shyam
Feb 4 2008, 11:33 AM
he is a wise guy..
using interrupts..
there are lots of interrupt sources in arm that you can use mostly IRQ not much burden on the controller...!! ARM is supposed to handle this business @ low power
mhel
Feb 5 2008, 11:05 AM
I only needed the cursor display when I'm ask to input values via keyboard, it seems odd without the cursor, and the blinking is just aesthetic i thought it looks cool and the interrupt seems to be a good way of doing it.

mhel
Feb 13 2008, 6:47 PM
finally figured out how to scroll sweeet.
this works for a 5x8 font, need to change the hard values to variables
to match the font size used.

Note: this is for 240x128 dots LCD, 16rows 30columns 8x8dots 16*8*30=3840
so you know which to change to match your's.
CODE:
void scroll(void)
/**************************************************************/
{
    uint32_t i;
    // Row 15 is the end, this means we need to scroll up
    if (yStart >=128)
    {
        // Move the current text chunk that makes up the screen
        // back in the buffer by a line
        for (i = 0; i < 3840; i++)
        {
                framebuffer[i] = framebuffer[i+240];

        }
        // The last line should now be blank. Do this by writing 0's
        for (i = 3600; i < 3840; i++)//120*30
        {
            framebuffer[i] = 0x00;
        }
        // The cursor should now be on the last line.
        yStart = 120;

    }
}
Ajay
Feb 13 2008, 9:59 PM
sounds sweet..

make a small video i wanna see scrolling thingy..
abbas1707
Feb 14 2008, 6:13 AM
Ajay wrote ...

sounds sweet..

make a small video i wanna see scrolling thingy..

me tooooooooooo
tom_softi
Apr 17 2008, 5:32 PM
Hi all,
how have you connected your dsiplay to the LPC
have you used a level shifter from 3,3 to 5V or is it connected directly to the LPC port pins.

regards Tom
shyam
Apr 17 2008, 9:14 PM
level shifter is not required!!!..

the pins (data/ctrl) are 3v3 compattible . By the way which LCD u plan to use??

mhel
Apr 18 2008, 12:50 AM
Sorry guys for late reply, been busy. I was not able to take video of the scrolling, with t6963c scrolling does not look good since it causes ghosting I think that's the right term. I meant because it scrolls very fast the display is not as clear compared to when you scroll in a terminal.


tom_softi:
yes shyam is right I didn't use any level shifter, it depends on the lcd specs I guess. usually minimum turn on is 3.2v I think, and some of the LPC pins are 5v tolerant.




shyam
Apr 18 2008, 6:23 AM
i am working on Mukund Deshmukh's code for KS0108 adapted from the 51 code.
i am attaching the code .
i am facing a strange problem.
i can see data on only one half of the LCD.
i interchanged CS1 and CS2 pins thus now i can see data on the other half.. but still unable to access both at a time.
hope somebody wud help me out!

grlcd.rar
mhel
Apr 18 2008, 10:03 AM
shyam,
just curious, why is it that in glcd.h the defines for control pins are:
CODE:

#define LCD_CS2         BIT(10)  /* Chip Select Col1-64   P0.10*/
#define LCD_CS1         BIT(28)  /* Chip Select Col64-128 P0.28 */
#define LCD_RW                  BIT(31)  /* Read/Write  P031 */
#define LCD_DI                  BIT(6)  /* Data/Instr. P0.06 */
#define LCD_E                   BIT(26)  /* Enable P0.26 */
#define LCD_RST         BIT(27)  /* Enable P0.27 */
 


but when used in control it has 'G'
CODE:

#define LCD_CONTROL     (uint32_t)(GLCD_CS1|GLCD_CS2|GLCD_RW|GLCD_DI|GLCD_E|GLCD_RESET)
 


edit:
never mind I just saw the lcdinit and I guess it doesnt matter.
shyam
Apr 18 2008, 3:10 PM
u r right mhel...

but u can see in the code..


LCD_CONTROL is not used any where.. this is cause i have not started the cleaning job yet
shyam
Apr 18 2008, 7:55 PM
hello everybody!!!!

as always the code was perfect somehow the PIN P0.2 was not functional dont know why...

any ways i am pleased to announce that this code is working perfectly ..
so we have one more code for KS0108 taht can be uploaded to the library
Ajay
Apr 19 2008, 9:17 AM
well you can do that yourself add it.. will see u on chat and explain you how to do that
mhel
Apr 19 2008, 1:02 PM
could it be the pullup? P0.2 is an i2c pin.
shyam
Apr 19 2008, 2:25 PM
aha!!!
u got point there!!

|o| how cud i have missed it???
will check that and reply!

thanx Mhel
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Rickey's World © 2003 - 2007