Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

GLCD source code COMPLETED!!

Status
Not open for further replies.

Deepak350

Member level 1
Member level 1
Joined
Jan 27, 2009
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
India
Activity points
1,550
glcd_init_bp5

Hello all,

I'm using a PIC18F8520 MCU, MicroC IDE and a 128x64 GLCD. With the in-built library functions the GLCD is working fine, but I want to use code without using the library functions for portability reasons. Please help me with the source code to simply initialize the GLCD and display a character for now. Thank you in advance.
This is my code as of now and is not working:
#define GLCD_DI PORTJ.F2
#define GLCD_RW PORTJ.F3
#define GLCD_EN PORTJ.F4
#define GLCD_CS1 PORTJ.F0
#define GLCD_CS2 PORTJ.F1
#define GLCD_RST PORTJ.F5
#define GLCD_DATA PORTD

#define X_ADRESS 0xB8 // Adress base for Page 0
#define Y_ADRESS 0x40 // Adress base for Y0
#define START_LINE 0xC0 // Adress base for line 0
#define DISPLAY_ON 0x3F // Turn display on
#define DISPLAY_OFF 0x3E // Turn display off

#define RIGHT 0
#define LEFT 1
#define BUSY 0x80

typedef unsigned int U16;

void GLCDWaitBusy( )
{

GLCD_DATA= 0xFF; // Set LCD_DATA port in input mode
TRISD = 0xFF;
GLCD_DI = 0; // Instruction mode
GLCD_RW = 1; // Read mode
GLCD_EN = 0; // Strobe
Delay_ms( 10 );
GLCD_EN = 1;

//while( GLCD_DATA & 0x7F == BUSY ); // Mask the other status bits and test the BUSY bit
while( GLCD_DATA & 0x80 );

}

void GLCDInstructionWrite( U16 Instruction )
{

GLCDWaitBusy( ); // Wait until LCD not busy
GLCD_DI = 0; // Instruction mode
GLCD_RW = 0; // Write mode
GLCD_DATA = Instruction; // Outbyte
GLCD_EN = 1; // Strobe
Delay_ms( 10 );
GLCD_EN = 0;

}

void GLCDSelectSide( U16 Side )
{

if( Side == RIGHT )
{
// Switch to right
GLCD_EN = 0;
GLCD_DI = 0;
GLCD_RW = 1;
GLCD_CS1 = 0;
GLCD_CS2 = 1;

GLCDInstructionWrite( Y_ADRESS ); // Set column to 0

}
else
{
// Switch to left
GLCD_EN = 0;
GLCD_DI = 0;
GLCD_RW = 1;
GLCD_CS1 = 1;
GLCD_CS2 = 0;

GLCDInstructionWrite( Y_ADRESS ); // Set column to 0

}

}

void GLCDDataWrite( U16 Data )
{

GLCDWaitBusy( ); // Wait until LCD not busy
GLCD_DI = 1; // Data mode
GLCD_RW = 0; // Write mode
GLCD_DATA = Data; // Outbyte
GLCD_EN = 1; // Strobe
Delay_ms( 10 );
GLCD_EN = 0;

}

void GLCD_ClearScreen( )
{

U16 Page = 0;
U16 Column = 0;
// Process the 8 pages of the GLCD
for( Page = 0; Page < 8; Page++ )
{

GLCDSelectSide( LEFT ); // Select left side
GLCDInstructionWrite( X_ADRESS | Page ); // Set the page number
GLCDInstructionWrite( Y_ADRESS ); // Set column to 0

// Process a page on both sides
for ( Column = 0; Column < 128; Column++ )
{

if( Column == 64 )
{

GLCDSelectSide( RIGHT ); // Select right side
GLCDInstructionWrite( X_ADRESS | Page ); // Set the page number
GLCDInstructionWrite( Y_ADRESS ); // Set column to 0

}

GLCDDataWrite( 0x00 ); // Erase a column

}

}

}

void GLCDInt( )
{

GLCD_DATA = 0;
GLCD_DI = 0;
GLCD_RW = 0;
GLCD_EN = 0;
GLCD_CS1 = 0;
GLCD_CS2 = 0;

GLCD_RST = 1;
Delay_ms( 10 );
GLCD_RST=0;
Delay_ms( 10 );
GLCD_RST=1;

GLCDSelectSide( LEFT );
GLCDInstructionWrite( DISPLAY_OFF ); // Display OFF
GLCDInstructionWrite( START_LINE );
GLCDInstructionWrite( X_ADRESS );
GLCDInstructionWrite( Y_ADRESS );
GLCDInstructionWrite( DISPLAY_ON ); // Display ON

GLCDSelectSide( RIGHT );
GLCDInstructionWrite( DISPLAY_OFF ); // Display OFF
GLCDInstructionWrite( START_LINE );
GLCDInstructionWrite( X_ADRESS );
GLCDInstructionWrite( Y_ADRESS );
GLCDInstructionWrite( DISPLAY_ON ); // Display ON

GLCD_ClearScreen( );

}

