LCDInfo.com

http://www.lcdinfo.com
It is currently Fri Nov 22, 2024 9:03

All times are UTC + 2 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Sun Jan 11, 2004 13:16 
Offline

Joined: Sun Jan 11, 2004 12:57
Posts: 3
Hi !

NO MORE PROBLEMS !!! IT WORKS !!! :D
The negative voltage for the contrast was the problem. The Code works - could be better but it works.

THANX !!!


Last edited by heijak on Mon Jan 12, 2004 15:42, edited 2 times in total.

Top
 Profile  
 
PostPosted: Sun Jan 11, 2004 20:17 
Offline

Joined: Sun Dec 07, 2003 23:27
Posts: 3
Location: Jyväskylä
heijak wrote:
void testdata() { //send displaydata to the lcd
//output_high(CS1);
//output_high(CS2);
output_high(RS);
//output_low(RW);
}


Since I don't know how you have connected LCD to pic I can't be sure what is wrong(if something with code is). But if you post link to scematics and specific display type (there are some differences between logic levels = inverted/noninverted inputs), then I believe that someone could help you with your problem.

Edit: Sorry I didn't read sourse well enough, missed point where CS-pins were set.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 1:17 
Offline

Joined: Sun Jan 11, 2004 12:57
Posts: 3
Hi !!
THANX for your reply.
I actually changed the code a bit. I think it's more readable that way. But it still doesnt work ... :cry: !!! Looks like that just the backlight is working .. :evil:

Something about the connections:
LCD -> PIC16f77
RS -> Port B Pin 7
RW -> Port B Pin 6
E -> Port B Pin 5
D0 -> Port B Pin 4
D1 -> Port B Pin 3
... D4 -> Port B Pin 0
D5 -> Port D Pin 7
D6-> Port D Pin 6
D7 -> Port D Pin 5
CS1 -> Port D Pin 4
CS2 -> Port D Pin 3
Reset -> Port D Pin 2
I used that schematic (replace the parallel port with the PIC16):
http://home.pi.be/~depippe/scheme.gif

Here is the "new" source-code:
#include <16F77.h>
#use delay(clock=20000000)
#define RS PIN_B7
#define RW PIN_B6
#define E PIN_B5
#define D0 PIN_B4
#define D1 PIN_B3
#define D2 PIN_B2
#define D3 PIN_B1
#define D4 PIN_B0
#define D5 PIN_D7
#define D6 PIN_D6
#define D7 PIN_D5
#define CS1 PIN_D4
#define CS2 PIN_D3
#define RESET PIN_D2
int i = 0;
int c = 0;

void pinsetup() {
set_tris_b(0); //port B all outputs
output_b(0); //output on port B all 0s
set_tris_d(0); //port D all outputs
output_d(0); //output on port D all 0s
output_high(RESET); //set Reset to 1, RESET not active ??
delay_ms(1000);
}

void startline() { //instruction to set display start line
output_high(CS1); //select cs1
output_low(CS2);
output_low(RS);
output_low(RW);
delay_ms(250);
output_high(E);
delay_ms(560);
output_low(D0); //display start line
output_low(D1);
output_low(D2);
output_low(D3);
output_low(D4);
output_low(D5);
output_high(D6);
output_high(D7);
delay_ms(50);
output_low(E);
delay_ms(560); //560
}

void setpage() { //instruction to set x address in addressregister
output_high(CS1); //select cs1
output_low(CS2);
output_low(RS);
output_low(RW);
delay_ms(250);
output_high(E);
delay_ms(560);
output_low(D0);
output_low(D1);
output_low(D2);
output_high(D3);
output_high(D4);
output_high(D5);
output_low(D6);
output_high(D7);
delay_ms(50);
output_low(E);
}

void setline() { //instruction to set y address in addresscounter
output_high(CS1); //select cs1
output_low(CS2);
output_low(RS);
output_low(RW);
delay_ms(250);
output_high(E);
delay_ms(560);
output_low(D0);
output_low(D1);
output_low(D2);
output_low(D3);
output_low(D4);
output_low(D5);
output_high(D6);
output_low(D7);
delay_ms(50);
output_low(E);
delay_ms(560);
}

void lcdstartup() { //send display on instruction to the lcd
output_low(E);
delay_ms(560);
output_high(CS1); //select cs1
output_low(CS2);
output_low(RS);
output_low(RW);
delay_ms(250);
output_high(E);
delay_ms(560);
output_high(D0); //display on sequence
output_high(D1);
output_high(D2);
output_high(D3);
output_high(D4);
output_high(D5);
output_low(D6);
output_low(D7);
delay_ms(50);
output_low(E);
delay_ms(560); //=>cs1 on
setpage();
setline();
startline();
i=1;
}

void jumping_e() { //changes E from 1 to 0
output_high(E);
delay_ms(550);
output_low(E);
delay_ms(560);
++c;
}

void testdata() { // should write 11111111 into dram
output_high(CS1); //select cs1
output_low(CS2);
output_high(RS);
output_low(RW);
delay_ms(250);
output_high(E);
delay_ms(560);
output_high(D0); //data for dram
output_high(D1);
output_high(D2);
output_high(D3);
output_high(D4);
output_high(D5);
output_high(D6);
output_high(D7);
delay_ms(50);
output_low(E); //=>write 11111111 into dram
while(c<20)
jumping_e();
}

void main() {
delay_ms(2000);
pinsetup();
if (i<1)
lcdstartup();
testdata();
}

Maybe someone finds a solution ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 21:52 
Offline

Joined: Fri Nov 28, 2003 21:49
Posts: 3
Which compiler are you using?
If you are using CCS then the example glcd.c actually is for the ks0108.
I wrote my own driver before realising this.

If you still have problems I will post code.
:)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 22:00 
Offline

Joined: Fri Nov 28, 2003 21:49
Posts: 3
here is my code, I cannot post the ccs driver obviously
visit www.compysys1.com/workbench
there is a facility for converting bmps to raw data for use with the ks0108

#include "bmp.c"
#include "splash.c"

#byte PORTA= 0x0F80
#byte PORTB= 0x0F81
#byte PORTC= 0x0F82
#byte PORTD= 0x0F83

//board specific definitions for pins
#define lcd_enable PIN_C0 //Enable pin on LCD
#define lcd_cmd PIN_C1 //Data/Command Pin 4 on LCD
#define lcd_rw PIN_C2 //Read/Write Pin 5 on LCD
#define lcd_cs1 PIN_B1 //ChipSelect1 Pin 15 on LCD
#define lcd_cs2 PIN_B2 //ChipSelect2 Pin 16 on LCD
#define lcd_rst PIN_C5 //Reset Pin 17 on LCD

#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_progress_bar(int8 x_start, int8 y_start, int8 length, int1 color);

