AtomSoft
Well-Known Member
New update.. i recently came across the need to have the text on the LCD oriented to a specific position so i create the following code:
strlen is in strings.h in C18 and is very useful.
Example Code:
Code:
#define LEFT 0
#define RIGHT 1
#define CENTER 2
Code:
mylen = strlen((const char*)pString);
switch(orientation){
case LEFT:
y = 0;
break;
case RIGHT:
y = 131 - (mylen*width);
break;
case CENTER:
y = ((131 - (mylen*width)) / 2);
break;
}
strlen is in strings.h in C18 and is very useful.
Example Code:
Code:
void LCDPutStr2(const unsigned char *pString, int x, char orientation, int Size, int fColor, int bColor) {
unsigned char oldY, width;
unsigned char y, mylen;
mylen = strlen((const char*)pString);
if(Size == 0)
width = 6;
else
width = 8;
switch(orientation){
case LEFT:
y = 0;
break;
case RIGHT:
y = 131 - (mylen*width);
break;
case CENTER:
y = ((131 - (mylen*width)) / 2);
break;
}
oldY = y;
while (*pString) { // loop until 0 is found
LCDPutChar(*pString++, x, y, Size, fColor, bColor); // draw the character
y += width; // Depending on Font width add to y(left)
if(y > 131 - width){ // If y > 131 max res then goto new line and resume
y = oldY; // Reset y from the start.
x+=9; // Add 9 pixels to hight
}
}
}
Last edited: