1. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    Hi Guys,
    I just got a 24x17 graphics display working for character LCDs
    using their custom character RAM :)


    I'm looking to calc inverted angles now,
    and do a Pong with sound, if not some other game.
    I don't have to think about the custom chars anymore,
    I can set pixel coordinates, and will try a line/circle drawing routines.
    This will be fun :)

    I can't help thinking it's ten years too late for this,
    when graphics LCDs were not abundant, but everybody had these.
    Last edited: Oct 13, 2013
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Cool, I like it, but I doubt you can get a Pong game going, just not enough symbols to work with. LCD displays are damn useful so it's not wasted work.

    Besides, it's never too late to catch up <grin>
  3. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    It doesn't require symbols it's monochrome bitmap sprites :)
    Proper pixel accurate 24x17bit (51 byte) frame buffer.
    I'm rewriting the entire framebuffer for every frame.
    Not high enough res could be the limitation, but a single pixel ball,
    and single pixel width bats....
  4. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    Photos? Some people don't like going to boobtube and paying their service provider for large multi-Mb downloads just to see what it is...
  5. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    I'll see what I can do RB, It will probably get a page of it's own and be given away when it's done.
    A still photo only demonstrates that
    I can load eight chars into their locations and display them though.

    I'm having trouble with line and circle drawing routines.
    They usually are in C, and check for values below zero,
    where variables in the pic just wrap to 0xFF when decremented from zero.
  6. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    Here's the trouble where I'm finding the algorithms are usually in C,
    and want to look for values below zero.

    I was able to do a trick and check a value is above decimal 128,
    pretending that value is zero.
    This is so far only working if the destination point of the line has higher
    x and y coordinates than the start point..
    (ie. I can draw a line at any angle from x-0,y-0, to anywhere).

    Here is the difference in the code:

    Code ( (Unknown Language)):
    2. x0 = 3 : y0 = 3
    3. x1 = 21 : y1 = 11
    4. gosub drawline

    Code ( (Unknown Language)):
    2. drawline:
    3.     stepx = 0
    4.     stepy = 0
    5.     frac = 0
    6.     'a line is x0,y0 to x1,y1.
    7.     dy = y1 - y0
    8.     dx = x1 - x0
    10.     IF dy > 128 THEN
    11.     dy = dy - 1
    12.     stepy = stepy - 1
    13.     ELSE
    14.     stepy = 1
    15.     ENDIF
    17.     IF dx > 128 THEN
    18.     dx = dx - 1
    19.     stepx = stepx - 1
    20.     ELSE
    21.     stepx = 1
    22.     ENDIF
    24.     dy = dy << 1
    25.     dx = dx << 1
    27.     'draw pixel
    28.     px = x0 : py = y0
    29.     gosub setpixel
    31.     IF (dx > dy || dx > 128) THEN
    33.     frac = dy - (dx >> 1)
    34.     WHILE x0 != x1
    35.     IF (frac < 128) THEN
    36.     y0 = y0 + stepy
    37.     frac = frac - dx
    38.     ENDIF
    39.     x0 = x0 + stepx
    40.     frac = frac + dy
    41.     'draw pixel
    42.     px = x0 : py = y0
    43.     gosub setpixel
    44.     WEND
    46.     ELSE
    48.     frac = dx - (dy >> 1)
    49.     WHILE y0 != y1
    50.     IF (frac < 128) THEN
    51.     x0 = x0 + stepx
    52.     frac = frac - dy
    53.     ENDIF
    54.     y0 = y0 + stepy
    55.     frac = frac + dx
    56.     'draw pixel
    57.     px = x0 : py = y0
    58.     gosub setpixel
    59.     WEND
    61.     ENDIF
    63. return
    ... and the original C I always used on gfx platforms:

    Code ( (Unknown Language)):
    2. static void drawLine(int x0, int y0, int x1, int y1, int color, Color* destination, int width)
    3. {
    4.     int dy = y1 - y0;
    5.     int dx = x1 - x0;
    6.     int stepx, stepy;
    8.     if (dy < 0) { dy = -dy;  stepy = -width; } else { stepy = width; }
    9.     if (dx < 0) { dx = -dx;  stepx = -1; } else { stepx = 1; }
    10.     dy <<= 1;
    11.     dx <<= 1;
    13.     y0 *= width;
    14.     y1 *= width;
    15.     destination[x0+y0] = color;
    16.     if (dx > dy) {
    17.         int fraction = dy - (dx >> 1);
    18.         while (x0 != x1) {
    19.             if (fraction >= 0) {
    20.                 y0 += stepy;
    21.                 fraction -= dx;
    22.             }
    23.             x0 += stepx;
    24.             fraction += dy;
    25.             destination[x0+y0] = color;
    26.         }
    27.     } else {
    28.         int fraction = dx - (dy >> 1);
    29.         while (y0 != y1) {
    30.             if (fraction >= 0) {
    31.                 x0 += stepx;
    32.                 fraction -= dy;
    33.             }
    34.             y0 += stepy;
    35.             fraction += dx;
    36.             destination[x0+y0] = color;
    37.         }
    38.     }
    39. }
    I wonder what of the C compilers that are for 16F pic microcontrollers?
    Maybe they don't do signed integers either?

    Any assistance appreciated :)
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
  8. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    I've used C30, Problem is I'd have to port the rest.
    It's in PicBASIC with inline RISC, so I can work with either.

    I sorted out the line drawing :)
    Currently the routine is fine if both destination coords are greater than the source point coords,
    so if for example, the destination y coord is smaller,
    I just reference the original source y coord, and invert every pixel point along the y axis,
    so the correction is made as I draw.
    That means there are four checks of coordinate values (greater and lower) before drawing a line, but it works though.
  9. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    If you wish to stick with Basic OshonSoft sells a reasonably priced basic compiler. Trial version available for download.

    I used this years back and found it quite serviceable.
  10. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    I robbed Circle drawing from another BASIC library that deals with real graphics LCDs.

    Still at odds with BASIC.. It appears if you want trig, you have to get a cordic lib working,
    and it consumes a lot of memory on the smaller pics.
    I think I might try C30 again next time, I think it did have trig, and standard math.
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    You only get what you pay for. If you just need unsigned byte wide quantities you get a tiny math library (if any).

    You start including long integers, signed integers, or floating variables the library grows.

    Trig functions too? Damn... you may be pushing it there, especially if you want any speed.

    Far better to precompute the circle and store the resulting data on the PIC.
  12. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    In the end it's all aiming at my own hardware & software GPS.
    Point rotation is a must for track up display, even if it is only a 2D GPS.
    Also need trig and floats to calc bearing & distance, Sun & moon calcs, etc.
    I have done them on two higher level platforms.
    I don't know if I'll ever get to doing the full hardware, but might as well be playing with the capable stuff :)

    I was thinking of using one of the dspics... I write for one with C30
    with SD card, etc... More that I modified an existing project, but it looked good.

    Speaking of pre-computing,.. now I have lines, I can just pre-compute (with an iPhone program)
    the 3D rotated points for this cube, and animate it without the trig.
    3D spinning cube would be a first for character based LCDs I think :D

  13. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    How are you going to draw to the pixels between characters Art?

    The text LCDs I've seen (16x1, 16x2, 20x2 etc) only have 5x7 pixels implemented for each char on the LCD glass.

    Or are you using some special type of text LCD?
  14. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    The drawing in the post above is representing the display,
    and the highlighted pixels are the invisible pixels between chars and lines.
    The only difference is I used the invisible line to the right of this drawing
    because that's 24 pixels across, an even three bytes per line, 51 bytes total.

    Luckily they are precisely the right size of the real pixels.
    They are valid to write to, you just can see them.
    It's not too bad because the display is animated,
    but that is also why I can't do an analogue clock face... the hands would
    be invisible at 90 degree increments.

    PicBASIC Pro source, Hex, Doc & Schematic are here:

    I will get some pics up... pics do capture a bit of movement because the LCD is slow.
  15. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    I think you can tell they are moving:

  16. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Art: You really need to get a graphic LCD.

    If you don't do it sooner then later you'll be tossing out a lot of code directed at the alphanumeric LCD.

    And the PIC32's sure do have lots of code and data space. Largest hobby drawback is I don't think any come in a DIP, but things like the Bit Whacker can help make up for this.
  17. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    It's not tossing it out, it's compatible.
    The GLCD I'm getting is done by setting pixel coordinates too.

    The point of it is really in doing it on that LCD.
    For anything less than a big project, I'm happy enough to use my iPhone.
    It's difficult to justify making a big thing unless it can offer something my phone can't
    ... unless of course it is a major project the likes of free mapping GPS, etc.
  18. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    Great photos Art, thank you. :)

    I second what ErnieM said, you would be great with a GLCD.

    You can get cheap 128x64 single colour GLCDs from ebay, and do stuff like this;

  19. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    Of course :) I would just reach for my phone though.
    I don't consider that I'm missing out.

    I much enjoy programming for micros over higher level graphics platforms
    because of the bare metal nature of micros... even BASIC for a micro seems like very pure programming.
    I just can't think of much that I need one for, where I wouldn't use an existing machine.
    Not to say there aren't countless uses.. but I'm a hobby enthusiast..
    the thing has to serve me at home.
  20. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    The GLCD type in that photo can be driven very easily from a micro, it just takes a couple more drive pins. You can re-use most of your graphics code for making circles, boxes etc.

    They can be bought for about $7-$8 these days which is comparable to what 16x2 text LCDs cost a couple of years back.