CHAR CONST fonts[475]= { //dec ascii
0x00,0x00,0x00,0x00,0x00, //32 <Space>
0x00,0x00,0x4F,0x00,0x00, //33 !
0x00,0x07,0x00,0x07,0x00, //34 "
0x14,0x7F,0x14,0x7F,0x14, //35 #
0x24,0x2A,0x7F,0x2A,0x12, //36 $
0x23,0x13,0x08,0x64,0x62, //37 %
0x36,0x49,0x55,0x22,0x50, //38 &
0x00,0x05,0x03,0x00,0x00, //39 '
0x1C,0x22,0x41,0x00,0x00, //40 (
0x00,0x00,0x41,0x22,0x1C, //41 )
0x14,0x08,0x3E,0x08,0x14, //42 *
0x08,0x08,0x3E,0x08,0x08, //43 +
0x00,0x50,0x30,0x00,0x00, //44 ,
0x08,0x08,0x08,0x08,0x08, //45 -
0x00,0x60,0x60,0x00,0x00, //46 .
0x20,0x10,0x08,0x04,0x02, //47 /
0x3E,0x51,0x49,0x45,0x3E, //48 0
0x00,0x42,0x7F,0x40,0x00, //49 1
0x42,0x61,0x51,0x49,0x46, //50 2
0x21,0x41,0x45,0x4B,0x31, //51 3
0x18,0x14,0x12,0x7F,0x10, //52 4
0x27,0x45,0x45,0x45,0x39, //53 5
0x3C,0x4A,0x49,0x49,0x30, //54 6
0x01,0x71,0x09,0x05,0x03, //55 7
0x36,0x49,0x49,0x49,0x36, //56 8
0x06,0x49,0x49,0x49,0x3E, //57 9
0x00,0x36,0x36,0x00,0x00, //58 :
0x00,0x56,0x36,0x00,0x00, //59 ;
0x08,0x14,0x22,0x41,0x00, //60 <
0x14,0x14,0x14,0x14,0x14, //61 =
0x00,0x41,0x22,0x14,0x08, //62 >
0x02,0x01,0x51,0x09,0x06, //63 ?
0x32,0x49,0x79,0x41,0x3E, //64 @
0x7E,0x11,0x11,0x11,0x7E, //65 A
0x7F,0x49,0x49,0x49,0x36, //66 B
0x3E,0x41,0x41,0x41,0x22, //67 C
0x7F,0x41,0x41,0x22,0x1C, //68 D
0x7F,0x49,0x49,0x49,0x41, //69 E
0x7F,0x09,0x09,0x09,0x01, //70 F
0x3E,0x41,0x49,0x49,0x7A, //71 G
0x7F,0x08,0x08,0x08,0x7F, //72 H
0x00,0x41,0x7F,0x41,0x00, //73 I
0x20,0x40,0x41,0x3F,0x01, //74 J
0x7F,0x08,0x14,0x22,0x41, //75 K
0x7F,0x40,0x40,0x40,0x40, //76 L
0x7F,0x02,0x0C,0x02,0x7F, //77 M
0x7F,0x04,0x08,0x10,0x7F, //78 N
0x3E,0x41,0x41,0x41,0x3E, //79 O
0x7F,0x09,0x09,0x09,0x06, //80 P
0x3E,0x41,0x51,0x21,0x5E, //81 Q
0x7F,0x09,0x19,0x29,0x46, //82 R
0x46,0x49,0x49,0x49,0x31, //83 S
0x01,0x01,0x7F,0x01,0x01, //84 T
0x3F,0x40,0x40,0x40,0x3F, //85 U
0x1F,0x20,0x40,0x20,0x1F, //86 V
0x3F,0x40,0x38,0x40,0x3F, //87 W
0x63,0x14,0x08,0x14,0x63, //88 X
0x07,0x08,0x70,0x08,0x07, //89 Y
0x61,0x51,0x49,0x45,0x43, //90 Z
0x7F,0x41,0x41,0x00,0x00, //91 [
0x02,0x04,0x08,0x10,0x20, //92 \
0x00,0x00,0x41,0x41,0x7F, //93 ]
0x04,0x02,0x01,0x02,0x04, //94 ^
0x40,0x40,0x40,0x40,0x40, //95 _
0x00,0x01,0x02,0x04,0x00, //96 `
0x20,0x54,0x54,0x54,0x78, //97 a
0x7F,0x48,0x44,0x44,0x38, //98 b
0x38,0x44,0x44,0x44,0x20, //99 c
0x38,0x44,0x44,0x48,0x7F, //100 d
0x38,0x54,0x54,0x54,0x18, //101 e
0x08,0x7E,0x09,0x01,0x02, //102 f
0x0C,0x52,0x52,0x52,0x3E, //103 g
0x7F,0x08,0x04,0x04,0x78, //104 h
0x00,0x44,0x7D,0x40,0x00, //105 i
0x00,0x20,0x40,0x44,0x3D, //106 j
0x7F,0x10,0x28,0x44,0x00, //107 k
0x00,0x41,0x7F,0x40,0x00, //108 l
0x7C,0x04,0x18,0x04,0x78, //109 m
0x7C,0x08,0x04,0x04,0x78, //110 n
0x38,0x44,0x44,0x44,0x38, //111 o
0x7C,0x14,0x14,0x14,0x08, //112 p
0x08,0x14,0x14,0x18,0x7C, //113 q
0x7C,0x08,0x04,0x04,0x08, //114 r
0x48,0x54,0x54,0x54,0x20, //115 s
0x04,0x3F,0x44,0x40,0x20, //116 t
0x3C,0x40,0x40,0x20,0x7C, //117 u
0x1C,0x20,0x40,0x20,0x1C, //118 v
0x3C,0x40,0x30,0x40,0x3C, //119 w
0x44,0x28,0x10,0x28,0x44, //120 x
0x0C,0x50,0x50,0x50,0x3C, //121 y
0x44,0x64,0x54,0x4C,0x44, //122 z
0x08,0x36,0x41,0x00,0x00, //123 {
0x00,0x00,0x7F,0x00,0x00, //124 |
0x00,0x00,0x41,0x36,0x08, //125 }
// 0x00,0x08,0x04,0x08,0x04 //126 ~
0x7E,0x7E,0xFF,0x7E,0x7E //126 ~

};

