2x16 LCD Graphics :)


Closed Thread
Results 1 to 40 of 52

Hybrid View

  1. #1
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 2x16 LCD Graphics :)

    Thanks Guys,
    I am having some trouble with diagonal lines and circles.
    When you use a real gfx display with PBP, is it usually the display that
    handles the lines and circles, or is it done in PBP?

    I'm finding the algorithms are usually in C, and all seem to want to look
    for values below zero (signed integer variables), where one of these
    variables would wrap back to 0xFF if you decremented from zero using PBP

    For the only diagonal lines in the video, I was able to do a trick and
    check a value is above #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:
    x0 = 3 : y0 = 3
    x1 = 21 : y1 = 11
    gosub drawline

    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

    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 pics.
    Maybe they don't do signed integers either?
    If I could compile the original C source in a pic C compiler,
    and then disassemble it, I could have the result in RISC asm.
    Last edited by Art; - 13th October 2013 at 03:19.

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: 2x16 LCD Graphics :)

    Quote Originally Posted by Art View Post
    I am having some trouble with diagonal lines and circles.
    When you use a real gfx display with PBP, is it usually the display that
    handles the lines and circles, or is it done in PBP?
    In a real graphic LCD, it is the user who draws the lines / circles using Bresenhams algorithm or a variant. PBP, C or ASM is just a matter of choice.

    I am curious to know why you want to use a character lcd this way other than for the thrill of doing it. You only get 8 programmable characters which is about a 4th of the 16x2 display. Your demos too show repeated patterns. It is much more challenging and fun to get a graphic lcd come upto video speed (20fps and more).

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 2x16 LCD Graphics :)

    It is for the thrill.. and I figure the work is not wasted, because these LCDs do still get use.
    I already did an LED matrix display with games, scroller etc., and I don't think it is getting any faster.
    Also, I have not written for pics in some time, and needed something to get going.
    There is room to duplicate the graphics screen, but for a practical application,
    I figure the rest of the screen would have some text on it.

    I have solved the line drawing, but if you have a way to draw circles in PBP it
    would be appreciated At the moment my circles are perfect squares of the
    correct radius, but I'm keeping that for squares since it beats defining all the corner coordinates

    I would not buy a gfx LCD if I couldn't do the graphics, so it's a good way to come up with
    the routines now. I would still like to do my own hardware/software mapping GPS one day.

    I do plan to give it away when it's finished and cleaned up.


    ps to mods, it would be great if you could delete every video posted here
    (can seem to delete/edit my posts)
    I've done the C-64/Amiga style Megademo
    Last edited by Art; - 13th October 2013 at 06:22.

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: 2x16 LCD Graphics :)

    Videos removed.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 2x16 LCD Graphics :)

    Thanks Robert, I combined everything into one retro demo:



    I robbed the circle drawing from a GLCD code sample here, and added a bit more.
    There are 10 sections to the demo, but they only last a few seconds each.
    The trick at the end is what I should have started with to trick people to thinking
    I had the entire display

    It is almost ready to go, I just have to make sense of the source for others.
    Last time I released a project, there were three different revisions of matching
    hardware and software improvements with schematics,
    and although others got it working, it caused confusion, and years of follow up for me.
    Being mindful of that this time round, the schematic is in the PBP manual



    The only differences are this is a 16F628A (instead of 16F84/A in the manual),
    the LCD backlight is powered by the pic (RB6) for the strobe effect in the video,
    and the pic is driven with an 8MHz crystal to match the speed in the video.
    The clock speed is not critical though.
    The serial Rx pin in the familiar looking diagram is not implemented.

    If you make a board for this, it's still tentative.
    LCD R/W pin may need to be accessed later, so it might pay to wire
    it to somewhere accessible before wiring it to ground to mod later
    (I heard you can rip all of the character graphics from the LCD itself).
    It should also get a couple of buttons.
    Cheers, Art.

  6. #6
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: 2x16 LCD Graphics :)

    WARNING: Video may trigger epyleptic seizure in some viewers.

    Use 3D glasses under welding goggles as protection.



    Awesome stuff Art.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: 2x16 LCD Graphics :)

    Here it is:
    http://www.freewebs.com/defxev/LC2D.zip

    Interestingly... I realised this is one of the two LCDs I bought off Melanie here ages ago:
    http://www.picbasic.co.uk/forum/show...=2298#post2298
    Funny that. There was not much fancier at the time, but now the options are endless.

    I always get that last little nice feature working AFTER the distribution

Similar Threads

  1. Need advice with LCD 2x16
    By fratello in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th April 2011, 06:58
  2. 2x16 lcd problem
    By k3v1nP in forum mel PIC BASIC
    Replies: 11
    Last Post: - 30th October 2008, 04:46
  3. graphics lcd with lcdout style serial??
    By reaper0995 in forum Serial
    Replies: 4
    Last Post: - 27th March 2008, 19:57
  4. small 2X16 LCD
    By Ron Marcus in forum Off Topic
    Replies: 2
    Last Post: - 26th October 2007, 20:37
  5. OT: KS0108 Graphics LCD control question
    By Archilochus in forum General
    Replies: 2
    Last Post: - 18th December 2004, 18:23

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts