CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

graphic lcd problems..

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
curt2go



Joined: 21 Nov 2003
Posts: 200

View user's profile Send private message

graphic lcd problems..
PostPosted: Tue Nov 25, 2003 12:46 pm     Reply with quote

I have been able to make the code from CCS in there examples to work very well. BUT they do not implement an easy screen print like lcd_putc or something. Now I have tried to implement the other code that was shown to me in the Samsung thread. The problem is I am testing with a f877 and must split the constant BYTE TEXT into 2 diff constants. Here is the code I am using from the other thread it compiles fine but the characters come out garbled up. Any help would be appreciated.. TTY

PS Sorry its so long..



#ifndef GLCD_C
#define GLCD_C

//#ifndef GLCD_WIDTH
#define GLCD_WIDTH 128 // Used for text wrapping by glcd_text57 function
//#endif

#define ON 1
#define OFF 0

#define YES 1
#define NO 0

#ifndef glcd_cs1
#define glcd_cs1 PIN_B1 // Chip Selection 1
#endif

#ifndef GLCD_CS2
#define GLCD_CS2 PIN_B0 // Chip Selection 2
#endif

#ifndef GLCD_DI
#define GLCD_DI PIN_B2 // Data or Instruction input
#endif

#ifndef GLCD_RW
#define GLCD_RW PIN_B4 // Read/Write
#endif

#ifndef GLCD_E
#define GLCD_E PIN_B5 // Enable
#endif

#ifndef GLCD_RST
#define GLCD_RST PIN_C0 // Reset
#endif



BYTE glcd_readByte(BYTE chip);
void glcd_writeByte(BYTE chip, BYTE data);
void glcd_fillScreen(int1 color);

const BYTE TEXT[51][5] ={0x00, 0x00, 0x00, 0x00, 0x00, // SPACE
0x00, 0x00, 0x5F, 0x00, 0x00, // !
0x00, 0x03, 0x00, 0x03, 0x00, // "
0x14, 0x3E, 0x14, 0x3E, 0x14, // #
0x24, 0x2A, 0x7F, 0x2A, 0x12, // $
0x43, 0x33, 0x08, 0x66, 0x61, // %
0x36, 0x49, 0x55, 0x22, 0x50, // &
0x00, 0x05, 0x03, 0x00, 0x00, // '
0x00, 0x1C, 0x22, 0x41, 0x00, // (
0x00, 0x41, 0x22, 0x1C, 0x00, // )
0x14, 0x08, 0x3E, 0x08, 0x14, // *
0x08, 0x08, 0x3E, 0x08, 0x08, // +
0x00, 0x50, 0x30, 0x00, 0x00, // ,
0x08, 0x08, 0x08, 0x08, 0x08, // -
0x00, 0x60, 0x60, 0x00, 0x00, // .
0x20, 0x10, 0x08, 0x04, 0x02, // /
0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
0x04, 0x02, 0x7F, 0x00, 0x00, // 1
0x42, 0x61, 0x51, 0x49, 0x46, // 2
0x22, 0x41, 0x49, 0x49, 0x36, // 3
0x18, 0x14, 0x12, 0x7F, 0x10, // 4
0x27, 0x45, 0x45, 0x45, 0x39, // 5
0x3E, 0x49, 0x49, 0x49, 0x32, // 6
0x01, 0x01, 0x71, 0x09, 0x07, // 7
0x36, 0x49, 0x49, 0x49, 0x36, // 8
0x26, 0x49, 0x49, 0x49, 0x3E, // 9
0x00, 0x36, 0x36, 0x00, 0x00, // :
0x00, 0x56, 0x36, 0x00, 0x00, // ;
0x08, 0x14, 0x22, 0x41, 0x00, // <
0x14, 0x14, 0x14, 0x14, 0x14, // =
0x00, 0x41, 0x22, 0x14, 0x08, // >
0x02, 0x01, 0x51, 0x09, 0x06, // ?
0x3E, 0x41, 0x59, 0x55, 0x5E, // @
0x7E, 0x09, 0x09, 0x09, 0x7E, // A
0x7F, 0x49, 0x49, 0x49, 0x36, // B
0x3E, 0x41, 0x41, 0x41, 0x22, // C
0x7F, 0x41, 0x41, 0x41, 0x3E, // D
0x7F, 0x49, 0x49, 0x49, 0x41, // E
0x7F, 0x09, 0x09, 0x09, 0x01, // F
0x3E, 0x41, 0x41, 0x49, 0x3A, // G
0x7F, 0x08, 0x08, 0x08, 0x7F, // H
0x00, 0x41, 0x7F, 0x41, 0x00, // I
0x30, 0x40, 0x40, 0x40, 0x3F, // J
0x7F, 0x08, 0x14, 0x22, 0x41, // K
0x7F, 0x40, 0x40, 0x40, 0x40, // L
0x7F, 0x02, 0x0C, 0x02, 0x7F, // M
0x7F, 0x02, 0x04, 0x08, 0x7F, // N
0x3E, 0x41, 0x41, 0x41, 0x3E, // O
0x7F, 0x09, 0x09, 0x09, 0x06, // P
0x1E, 0x21, 0x21, 0x21, 0x5E, // Q
0x7F, 0x09, 0x09, 0x09, 0x76};// R