//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(lcd_cmd);
output_low(lcd_rw);
output_low(lcd_enable);
output_low(lcd_cs1);
output_low(lcd_cs2);

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

//command mode
output_low(lcd_cmd);
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(lcd_cmd);

x_position = 0;
y_position = 0;

return;
}



void lcd_write(int1 half)
{
delay_us(10);
if(half)
{
output_high(lcd_cs1);
output_low(lcd_cs2);
}
else
{
output_low(lcd_cs1);
output_high(lcd_cs2);
}
delay_us(5);
output_high(lcd_enable);
delay_us(5);
output_low(lcd_enable);
delay_us(5);

return;
}



void lcd_clrscr(void)
{
int8 x,y;

output_low(lcd_cmd);

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

output_high(lcd_cmd);

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

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

output_high(lcd_cmd);

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

output_low(lcd_cmd);

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

output_high(lcd_cmd);

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 = fonts[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()
{
int8 data;
set_tris_d(0xFF);


output_high(lcd_rw);
if(x_position > 63)
{
output_high(lcd_cs2);
delay_us(2);
output_high(lcd_enable);
delay_us(2);
output_low(lcd_enable);
delay_us(2);
output_high(lcd_enable);
delay_us(6);
data = lcd_data;
output_low(lcd_enable);
delay_us(2);
output_low(lcd_cs2);

}
else
{
output_high(lcd_cs1);
delay_us(2);
output_high(lcd_enable);
delay_us(2);
output_low(lcd_enable);
delay_us(2);
output_high(lcd_enable);
delay_us(6);
data = lcd_data;
output_low(lcd_enable);
delay_us(2);
output_low(lcd_cs1);

}
output_low(lcd_rw);
set_tris_d(0x00);

return data;
}



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

output_low(lcd_cmd);
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(lcd_cmd);

return;
}


void lcd_newline(void)
{
x_position = 0;

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

output_low(lcd_cmd);
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(lcd_cmd);
}

return;
}


void lcd_load_bmp(void)
{
int8 x,y;
int16 ptr=0;


output_low(lcd_cmd);

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

output_high(lcd_cmd);

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

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

output_high(lcd_cmd);

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

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

output_high(lcd_cmd);

lcd_gotoxy(0,0);

return;
}

void lcd_load_splash(void)
{
int8 x,y;
int16 ptr=0;


output_low(lcd_cmd);

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

output_high(lcd_cmd);

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

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

output_high(lcd_cmd);

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

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

output_high(lcd_cmd);

lcd_gotoxy(0,0);

return;
}


void lcd_progress_bar(int8 x_start, int8 y_start, int8 length, int1 color)
{
int8 x_end,x;

lcd_gotoxy(x_start, y_start);
x_end = x_start + length;

if(color == 1)
{
lcd_data = 0xFF;
}
else
{
lcd_data = 0x00;
}
//check there is space to print
if((x_position + length) < CS2_MAX_X)
{
for(x=0; x<length; x++)
{
if(x_position > CS1_MAX_X)
{
lcd_write(LCD_RIGHT);
}
else
{
lcd_write(LCD_LEFT);
}
x_position++;
}
}
return;
}


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 07, 2004 0:49 
Offline

Joined: Sun Jan 11, 2004 12:57
Posts: 3
Hi !

Thanx for your help. Your code will help me to understand how the display and all the functions work.

heijak


Top
 Profile  
 
PostPosted: Mon Apr 12, 2004 17:12 
Offline

Joined: Mon Apr 12, 2004 17:04
Posts: 1
Location: Colombia
Hi!!

i'm new on this forum and i found all the information very usefull.
i need to connnect a PIC microcontroller to a ks108 lcd, i tried to used the programs that you posted in the forum but i need the 16F77.h, bmp.c and
splash.c files, please you can say me where can i get them?
Thanks in advance for all your help


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 11:49 
Offline

Joined: Sun May 05, 2002 22:05
Posts: 2063
Location: Lappeenranta, Finland
I'm not sure what is in the bmp.c and splash.c files but they might include some image data.
16F77.h comes with the compiler. I'm not sure which compiler was used here, maybe CCS.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 2 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group