curt2go
Joined: 21 Nov 2003 Posts: 200
|
graphic lcd problems.. |
Posted: Tue Nov 25, 2003 12:46 pm |
|
|
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;
} |
|