msakms
Joined: 20 Nov 2011 Posts: 7 Location: Doha/Qatar
|
ST7565R DRIVER |
Posted: Sun Nov 20, 2011 8:14 am |
|
|
Here you are bro, feel free to inform me about any doubts you have and maybe we can all discuss any tweaks & optimization changes that might come in handy.
Code: | /////////////////////////////////////////////////////////////////////////////////////////////
// ST7565R-FUNCTION PROTOTYPES: //
// //
// //
// void CMD_MODE()----->Instructions Command Mode //
// void DRAM_MODE()------->Display-RAM Mode //
// void CLK_IN()--------> Enable pin clocking-in //
// void INIT_LCD()------>GLCD initialization //
// void PRINT(char letter)--------->Character or string print function between quotes. //
// void CLEAR_LCD()------>Clear the GLCD //
// void GOTO_PAGE()------>Goto p=PAGE ADDRESS and c=COLUMN ADDRESS //
// //
// //
/////////////////////////////////////////////////////////////////////////////////////////////
// msakms-ST7565R V1.0 //
////////////////////////////////////////////////////////////////////////////////////////////
#Define RD PIN_C3
#Define A0 PIN_C4
#Define WR PIN_C5
#Define CS1 PIN_C6
#Define LCD_RESET PIN_C7
unsigned int init[]={0x40,0xA0,0xC8,0xA6,0xA3,0x2F,0xAD,0x00,0xAF,0xA4};
unsigned int d, c, x, i2, ln, un, i;
static unsigned int p;
unsigned int const ps = 0xB0;
char letter;
const byte TEXT[39][6]= {
0x7E, 0x09, 0x09, 0x09, 0x7E, 0x00, //A
0x7F, 0x49, 0x49, 0x36, 0x00, 0x00, //B
0x3E, 0x41, 0x41, 0x41, 0x00, 0x00, //C
0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, //D
0x7F, 0x49, 0x49, 0x49, 0x00, 0x00, //E
0x7F, 0x09, 0x09, 0x09, 0x00, 0x00, //F
0x3F, 0x41, 0x49, 0x79, 0x00, 0x00, //G
0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, //H
0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, //I
0x60, 0x41, 0x7F, 0x01, 0x00, 0x00, //J
0x7F, 0x08, 0x04, 0x0A, 0x71, 0x00, //K
0x7F, 0x40, 0x40, 0x40, 0x00, 0x00, //L
0x7F, 0x02, 0x04, 0x02, 0x7F, 0x00, //M
0x7F, 0x02, 0x04, 0x08, 0x7F, 0x00, //N
0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, //O
0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, //P
0x3E, 0x41, 0x61, 0x7E, 0x80, 0x00, //Q
0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, //R
0x46, 0x49, 0x49, 0x49, 0x31, 0x00, //S
0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, //T
0x3F, 0x40, 0x40, 0x3F, 0x00, 0x00, //U
0x07, 0x18, 0x60, 0x18, 0x07, 0x00, //V
0x7F, 0x80, 0x70, 0x80, 0x7F, 0x00, //W
0x63, 0x14, 0x08, 0x14, 0x63, 0x00, //X
0x03, 0x04, 0x78, 0x04, 0x03, 0x00, //Y
0x31, 0x29, 0x25, 0x23, 0x21, 0x00, //Z
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //SPACE
0x42, 0x7F, 0x40, 0x00, 0x00,0x00, //1
0x62, 0x51, 0x4D, 0x46, 0x00,0x00, //2
0x41, 0x45, 0x4B, 0x31, 0x00,0x00, //3
0x3C, 0x22, 0x7F, 0x20, 0x00,0x00, //4
0x47, 0x45, 0x45, 0x39, 0x00,0x00, //5
0x7E, 0x49, 0x49, 0x31, 0x00,0x00, //6
0x01, 0x79, 0x05, 0x03, 0x00,0x00, //7
0x3E, 0x49, 0x49, 0x3E, 0x00,0x00, //8
0x06, 0x09, 0x09, 0x7F, 0x00,0x00, //9
0x7F, 0x41, 0x41, 0x7F, 0x00,0x00, //0
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, //.
0x07, 0x05, 0x07, 0x00, 0x00, 0x00};//Celcius
void CMD_MODE() {
output_low(A0);
output_high(RD);
output_low(WR);
}
void DRAM_MODE() {
output_high(A0);
output_high(RD);
output_low(WR);
}
void CLK_IN() {
output_low(CS1);
output_high(CS1);
}
void INIT_LCD() {
//INITIALIZATION ROUTINE//
output_low(LCD_RESET);
output_high(LCD_RESET);
CMD_MODE();
for(i=0;i<10;i++)
{
output_d(init[i]);
CLK_IN();
}
//END OF INITIALIZATION ROUTINE//
}
void GOTO_PAGE(p,c) {
CMD_MODE();
d = ps + p;
output_d(d);
CLK_IN();
ln = c & 0b00001111;
un = c & 0b11110000;
un = un >> 4;
un = un | 0b00010000;
output_d(un);
CLK_IN();
output_d(ln);
CLK_IN();
}
void PRINT(char letter) {
switch(letter){
case 'A':
x = 0;
break;
case 'B':
x = 1;
break;
case 'C':
x = 2;
break;
case 'D':
x = 3;
break;
case 'E':
x = 4;
break;
case 'F':
x = 5;
break;
case 'G':
x = 6;
break;
case 'H':
x = 7;
break;
case 'I':
x = 8;
break;
case 'J':
x = 9;
break;
case 'K':
x = 10;
break;
case 'L':
x = 11;
break;
case 'M':
x = 12;
break;
case 'N':
x = 13;
break;
case 'O':
x = 14;
break;
case 'P':
x = 15;
break;
case 'Q':
x = 16;
break;
case 'R':
x = 17;
break;
case 'S':
x = 18;
break;
case 'T':
x = 19;
break;
case 'U':
x = 20;
break;
case 'V':
x = 21;
break;
case 'W':
x = 22;
break;
case 'X':
x = 23;
break;
case 'Y':
x = 24;
break;
case 'Z':
x = 25;
break;
case ' ':
x = 26;
break;
case '1':
x = 27;
break;
case '2':
x = 28;
break;
case '3':
x = 29;
break;
case '4':
x = 30;
break;
case '5':
x = 31;
break;
case '6':
x = 32;
break;
case '7':
x = 33;
break;
case '8':
x = 34;
break;
case '9':
x = 35;
break;
case '0':
x = 36;
break;
case '.':
x = 37;
break;
case '°':
x = 38;
break;
}
DRAM_MODE();
for(i=0;i<6;i++)
{
output_d(TEXT[x][i]);
CLK_IN();
} }
void CLEAR_LCD() {
for(i2=0;i2<4;i2++) {
GOTO_PAGE(i2,0);
for(i=0x00;i!=0x83;i++)
{
DRAM_MODE();
output_d(0x00);
CLK_IN();
}
}
} |
I'm using a PIC16F877-A @ 4MHz "So no need to check the busy flag because the timing is just perfect at such frequency" and the TOPWAY LM13232AFW 132x32 GLCD module. Make sure you check your product datasheet for any changes that you might need. |
|