Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 19th May 2008, 07:07 AM   (permalink)
Default C18 + KS0108 Graphic LCD Library

Hi,

Does anyone have an existing library that can be pulled into MPLAB C18 for a KS0108 compatible GLCD.

I've searched around and found at least one reference to one which required a lot of fixing as it wasnt working.

Thanks

Edit: Actually, I found this one: http://www.electro-tech-online.com/m...glcd-demo.html

So i'll check it out tonight.. looks like it will work

Last edited by andret; 19th May 2008 at 07:15 AM.
andret is offline   Reply With Quote
Old 19th May 2008, 07:17 AM   (permalink)
Default

This should get you started.

Mike.
Pommie is offline   Reply With Quote
Old 19th May 2008, 04:36 PM   (permalink)
Default

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
andret is offline   Reply With Quote
Old 20th May 2008, 12:26 AM   (permalink)
Default

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 BlueroomElectronics - look in the assembly instructions.

Mike.
Pommie is offline   Reply With Quote
Old 20th May 2008, 06:15 PM   (permalink)
Default

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.
andret is offline   Reply With Quote
Old 4th July 2008, 11:24 AM   (permalink)
Default

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.
darsin is offline   Reply With Quote
Old 5th July 2008, 04:47 AM   (permalink)
Default

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.
Pommie is offline   Reply With Quote
Old 5th July 2008, 07:30 AM   (permalink)
Default

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)??
darsin is offline   Reply With Quote
Old 5th July 2008, 08:42 AM   (permalink)
Default

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.
Pommie is offline   Reply With Quote
Old 7th July 2008, 01:51 AM   (permalink)
Default

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?
darsin is offline   Reply With Quote
Reply

Bookmarks

Tags
ks0108 c18 glcd

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Webpages explaining graphic LCD AceOfHearts General Electronics Chat 2 17th April 2008 06:35 PM
Graphic LCD Connections baberjaved Micro Controllers 0 19th January 2008 02:47 PM
Graphic LCD Library baberjaved Micro Controllers 1 28th December 2007 07:25 AM
HD44780 lcd help jay543_uk Micro Controllers 12 8th November 2007 03:26 PM
Graphic LCD flemmard Micro Controllers 1 13th September 2007 02:32 AM



All times are GMT. The time now is 01:22 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.