When writing a string you must choose the side (i made it this way because some people might like to split the display i two parts), you can call the function twice to write on both sides.
Some pieces of code where found elsewhere on the web (it is not everything mine).
I uses a new aproach in writing text as it uses a 2D array to strore the font.
Any question or modification to make it better is welcome.
Code: Select all
const unsigned short alfab[][5] = {
{0x00,0x00,0x00,0x00,0x00}, //* Espace
{0x00,0x00,0x4f,0x00,0x00}, //* ! */
{0x00,0x07,0x00,0x07,0x00}, //* " */
{0x14,0x7f,0x14,0x7f,0x14}, //* # */
{0x24,0x2a,0x7f,0x2a,0x12}, //* $ */
{0x23,0x13,0x08,0x64,0x62}, //* % */
{0x36,0x49,0x55,0x22,0x20}, //* & */
{0x00,0x05,0x03,0x00,0x00}, //* ' */
{0x00,0x1c,0x22,0x41,0x00}, //* ( */
{0x00,0x41,0x22,0x1c,0x00}, //* ) */
{0x14,0x08,0x3e,0x08,0x14}, //* * */
{0x08,0x08,0x3e,0x08,0x08}, //* + */
{0x50,0x30,0x00,0x00,0x00}, //* }, */
{0x08,0x08,0x08,0x08,0x08}, //* - */
{0x00,0x60,0x60,0x00,0x00}, //* . */
{0x20,0x10,0x08,0x04,0x02}, //* / */
{0x3e,0x51,0x49,0x45,0x3e}, //* 0
{0x00,0x42,0x7f,0x40,0x00}, //* 1 */
{0x42,0x61,0x51,0x49,0x46}, //* 2 */
{0x21,0x41,0x45,0x4b,0x31}, //* 3 */
{0x18,0x14,0x12,0x7f,0x10}, //* 4 */
{0x27,0x45,0x45,0x45,0x39}, //* 5 */
{0x3c,0x4a,0x49,0x49,0x30}, //* 6 */
{0x01,0x71,0x09,0x05,0x03}, //* 7 */
{0x36,0x49,0x49,0x49,0x36}, //* 8 */
{0x06,0x49,0x49,0x29,0x1e}, //* 9 */
{0x00,0x36,0x36,0x00,0x00}, //* : */
{0x00,0x56,0x36,0x00,0x00}, //* ; */
{0x08,0x14,0x22,0x41,0x00}, //* < */
{0x14,0x14,0x14,0x14,0x14}, //* = */
{0x00,0x41,0x22,0x14,0x08}, //* > */
{0x02,0x01,0x51,0x09,0x06}, //* ? */
{0x3e,0x41,0x5d,0x55,0x1e}, //* @
{0x7e,0x11,0x11,0x11,0x7e}, //* A */
{0x7f,0x49,0x49,0x49,0x36}, //* B */
{0x3e,0x41,0x41,0x41,0x22}, //* C */
{0x7f,0x41,0x41,0x22,0x1c}, //* D */
{0x7f,0x49,0x49,0x49,0x41}, //* E */
{0x7f,0x09,0x09,0x09,0x01}, //* F */
{0x3e,0x41,0x49,0x49,0x7a}, //* G */
{0x7f,0x08,0x08,0x08,0x7f}, //* H */
{0x00,0x41,0x7f,0x41,0x00}, //* I */
{0x20,0x40,0x41,0x3f,0x01}, //* J */
{0x7f,0x08,0x14,0x22,0x41}, //* K */
{0x7f,0x40,0x40,0x40,0x40}, //* L */
{0x7f,0x02,0x0c,0x02,0x7f}, //* M */
{0x7f,0x04,0x08,0x10,0x7f}, //* N */
{0x3e,0x41,0x41,0x41,0x3e}, //* O */
{0x7f,0x09,0x09,0x09,0x06}, //* P
{0x3e,0x41,0x51,0x21,0x5e}, //* Q */
{0x7f,0x09,0x19,0x29,0x46}, //* R */
{0x26,0x49,0x49,0x49,0x32}, //* S */
{0x01,0x01,0x7f,0x01,0x01}, //* T */
{0x3f,0x40,0x40,0x40,0x3f}, //* U */
{0x1f,0x20,0x40,0x20,0x1f}, //* V */
{0x3f,0x40,0x38,0x40,0x3f}, //* W */
{0x63,0x14,0x08,0x14,0x63}, //* X */
{0x07,0x08,0x70,0x08,0x07}, //* Y */
{0x61,0x51,0x49,0x45,0x43}, //* Z */
{0x00,0x7f,0x41,0x41,0x00}, //* [ */
{0x02,0x04,0x08,0x10,0x20}, //* \ */
{0x00,0x41,0x41,0x7f,0x00}, //* ] */
{0x04,0x02,0x01,0x02,0x04}, //* ^ */
{0x40,0x40,0x40,0x40,0x40}, //* _ */
{0x00,0x00,0x03,0x05,0x00}, //* `
{0x20,0x54,0x54,0x54,0x78}, //* a */
{0x7F,0x44,0x44,0x44,0x38}, //* b */
{0x38,0x44,0x44,0x44,0x44}, //* c */
{0x38,0x44,0x44,0x44,0x7f}, //* d */
{0x38,0x54,0x54,0x54,0x18}, //* e */
{0x04,0x04,0x7e,0x05,0x05}, //* f */
{0x08,0x54,0x54,0x54,0x3c}, //* g */
{0x7f,0x08,0x04,0x04,0x78}, //* h */
{0x00,0x44,0x7d,0x40,0x00}, //* i */
{0x20,0x40,0x44,0x3d,0x00}, //* j */
{0x7f,0x10,0x28,0x44,0x00}, //* k */
{0x00,0x41,0x7f,0x40,0x00}, //* l */
{0x7c,0x04,0x7c,0x04,0x78}, //* m */
{0x7c,0x08,0x04,0x04,0x78}, //* n */
{0x38,0x44,0x44,0x44,0x38}, //* o */
{0x7c,0x14,0x14,0x14,0x08}, //* p
{0x08,0x14,0x14,0x14,0x7c}, //* q */
{0x7c,0x08,0x04,0x04,0x00}, //* r */
{0x48,0x54,0x54,0x54,0x24}, //* s */
{0x04,0x04,0x3f,0x44,0x44}, //* t */
{0x3c,0x40,0x40,0x20,0x7c}, //* u */
{0x1c,0x20,0x40,0x20,0x1c}, //* v */
{0x3c,0x40,0x30,0x40,0x3c}, //* w */
{0x44,0x28,0x10,0x28,0x44}, //* x */
{0x0c,0x50,0x50,0x50,0x3c}, //* y */
{0x44,0x64,0x54,0x4c,0x44}, //* z */
{0x08,0x36,0x41,0x41,0x00}, //* { */
{0x00,0x00,0x77,0x00,0x00}, //* | */
{0x00,0x41,0x41,0x36,0x08}, //* } */
{0x08,0x08,0x2a,0x1c,0x08}, //* <- */ 126
{0x08,0x1c,0x2a,0x08,0x08}, //* -> */ 127
{0x14,0x3E,0x55,0x55,0x41}, //euro sign 128
{0x68,0x5C,0x4B,0x49,0x01},//GBP sign 129
{0x01,0x0A,0x7C,0x0A,0x01}//yen sign 130
};
#define LCD_TRIS TRISD
#define LCD_DATA PORTD
#define ENABLE PORTB.F4
#define RW PORTB.F3
#define DI PORTB.F2
#define RESET PORTB.F5
#define CS1 PORTB.F0
#define CS2 PORTB.F1
#define LEFT 1
#define RIGHT 0
#define gjeresia_1_karakter 5
#define ON 1
#define OFF 0
void glcd_setside(unsigned char sides);
void _lcd_enable(void);
void glcd_setpage(unsigned char page);
void glcd_setxaddr(unsigned char y);
void glcd_write (unsigned char data);
void glcd_command(char command,char side1);
void glcd_start(char mode);
void glcd_mbush(char side, unsigned char fill);
void glcd_putch(char ch,char side,char start,char page);
void glcd_puts( char *uau,char side1,char start1,char page1);
//Inicializon GLCD
void glcd_start(char mode)
{
RESET=0;
Delay_us(5);
RESET=1;
Delay_us(5);
glcd_command(0xC0, LEFT);
glcd_command(0xC0, RIGHT);
glcd_command(0x40, LEFT);
glcd_command(0x40, RIGHT);
glcd_command(0xB8, LEFT);
glcd_command(0xB8, RIGHT);
if(mode == ON)
{
glcd_command(0x3F, LEFT);
glcd_command(0x3F, RIGHT);
}
else
{
glcd_command(0x3E, LEFT);
glcd_command(0x3E, RIGHT);
}
}
//Dergon komande ne GLCD
void glcd_command(char command,char side1)
{
DI=0;
RW=0;
glcd_setside(side1);
LCD_DATA = command;
_lcd_enable();
}
//Dergon byte(data) tek GLCD
void glcd_write (unsigned char data)
{
DI=1;
RW=0;
LCD_DATA = data;
_lcd_enable();
}
//Zgjedh nje nga rreshtat per te shkruar nga 0 ne 7
void glcd_setpage(unsigned char page)
{
DI=0;
RW=0;
PORTD = 0b10111000 | page;
_lcd_enable();
}
//Clock byte in
void _lcd_enable(void)
{
Delay_us(1);
ENABLE=1;
Delay_us(1);
ENABLE=0;
}
//Zgjedh nje nga anet e GLCD, LEFT ose RIGHT
void glcd_setside(unsigned char sides)
{
if (sides) // set a CS pin low to enable it
{
CS1 = 0;
CS2 = 1;
}
else
{
CS1 = 1;
CS2 = 0;
}
}
//Zgjedh fillimin e germes. Percakton largesen e fillimit te germes nga ana e GLCD nga 0 ne 63
void glcd_setxaddr(unsigned char y)
{
DI=0;
RW=0;
LCD_DATA = 0b01000000 | (y & 0b00111111);
_lcd_enable();
}
//Mbush GLCD sipas nje byte te caktuar. Nese do te boshatisesh GLCD byte=0x00
void glcd_mbush(char side, unsigned char fill)
{
unsigned char x,y;
if(side)
{
glcd_setside(LEFT);
for (x=0; x<8; x++)
{
glcd_setpage(x); // set the page (x)
glcd_setxaddr(0); // set the y address to 0
RW=0;
DI=1; // setup for data
LCD_DATA=fill;
for (y=0; y<64; y++) // clear the row
{
_lcd_enable();
}
}
}
else
{
glcd_setside(RIGHT);
for (x=0; x<8; x++)
{
glcd_setpage(x); // set the page (x)
glcd_setxaddr(0); // set the y address to 0
RW=0;
DI=1; // setup for data
LCD_DATA=fill;
for (y=0; y<64; y++) // clear the row
{
_lcd_enable();
}
}
}
}
//Paraqet nje germe nje GLCD
void glcd_putch(char ch1,char side1,char start1,char page1)
{
char e;
glcd_setside(side1);
glcd_setpage(page1);
glcd_setxaddr(start1);
for(e=0;e<5;e++)
{
glcd_write(alfab[ch1-32][e]);
}
glcd_write(0);
}
//Paraqet nje string ne GLCD
void glcd_puts( char *uau,char side1,char start1,char page1)
{
char e=0,*addr=uau;
glcd_setside(side1);
glcd_setxaddr(start1);
glcd_setpage(page1);
while(*uau)
{
for(e=0;e<5;e++)
{
glcd_write(alfab[*uau-32][e]);
}
*uau++;
glcd_write(0);
}
}