const BYTE TEXT2[44][5]={0x26, 0x49, 0x49, 0x49, 0x32, // S
0x01, 0x01, 0x7F, 0x01, 0x01, // T
0x3F, 0x40, 0x40, 0x40, 0x3F, // U
0x1F, 0x20, 0x40, 0x20, 0x1F, // V
0x7F, 0x20, 0x10, 0x20, 0x7F, // W
0x41, 0x22, 0x1C, 0x22, 0x41, // X
0x07, 0x08, 0x70, 0x08, 0x07, // Y
0x61, 0x51, 0x49, 0x45, 0x43, // Z
0x00, 0x7F, 0x41, 0x00, 0x00, // [
0x02, 0x04, 0x08, 0x10, 0x20, // \
0x00, 0x00, 0x41, 0x7F, 0x00, // ]
0x04, 0x02, 0x01, 0x02, 0x04, // ^
0x40, 0x40, 0x40, 0x40, 0x40, // _
0x00, 0x01, 0x02, 0x04, 0x00, // `
0x20, 0x54, 0x54, 0x54, 0x78, // a
0x7F, 0x44, 0x44, 0x44, 0x38, // b
0x38, 0x44, 0x44, 0x44, 0x44, // c
0x38, 0x44, 0x44, 0x44, 0x7F, // d
0x38, 0x54, 0x54, 0x54, 0x18, // e
0x04, 0x04, 0x7E, 0x05, 0x05, // f
0x08, 0x54, 0x54, 0x54, 0x3C, // g
0x7F, 0x08, 0x04, 0x04, 0x78, // h
0x00, 0x44, 0x7D, 0x40, 0x00, // i
0x20, 0x40, 0x44, 0x3D, 0x00, // j
0x7F, 0x10, 0x28, 0x44, 0x00, // k
0x00, 0x41, 0x7F, 0x40, 0x00, // l
0x7C, 0x04, 0x78, 0x04, 0x78, // m
0x7C, 0x08, 0x04, 0x04, 0x78, // n
0x38, 0x44, 0x44, 0x44, 0x38, // o
0x7C, 0x14, 0x14, 0x14, 0x08, // p
0x08, 0x14, 0x14, 0x14, 0x7C, // q
0x00, 0x7C, 0x08, 0x04, 0x04, // r
0x48, 0x54, 0x54, 0x54, 0x20, // s
0x04, 0x04, 0x3F, 0x44, 0x44, // t
0x3C, 0x40, 0x40, 0x20, 0x7C, // u
0x1C, 0x20, 0x40, 0x20, 0x1C, // v
0x3C, 0x40, 0x30, 0x40, 0x3C, // w
0x44, 0x28, 0x10, 0x28, 0x44, // x
0x0C, 0x50, 0x50, 0x50, 0x3C, // y
0x44, 0x64, 0x54, 0x4C, 0x44, // z
0x00, 0x08, 0x36, 0x41, 0x41, // {
0x00, 0x00, 0x7F, 0x00, 0x00, // |
0x41, 0x41, 0x36, 0x08, 0x00, // }
0x02, 0x01, 0x02, 0x04, 0x02};// ~


