CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

GLCD initialization problem ST7565
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 20059

View user's profile Send private message

PostPosted: Mon Jan 30, 2017 1:11 pm     Reply with quote

The obvious thing is your addressing is wrong. The first command is meant to carry the high nibble of the address. The second the low nibble. You are sending these the wrong way round....
jamalavedra



Joined: 25 Oct 2016
Posts: 62

View user's profile Send private message

PostPosted: Tue Jan 31, 2017 11:32 am     Reply with quote

Great, apparently it works now.
I am trying to use an algorithm (Bresenham's algorithm) in order to draw lines and make rectangles. The rectangles get drawn in the display and everything but they repeat several times column-wise.

Apparently it can't be anything to do with the code of the rectangle or lines because it does this regardless if I draw circles, rectangles or lines. Any thoughts on why this might happen?

Apart from that, I can't figure out what is the mistake in the code when writing letters or numbers. When used to write something, strings of lines appear were the letters should be.

Code:

bounding_box_t draw_text(char *string, unsigned char x, unsigned char y, unsigned char *font, unsigned char spacing) {
   bounding_box_t ret;
   bounding_box_t tmp;

   ret.x1 = x;
   ret.y1 = y;

   spacing += 1;

   // BUG: As we move right between chars we don't actually wipe the space
   while (*string != 0) {
      tmp = draw_char(*string++, x, y, font);

      // Leave a single space between characters
      x = tmp.x2 + spacing;
   }

   ret.x2 = tmp.x2;
   ret.y2 = tmp.y2;

   return ret;
}

bounding_box_t draw_char(unsigned char c, unsigned char x, unsigned char y, unsigned char *font) {
   unsigned short pos;
   unsigned char width;
   bounding_box_t ret;

   ret.x1 = x;
   ret.y1 = y;
   ret.x2 = x;
   ret.y2 = y;

   // Read first byte, should be 0x01 for proportional
   if (font[FONT_HEADER_TYPE] != FONT_TYPE_PROPORTIONAL) return ret;

   // Check second byte, should be 0x02 for "vertical ceiling"
   if (font[FONT_HEADER_ORIENTATION] != FONT_ORIENTATION_VERTICAL_CEILING) return ret;

   // Check that font start + number of bitmaps contains c
   if (!(c >= font[FONT_HEADER_START] && c <= font[FONT_HEADER_START] + font[FONT_HEADER_LETTERS])) return ret;

   // Adjust for start position of font vs. the char passed
   c -= font[FONT_HEADER_START];

   // Work out where in the array the character is
   pos = font[c * FONT_HEADER_START + 5];
   pos <<= 8;
   pos |= font[c * FONT_HEADER_START + 6];

   // Read first byte from this position, this gives letter width
   width = font[pos];

   // Draw left to right
   unsigned char i;
   for (i = 0; i < width; i++) {

      // Draw top to bottom
      for (j = 0; j < font[FONT_HEADER_HEIGHT]; j++) {
         // Increment one data byte every 8 bits, or
         // at the start of a new column  HiTech optimizes
         // the modulo, so no need to try and avoid it.
         if (j % 8 == 0) pos++;

         if (font[pos] & 1 << (j % 8)) {
            glcd_pixel(x + i, y + j, 1);
         } else {
            glcd_pixel(x + i, y + j, 0);
         }
      }
   }

   ret.x2 = ret.x1 + width - 1;
   // TODO: Return the actual height drawn, rather than the height of the
   //       font.
  // ret.y2 = ret.y1 + height;
   ret.y2 = ret.y1 + font[FONT_HEADER_HEIGHT];

   return ret;
}

unsigned char text_height(unsigned char *string, unsigned char *font) {
   // TODO: Possibly work out the actual pixel height.  Letters with
   //       descenders (like 'g') are taller than letters without (like 'k')

   // Height is stored in the header
   return font[FONT_HEADER_HEIGHT];
}

unsigned char text_width(unsigned char *string, unsigned char *font, unsigned char spacing) {
   unsigned char width = 0;
   unsigned short pos;
   unsigned char c;

   // TODO: Implement for fixed width fonts

   // Check font type, should be 0x01 for proportional
   if (font[FONT_HEADER_TYPE] != FONT_TYPE_PROPORTIONAL) return 0;

   while (*string != 0) {
      c = *string++;
   
      // Check that font start + number of bitmaps contains c
      // TODO: Should we continue here but add 0 to width?
      if (!(c >= font[FONT_HEADER_START] && c <= font[FONT_HEADER_START] + font[FONT_HEADER_LETTERS])) return 0;
   
      // Adjust for start position of font vs. the char passed
      c -= font[FONT_HEADER_START];
   
      // Work out where in the array the character is
      pos = font[c * FONT_HEADER_START + 5];
      pos <<= 8;
      pos |= font[c * FONT_HEADER_START + 6];
   
      // Read first byte from this position, this gives letter width
      width += font[pos];

      // Allow for space between letters
      width += spacing;
   }

   // The last letter wont have a space after it
   return width - spacing;
}

The font is not attached here but i don't think there is a mistake there.

thanks
jaume
temtronic



Joined: 01 Jul 2010
Posts: 9632
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 31, 2017 1:36 pm     Reply with quote

Really, you've got to concentrate on ONE issue, fix it, then move onto the next. For a driver that was supposed to work, there's been a lot of 'patching' needed.

I'd get simple TEXT to be displayed, where I wanted it first....It _should_ be easy to get a GLCD to do that.

At least once it does you can USE the LCD to display data.

The problem with 'graphics' is that there is a LOT of 'math' involved,so unless you have code sending to a PC terminal program items like start, stop X,Y values it's very hard to debug what is wrong, code or hardware.

Jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group