Pic Game

Thread Starter

Art

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

http://www.youtube.com/watch?v=1xq8xJqbkNA

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:

ErnieM

Joined Apr 24, 2011
8,415
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>
 

Thread Starter

Art

Joined Sep 10, 2007
806
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>
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....
 

THE_RB

Joined Feb 11, 2008
5,438
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...
 

Thread Starter

Art

Joined Sep 10, 2007
806
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...
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.
 

Thread Starter

Art

Joined Sep 10, 2007
806
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:

Rich (BB code):
x0 = 3 : y0 = 3
x1 = 21 : y1 = 11
gosub drawline

Rich (BB code):
drawline:
	stepx = 0
	stepy = 0
	frac = 0
	'a line is x0,y0 to x1,y1.
	dy = y1 - y0
	dx = x1 - x0

	IF dy > 128 THEN
	dy = dy - 1
	stepy = stepy - 1
	ELSE
	stepy = 1
	ENDIF

	IF dx > 128 THEN
	dx = dx - 1
	stepx = stepx - 1
	ELSE
	stepx = 1
	ENDIF

	dy = dy << 1
	dx = dx << 1

    'draw pixel
	px = x0 : py = y0
	gosub setpixel
    
	IF (dx > dy || dx > 128) THEN

    frac = dy - (dx >> 1)
    WHILE x0 != x1
    IF (frac < 128) THEN
	y0 = y0 + stepy
 	frac = frac - dx
	ENDIF
    x0 = x0 + stepx
    frac = frac + dy
    'draw pixel
  	px = x0 : py = y0
	gosub setpixel
    WEND

	ELSE

    frac = dx - (dy >> 1)
    WHILE y0 != y1
    IF (frac < 128) THEN 
	x0 = x0 + stepx
	frac = frac - dy
	ENDIF
    y0 = y0 + stepy
    frac = frac + dx
    'draw pixel
	px = x0 : py = y0
	gosub setpixel
    WEND

	ENDIF

return
... and the original C I always used on gfx platforms:

Rich (BB code):
static void drawLine(int x0, int y0, int x1, int y1, int color, Color* destination, int width)
{
	int dy = y1 - y0;
	int dx = x1 - x0;
	int stepx, stepy;
	
	if (dy < 0) { dy = -dy;  stepy = -width; } else { stepy = width; }
	if (dx < 0) { dx = -dx;  stepx = -1; } else { stepx = 1; }
	dy <<= 1;
	dx <<= 1;
	
	y0 *= width;
	y1 *= width;
	destination[x0+y0] = color;
	if (dx > dy) {
		int fraction = dy - (dx >> 1);
		while (x0 != x1) {
			if (fraction >= 0) {
				y0 += stepy;
				fraction -= dx;
			}
			x0 += stepx;
			fraction += dy;
			destination[x0+y0] = color;
		}
	} else {
		int fraction = dx - (dy >> 1);
		while (y0 != y1) {
			if (fraction >= 0) {
				x0 += stepx;
				fraction -= dy;
			}
			y0 += stepy;
			fraction += dx;
			destination[x0+y0] = color;
		}
	}
}
I wonder what of the C compilers that are for 16F pic microcontrollers?
Maybe they don't do signed integers either?

Any assistance appreciated :)
 

Thread Starter

Art

Joined Sep 10, 2007
806
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.
 

ErnieM

Joined Apr 24, 2011
8,415
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.
 

Thread Starter

Art

Joined Sep 10, 2007
806
I robbed Circle drawing from another BASIC library that deals with real graphics LCDs.
http://www.youtube.com/watch?v=1xq8xJqbkNA

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.
 

ErnieM

Joined Apr 24, 2011
8,415
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.
 

Thread Starter

Art

Joined Sep 10, 2007
806
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.
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

 

THE_RB

Joined Feb 11, 2008
5,438
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?
 

Thread Starter

Art

Joined Sep 10, 2007
806
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:
http://www.freewebs.com/defxev/LC2D.zip

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

ErnieM

Joined Apr 24, 2011
8,415
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.
 

Thread Starter

Art

Joined Sep 10, 2007
806
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.
 

THE_RB

Joined Feb 11, 2008
5,438
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;

 

Thread Starter

Art

Joined Sep 10, 2007
806
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;

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.
 

THE_RB

Joined Feb 11, 2008
5,438
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.
 
Top