// Purpose: Initialize a graphic LCD. This must be called before any
// other glcd function is used.
// Inputs: The initialization mode
// OFF - Turns the LCD off
// ON - Turns the LCD on
// Date: 5/28/2003
void glcd_init(int1 mode)
{
// Initialze some pins
output_high(GLCD_RST);
output_low(GLCD_E);
output_low(glcd_cs1);
output_low(GLCD_CS2);

output_low(GLCD_DI); // Set for instruction
glcd_writeByte(glcd_cs1, 0xC0); // Specify first RAM line at the top
glcd_writeByte(GLCD_CS2, 0xC0); // of the screen
glcd_writeByte(glcd_cs1, 0x40); // Set the column address to 0
glcd_writeByte(GLCD_CS2, 0x40);
glcd_writeByte(glcd_cs1, 0xB8); // Set the page address to 0
glcd_writeByte(GLCD_CS2, 0xB8);
if(mode == ON)
{
glcd_writeByte(glcd_cs1, 0x3F); // Turn the display on
glcd_writeByte(GLCD_CS2, 0x3F);
}
else
{
glcd_writeByte(glcd_cs1, 0x3E); // Turn the display off
glcd_writeByte(GLCD_CS2, 0x3E);
}

glcd_fillScreen(OFF); // Clear the display
}



#byte PORTD= 8

// the screen is built
//chip 1 chip 2
//1 - > 64 1 - > 64
//::----:: ::----:: byte byte
//::----:: ::----:: " "
//::----:: ::----:: " "
//::----:: ::----:: " "
//
//::----:: ::----::
//::----:: ::----::
//::----:: ::----::
//::----:: ::----::
//etc, 8 horizontal lines

#byte lcd_data = PORTD //ensure PORTD is declared as a byte
#use fast_io(D)

#define LCD_LEFT 1
#define LCD_RIGHT 0

void lcd_init(void);
void lcd_write(int1 half);
void lcd_gotoxy(int8 x, int8 y);
void lcd_clrscr(void);
void lcd_newline(void);
void lcd_load_bmp(void);

//position on LCD, x = 0 - 127, y = 0 - 7
int8 x_position, y_position;

#define CS1_MAX_X 63 //chip 1 x range 0 - 63
#define CS2_MAX_X 127 //chip 1 x range 64 - 127

#define DISPLAY_ON 0x3F //LCD Display ON
#define DISPLAY_OFF 0x3E //LCD Display OFF
#define SET_X 0x40 //LCD SET X command, add x - 0 to 63
#define SET_Y 0xB8 //LCD SET Y command, add y - 0 to 7
#define SET_RAM_0 0xC0 //LCD RAM, used for scrolling add x - 0 to 63

void lcd_init(void)
{

//init LCD lines
set_tris_d(0x00);
lcd_data = 0x00;
output_high(glcd_DI);
output_low(glcd_rw);
output_low(glcd_e);
output_low(glcd_cs1);
output_low(glcd_cs2);

//reset LCD
output_high(glcd_rst);
delay_us(10);
output_low(glcd_rst);
delay_us(5);
output_high(glcd_rst);
delay_us(10);

//command mode
output_low(glcd_DI);
lcd_data = DISPLAY_OFF;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
lcd_data = SET_RAM_0;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
lcd_gotoxy(0,0);
lcd_data = DISPLAY_ON;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
output_high(glcd_DI);

x_position = 0;
y_position = 0;

return;
}



