2x16 LCD Graphics :)


Results 1 to 40 of 52

Threaded View

  1. #8
    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.

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