Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C18 + KS0108 Graphic LCD Library

Status
Not open for further replies.
Thanks for the response....

In glcd.h you have:

#define b_GLCD_On

Does this translate to D/I on the LCD or does it have some other function specific to your board?

Thanks
 
GLCD_On is connected to the RST pin of the GLCD. Unfortunately I was rather lazy when I wrote that code, to change it to your hardware you need to change the #defines in GLCD.h and alter the TRIS statements in Init_GLCD in GLCD.c. You can find a schematic of the hardware that it runs on at **broken link removed** - look in the assembly instructions.

Mike.
 
Ok thanks got it working.

I'm changing the code so that its pin configurable in glcd.h (including TRIS registers) and I've inverting the pixel colours... yours is blanks on pixels... I want mine to be pixels on a blank screen.
 
Hi, I'm also using graphic LCD to do my project but the size of the LCD is 128x128
i'm doing the electronic Sudoku by using PIC18F4550
After I refering your code there is some code sentences I don't understand.
GLCD_Write_Cmd
- why do you need to write this?what is it different with the GLCD_Write_Data?
- GLCD_Write_Cmd(0x40+(XPos&0x3F));
GLCD_Write_Cmd(0xB8+((YPos&0x3F)>>3);

and I'm using 128x128 so there are 4 pins of chip select (CS1,CS2,CS3,CS4), so are the waveform of CS3 and CS4 are the same as the waveform of CS1 and CS2?

thx.
 
The difference between writing data and commands is the state of the RS pin.

To change the code to work for a 128*128 display, you will have to go through it and add code to any place that changes any CS pins. The obvious place is the WritePosition routine which would become (I think),
Code:
void WritePosition(void){
    b_GLCD_GCS1=0;
    b_GLCD_GCS2=0;
    b_GLCD_GCS3=0;
    b_GLCD_GCS4=0;
    if(YPos>63){
        if(XPos>63){
            b_GLCD_GCS4=1;
        }else{
            b_GLCD_GCS3=1;
        }
    }else{
        if(XPos>63){
            b_GLCD_GCS2=1;
        }else{
            b_GLCD_GCS1=1;
        }
    }
    GLCD_Write_Cmd(0x40+(XPos&0x3f));    //column=0
    GLCD_Write_Cmd(0xb8+((YPos&0x3f)>>3));    //row=0    
}

HTH

Mike.
 
ok but can you please explain this code for me??i'm not really understand it
GLCD_Write_Cmd(0x40+(XPos&0x3f)); //column=0
GLCD_Write_Cmd(0xb8+((YPos&0x3f)>>3)); //row=0
why (>>3)??
 
Writing command 0x40+n sets the position across the display.
The bytes that make up the display are arranged vertically with bit 0 being the top pixel. This means that the Y position has to be divided by 8 and shifting right 3 times does the same thing. Writing command 0xb8+n (n=0 to 7) sets the position in multiples of 8 down the display.

Example, if you write command 0x40+23, then command 0xb8+1 and then write data 0x02 you will turn on the pixel at 23 across and 10 down.

The various commands are explained on page 13 of the data sheet.

Mike.
 
I understand but can you check with my code?
#include <18f4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#define GLCD_DATA PORTD
#define b_GLCD_GCS1 PIN_E0
#define b_GLCD_GCS2 PIN_E1
#define b_GLCD_GCS3 PIN_A2
#define b_GLCD_GCS4 PIN_A3
#define b_GLCD_RS PIN_A4
#define b_GLCD_E PIN_A5


unsigned char w,XPos,YPos,i;
unsigned char GLCD_Read(void){
output_high(b_GLCD_E);
delay_us(0.010);
output_low(b_GLCD_E);
return w;
}

void Wait_Not_Busy(void){
SET_TRIS_D(0XFF);
output_low(b_GLCD_RS);
if(input(PIN_E0)==1&&input(PIN_E1)==1){
output_low(b_GLCD_GCS1);
while (GLCD_Read()&0x80)
output_high(b_GLCD_GCS1);
output_low(b_GLCD_GCS2);
while (GLCD_Read()&0x80)
output_high(b_GLCD_GCS2);
}
else{
while (GLCD_Read()&0x80);
}
SET_TRIS_D(0X00);
}

void GLCD_Write_Cmd(unsigned char data){
Wait_Not_Busy();
data=output_D(0x00);
output_low(b_GLCD_RS);
output_high(b_GLCD_E);
delay_us(0.015);
output_low(b_GLCD_E);
}

void GLCD_Write_Data(unsigned char data){
Wait_Not_Busy();
data=input_D();
output_high(b_GLCD_RS);
output_high(b_GLCD_E);
delay_us(0.015);
output_low(b_GLCD_E);
}

void WritePosition(void){
output_low(b_GLCD_GCS1);
output_low(b_GLCD_GCS2);
output_low(b_GLCD_GCS3);
output_low(b_GLCD_GCS4);
if (YPos>63){
if(XPos>63){
output_low(b_GLCD_GCS4);
}
else{
output_high(b_GLCD_GCS3);
}
if (XPos>63){

output_high(b_GLCD_GCS2);
}
else{
output_high(b_GLCD_GCS1);
}
}
GLCD_Write_Cmd(0x40+(XPos&0x3f)); //column=0
GLCD_Write_Cmd(0xb8+((YPos&0x3f)>>3)); //row=0

}

void SetPos(unsigned char x, unsigned char y){
x=XPos;
y=YPos;
WritePosition();
}

void MoveRight(void){
if(++XPos=64){
WritePosition();
}
if(XPos==128){
XPos=0;
YPos+=8;
YPos=YPos&0x7F;
WritePosition();
}
}

void clearScreen(void){
unsigned char i,j;
output_high(b_GLCD_GCS1);
output_high(b_GLCD_GCS2);
for(i=0;i<8;i++){
GLCD_Write_Cmd(0x40);
GLCD_Write_Cmd(0xB8+i);
for(j=0;j<0x40;j++)
GLCD_Write_Data(0xff);
}
SetPos(0,0);
}

void Init_GLCD(void){
SET_TRIS_E(0xFC); //output
SET_TRIS_A(0xF9); //output
SET_TRIS_D(0xFC); //output

output_low(b_GLCD_GCS1);
output_high(b_GLCD_GCS2);
output_low(b_GLCD_GCS3);
output_high(b_GLCD_GCS4);
GLCD_Write_Cmd(0x3F);
GLCD_Write_Cmd(0xC0);

}
void main(void){
Init_GLCD();
GLCD_Write_Cmd(0x40+23);
GLCD_Write_Cmd(0xB8+1);
GLCD_Write_Data(0x02);
}

Is my main function correct?
But I still couldn’t run it…the LCD display nothing and I checked all the connection already.
Can you please show me an example code to write a letter of “J” display on the GLCD_GCS1?
 
Status
Not open for further replies.

Latest threads

Back
Top