U16 GLCDDataRead( )
{

GLCD_DATA = 0xFF; // Set LCD_DATA port in input mode

GLCD_RW = 1; // Read mode
GLCD_DI = 1; // Data mode

GLCD_EN = 0; // Strobe
Delay_ms( 10 );
GLCD_EN = 1;
Delay_ms( 10 );

return GLCD_DATA; // Return the data read

}
/*
void GLCDSetDot( U16 Xaxis, U16 Yaxis )
{

U16 DataRead = 0;

GLCDInstructionWrite( START_LINE ); // Set adress for line 0

// Left side
if( Xaxis < 64 )
{

GLCDSelectSide( LEFT ); // Select left side
GLCDInstructionWrite( X_ADRESS + ( Yaxis / 8 ) ); // Select page number
GLCDInstructionWrite( Y_ADRESS + Xaxis ); // Select column

DataRead = GLCDDataRead( ); // Read the current location
DataRead = GLCDDataRead( ); // on the LCD. dummy read

GLCDInstructionWrite( X_ADRESS + ( Yaxis / 8 ) ); // Select page number
GLCDInstructionWrite( Y_ADRESS + Xaxis ); // Select column
GLCDDataWrite( DataRead | ( 1 << ( Yaxis % 8 ) ) ); // Plot the dot

}
else
// Right side
{

GLCDSelectSide( RIGHT ); // Select left side
GLCDInstructionWrite( X_ADRESS + ( Yaxis / 8 ) ); // Select page number
GLCDInstructionWrite( Y_ADRESS + Xaxis - 64 ); // Select column

DataRead = GLCDDataRead( ); // Read the current location
DataRead = GLCDDataRead( ); // on the LCD. dummy read

GLCDInstructionWrite( X_ADRESS + ( Yaxis / 8 ) ); // Select page number
GLCDInstructionWrite( Y_ADRESS + Xaxis - 64 ); // Select column
GLCDDataWrite( DataRead | ( 1 << ( Yaxis % 8 ) ) ); // Plot the dot

}

GLCDInstructionWrite( START_LINE ); // Set adress for line 0

}

void GLCDRectangle( U16 Xaxis1, U16 Yaxis1, U16 Xaxis2, U16 Yaxis2 )
{

U16 CurrentValue = 0;

// Draw the two horizontal lines
for( CurrentValue = 0; CurrentValue < Xaxis2 - Xaxis1+ 1; CurrentValue++ )
{

GLCDSetDot( Xaxis1 + CurrentValue, Yaxis1 );
GLCDSetDot( Xaxis1 + CurrentValue, Yaxis2 );
}

// Draw the two vertical lines
for( CurrentValue = 0; CurrentValue < Yaxis2 - Yaxis1 + 1; CurrentValue++ )
{

GLCDSetDot( Xaxis1, Yaxis1 + CurrentValue );
GLCDSetDot( Xaxis2, Yaxis1 + CurrentValue );

}

}
*/
void main( )
{

CMCON |= 0x07; // Turn off comparators
ADCON1 |= 0x0F; // Turn off analog inputs
MEMCON.EBDIS = 1; // Disable external memory bus

TRISJ = 0;
TRISD = 0;

//GLCDInt( );
//GLCDDataWrite( 0x65 );
//GLCDRectangle( 1, 1, 1, 1 );
Glcd_Init( &PORTJ, 0, 1, 2, 3, 5, 4, &PORTD ); // Glcd_Init_BP5, see Autocomplete
Glcd_Fill( 0x00 );
GLCD_Write_Text( "RACE=DYNAMICS" , 25, 11, 2 );
//GLCDSetDot(0,0);
//GLCDRectangle( 0, 0, 10, 10 );

}

Regards,
Deepak.
 

glcd india

Code Working!! A little more tuning and I'l have the entire working code. Will update the code once I'm done. Cheers!
 

I finally have the perfect woking complete code for the GLCD. Will post it if anyone requires it.. Cheers:)
 

Re: glcd_init_bp5 sir can u send me ur working code

sir can u send me ur working code..i need to display simple character on glcd
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top