void lcd_write(int1 half)
{
if(half)
{
output_high(glcd_cs1);
output_low(glcd_cs2);
}
else
{
output_low(glcd_cs1);
output_high(glcd_cs2);
}
delay_us(2);
output_high(glcd_e);
delay_us(2);
output_low(glcd_e);
delay_us(2);

return;
}



void lcd_clrscr(void)
{
int8 x,y;

output_low(glcd_DI);

lcd_data = DISPLAY_OFF;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);

output_high(glcd_DI);

for(y=0; y<8; y++)
{
output_low(glcd_DI);

lcd_data = SET_Y + y;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);

output_high(glcd_DI);

for(x=0; x<64; x++)
{
lcd_data = 0;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
}
}

output_low(glcd_DI);

lcd_data = DISPLAY_ON;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);

output_high(glcd_DI);

lcd_gotoxy(0,0);

return;
}


void lcd_putc( char c)
{
int16 index,count;
int8 x;

switch (c)
{
case '\f' :
lcd_clrscr();
break;

case '\n' :
lcd_newline();
break;

default :
//check there is space to print
if((x_position + 5) < CS2_MAX_X)
{ //print character
index = (int16)(c - 32) * 5;

for(x=0; x<5; x++)
{
lcd_data = TEXT[index++];
if(x_position > CS1_MAX_X)
{
lcd_write(LCD_RIGHT);
}
else
{
lcd_write(LCD_LEFT);
}
x_position++;
}
}
if((x_position + 1) < CS2_MAX_X)
{
lcd_data = 0x00;
if(x_position > CS1_MAX_X)
{
lcd_write(LCD_RIGHT);
}
else
{
lcd_write(LCD_LEFT);
}
x_position++;
}
break;
}

return;
}






int8 lcd_read_byte( void )
{

}



void lcd_gotoxy( int8 x, int8 y)
{
x_position = x;
y_position = y;

output_low(glcd_DI);
if(x > 63)
{
x = x - 63;
lcd_data = SET_X + x;
lcd_write(LCD_RIGHT);

lcd_data = SET_X;
lcd_write(LCD_LEFT);
}
else
{
lcd_data = SET_X + x;
lcd_write(LCD_LEFT);

lcd_data = SET_X;
lcd_write(LCD_RIGHT);
}

lcd_data = SET_Y + y;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
output_high(glcd_DI);

return;
}


void lcd_newline(void)
{
x_position = 0;

if(y_position < 7) //check for last line
{
y_position ++;

output_low(glcd_DI);
lcd_data = SET_X;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
lcd_data = SET_Y + y_position;
lcd_write(LCD_LEFT);
lcd_write(LCD_RIGHT);
output_high(glcd_DI);
}

return;
}
Guest








PostPosted: Tue Nov 25, 2003 4:05 pm     Reply with quote

Basically what I am looking to do is just write text out to the screen by using a printf or something like that. I am having problems doing this in the graphic display. Once again I am using the Samsung KS0108 on the CrystalFonts display. Thanx in advance.. TTY
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 25, 2003 4:31 pm     Reply with quote

Re: More info on the KS0108:

Here a driver for the Atmel AVR (ie., another micro-controller):
http://ccrma-www.stanford.edu/courses/250a/docs/avrlib-new/glcd_8c.html
Apparently, another page related to that one:
http://hubbard.engr.scu.edu/embedded/avr/avrlib/

An LCD forum, similar to the CCS forum, that talks about LCD drivers:
http://www.skippari.net/phpBB2/viewforum.php?f=9
Guest








PostPosted: Tue Nov 25, 2003 9:11 pm     Reply with quote

That may do the trick. I will test it out tommorow. I never thought puting chars out to the screen would be this difficult.. TTY
Acetoel



Joined: 20 Dec 2003
Posts: 7

View user's profile Send private message

graphic lcd problem...
PostPosted: Sat Dec 20, 2003 4:21 am     Reply with quote

Hello

I'm trying to interfase a Samsung KS0108 controller based GLCD (Winstar 128x64) with a PIC18F452. Does anybody has a piece of code or a library for this GLCD?
Thanks very much
Ezequiel
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group