this is the code i have prepared for my glcd interfacing..but glcd giving blank display only..I am not getting whats the problem..i have checked all the hardware it is ok...please give some suggestions..this is the 1st time i am interfacing GLCD...GLCD details are given int my 1st post..]
/*program for GLCD interfacing with pic16f72*/
#include <htc.h>
__CONFIG(WDTE_OFF & FOSC_HS & CP_OFF & BOREN_ON & PWRTE_OFF);
#define _XTAL_FREQ 12000000
#define data PORTB
#define DI PORTCbits.RC4
#define RW PORTCbits.RC5
#define EN PORTCbits.RC6
#define CS1 PORTCbits.RC2
#define CS2 PORTCbits.RC3
#define RST PORTCbits.RC1
bit chip2=0;
/*----------variable defination------------ */
bit chip2=0;
unsigned int status,comm,dat;
unsigned int count,x_count=0xb8,y_count=0x40;
/*const int pro0[64]={0x7E,0x09,0x09,0x09,0x7E,0x00,0x00,0x00,
0x7F,0x49,0x49,0x49,0x36,0x00,0x00,0x00,
0x1C,0x22,0x41,0x41,0x41,0x00,0x00,0x00,
0x7F,0x41,0x41,0x22,0x1C,0x00,0x00,0x00,
0x7F,0x49,0x49,0x49,0x49,0x00,0x00,0x00,
0x7F,0x09,0x09,0x09,0x01,0x00,0x00,0x00,
0x1C,0x22,0x41,0x49,0x79,0x00,0x00,0x00,
0x7F,0x08,0x08,0x08,0x7F,0x00,0x00,0x00}; // //Test code
*/
const char image1[]=
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00,
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00,
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00,
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, 0x00,
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3E, 0x41, 0x49, 0x49, 0x3A, 0x00, 0x00,
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00,
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00,
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00,
0x00, 0x00, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00,
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00,
0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00,
0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00,
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00,
0x00, 0x01, 0x71, 0x09, 0x05, 0x03, 0x00, 0x00,
0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00,
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00,
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00,
};
const char image2[]=
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x00,
0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x00,
0x00, 0x42, 0x61, 0x51, 0x49, 0x46, 0x00, 0x00,
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31, 0x00, 0x00,
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, 0x00,
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, 0x00,
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x00,
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x00,
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00,
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x00,
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x00,
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7E, 0x11, 0x11, 0x11, 0x7E, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x00,
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x00,
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x00,
0x00, 0x46, 0x49, 0x49, 0x49, 0x31, 0x00, 0x00,
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x00,
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x00,
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01, 0x00, 0x00,
};
/*----------function defination------------*/
void data_wr();
void command_wr();
void command_rd();
void check_sts();
void init_lcd();
void clr_disp();
//void delay_ms(unsigned int count);
void disp_data();
void main()
{
unsigned int i;
TRISC=0;
TRISB=0;
for(i=0;i<2;i++)
{
if(i==1)
chip2=1; //enabling chip2
init_lcd();
__delay_ms(1);
disp_data();
chip2=0; //disabling chip2
}
while(1);
}
/*-----------initiating the LCD-------------*/
void init_lcd()
{
RST=0;
__delay_ms(4);
RST=1;
__delay_ms(4);
EN=0;
DI=0; //selecting command
RW=0; //selecting write option. i.e.command write
CS1=0; //deselecting chip select1
CS2=0; //deselecting chip select2
__delay_ms(1);
/*-------initialising the LCD--------*/
comm=0x3f; //display on
check_sts();
command_wr();
comm=0xc0; //display start line 00
check_sts();
command_wr();
__delay_ms(1);
clr_disp();
__delay_ms(1);
}
/*-----------prototype for writing command------------------*/
void command_wr()
{
EN=0;
__delay_ms(1);
RW=0; //instruction write
if(!chip2)
{
CS1=1; //selecting chip select1
CS2=0; //deselecting chip select2
}
else
{
CS1=0; //deselecting chip select1
CS2=1; //selecting chip select2
}
DI=0;
data=comm;
EN=1;
__delay_ms(1);
EN=0;
}
/*------------prototype for writing data---------------------*/
void data_wr()
{
EN=0;
__delay_ms(1);
RW=0; //data write
if(!chip2)
{
CS1=1; //selecting chip select1
CS2=0; //deselecting chip select2
}
else
{
CS1=0; //deselecting chip select1
CS2=1; //selecting chip select2
}
DI=1;
__delay_ms(1);
data=dat;
EN=1;
__delay_ms(1);
EN=0;
__delay_ms(1);
}
/*-------------prototype for reading the command----------------*/
void command_rd()
{
EN=0;
__delay_ms(1);
RW=1; //instruction read
if(!chip2)
{
CS1=1; //selecting chip select1
CS2=0; //deselecting chip select2
}
else
{
CS1=0; //deselecting chip select1
CS2=1; //selecting chip select2
}
DI=0;
__delay_ms(1);
status=data;
EN=1;
__delay_ms(1);
EN=0;
__delay_ms(1);
RW=0;
__delay_ms(1);
EN=1;
}
/*---------------prototype for checking the status---------------*/
void check_sts()
{
__delay_ms(1);
TRISB=0xff; //making PORT0 as input
__delay_ms(1); //1ms delay
command_rd();
while((status & 0x80) != 0x80) //checking whether STA0 & STA1 are set or not
{
command_rd();
status=status & 0x80;
}
__delay_ms(1);
TRISB=0x00; //making PORT0 as output
//TRISC=0x00;
}
/*-----------prototype for delay generating function------------*/
/*void delay_ms(unsigned int count)
{
unsigned int i;
while(count--)
{
for(i=0;i<100;i++);
}
}
*/
/*------------prototype for clearing the display----------------*/
void clr_disp()
{
unsigned int j;
for(x_count=0xb8; x_count<0xc0; x_count++)
{
comm=x_count; //initially it is 0xb8
check_sts();
command_wr();
comm=y_count; //initially it is 0x40
check_sts();
command_wr();
for(j=0; j<64; j++,y_count++)
{
dat=0x00;
data_wr();
}
y_count=0x40;
}
}
/*--------------prototype for displaying data-----------------*/
void disp_data()
{
unsigned int k=0;
comm=0xb8; //setting starting x-address
check_sts();
command_wr();
comm=0x40; //setting starting y-address
check_sts();
command_wr();
for(x_count=0xb8;x_count<0xc0
{
for(count=0; count<64; k++,count++)
{
if(!chip2)
dat=image1[k];
else
dat=image2[k];
data_wr();
}
x_count++;
comm=x_count;
check_sts();
command_wr();
}
}