PDA

View Full Version : LCD Control



boboco
- 12th January 2006, 09:31
Hi All,

I use PBP.

I know this must be an old hat, but I've been trying this one for days. I'm using a Displaytech 162 LCD 2 x 16 on a PIC16F877 port d and, do what I will, I can't get it to write the second line. I've tried all sorts of DEFINES etc. without success.

If I define the display as one line, which I still suppose it to be, first line is normal, second line nothing. If I define the device as 2 line, however, I get no display at all.

Second line adress is given as 40H, but I've tried almost anything to no purpose.

I've driven lots of LCDs with lots of PICs and had some problems, but this is new to me. Or is the display most probably defect?

mister_e
- 12th January 2006, 15:33
Can you provide any datasheet for us? sometime we feel lazy to search... at least me ;)

Luciano
- 12th January 2006, 16:56
Hi,

Add 80h to the character address to make
the Display Data RAM Address Set command.
(When you add 80h you set bit 7).


$00 + $80 = $80
$40 + $80 = $c0



LCDOUT $FE,$80, "Hello on line 1"
LCDOUT $FE,$C0, "Hello on line 2"


Best regards,

Luciano

boboco
- 13th January 2006, 08:17
Hi Luciano, Hi Mister_e,

I have already tried the code as you write, Luciano, it doesn't work on this unit but thanks all the same.

If the unit isn't defect I'm wondering if the display controller chip is non-compatible to the Hitachi, it's a KS0070 but I believe it to be OK. I've got the data sheet in PDF and can send it to you if you require it, Mister_e. Checking through the command and address register it seems to be similar to the Hitachi controller. I'm beat.

mister_e
- 14th January 2006, 00:34
well, post your PDF here or the link to get it.

boboco
- 14th January 2006, 20:32
Hi Steve,

attached the PDF. Maybe you can find something. Thanks for the effort.

Greetings,

Rob

boboco
- 14th January 2006, 20:35
Hi Steve,

The file was too big, says BISOS.

Here the link

http://www.displaytech.com.hk/pdf/char/162a%20series-v11.PDF

Greetings,

Rob

mister_e
- 14th January 2006, 22:15
by searching here and there this one is suppose to be PBP compatible without too much problem. At least the controller is suppose to be HD44780 compliant.

Did you tried a longer start-up delay, let's say 2 Seconds at the top of the program?
Do you have another LCD to test with your current set-up?
What about the supply line? Clean and 5V?
what about your current setup? Any schematic or picture of it?

Maybe a simple hardware problem. unsufficient filtering or else.

alec
- 15th January 2006, 20:28
hi boboco

Try adding a 10ms pause between the two LCDOUT statements. It's the only way I've been able to display multiple lines.

boboco
- 16th January 2006, 12:11
Hi Steve, Hi Alec,

Alec, I've tried all sorts of delays, or even different program parts, to write line 2, all without success, but thanks anyway.

Steve, I usually allow 1 sec. startup, but trying 2 secs made no difference. The setup is a control circuit for medical laser x-y-z control containing analog and digital circuits. This model is supplied via laboratory power supply, is smoothed and filtered (100nF everywhere) and the line shows ca. 20 mV ripple in operation. The oscillator is decoupled from the VCC line because that causes lots of nasty noise usually. If you wish, I’ll send you the circuit diagram.

The code is the usual:


DEFINE LCD_etc…. ‘Setup LCD

Pause 1000 ‘Settle pause

LCDOUT, $FE, 1, “ Blah blah” ‘Write #1

GOSUB somewhere ‘Fetch, calculate variable

LCDOUT $FE, $C0, “ Blah “, DEC Variable ‘Display variable

I haven't got another unit of this size and type, to take another type for test will involve (sigh) a large amount of work as this is built-in and direct connected. If I don't get it to work, though, I'll buy a new one eventually. I don't like getting beat, though.

One point, I’m using a 16F877 and have the LCD defined to the D-Port as the only port free. I’m wondering if some register needs to be set/reset. I’ve been caught like that before. Is anything known? I’ve not found anything in the PIC Data book, but something with the parallel port control possible?

Greetings,

Rob

Rhatidbwoy
- 16th January 2006, 15:36
I was having a problem with HANTRONIX 20 x4.

I fixed the problem with a pause. In description to what I was getting was that I would get the second line to go and the fourth line to go. Not the first nor the third line to light. I played with many things, but what came to work was that I need a pause.

When you write your first line you normally would not need a clear screen (lcdout $fe, 1). So the second thing would write. leaving nothing for hte first line. This is were the pause is needed. So it looks something like this:

lcdout $fe,1
pause 10 'what ever value. I used 10
lcdout $fe, address (first line), (what ever you want to write here)
lcdout $fe, address (second line), (what ever you want to write here)

This might lead to something good and it might not, but it is something worth your while to try. I tried this with the 20x4 HANTRONIX and I got my screen to do what I wanted it to do.

boboco
- 18th January 2006, 08:21
Hi Rhatidbwoy,

I've tried all sorts of delay times beween lines, nothing works. I've ordered a new display, as I suppose this one to be defect. Thanks anyway.

Greetings

Acetronics2
- 18th January 2006, 09:02
Hi, Boboco

Was it a 50% Discount ???

...

Seriously, you should ask a question about that on the Displaytech site ...

Alain

Dave
- 18th January 2006, 12:26
boboco, As Rhatidbwoy mentioned I have found in the past (8+ years) that most LCD displays require anywhere from 5 to 15 Milliseconds to execute a clear command "$FE,01" or a home command "$FE,02". I have found this to be true with displays from OPTREX,ITRON,and CRYSTALFONTZ. They are all compatable with HD44780 type lcd controllers found on most lcds. Also whenever I use a command to place the cursor to a different location on the lcd I always use "PAUSEUS 100" as I have found in the past some displays require this delay. I have had no problems with any LCD or VFD displays using delays in my software as I have mentioned. LOL

Dave Purola,
N8NTA

Luciano
- 18th January 2006, 17:39
Initialization of a 16x2 LCD.

(4 bit Interface).

The first picture is the initialization of a Hitachi HD44780.
The second picture is the initialization of a Samsung KS0077.

Best regards,

Luciano


http://img8.picsplace.to/img8/7/lcd.JPG (http://picsplace.to/)



Hitachi HD44780 initialization
(The above picture)

E=1 D7=0 D6=0 D5=1 D4=1
E=1 D7=0 D6=0 D5=1 D4=1
E=1 D7=0 D6=0 D5=1 D4=1
E=1 D7=0 D6=0 D5=1 D4=0

E=1 D7=0 D6=0 D5=1 D4=0
E=1 D7=1 D6=0 D5=0 D4=0

E=1 D7=0 D6=0 D5=0 D4=0
E=1 D7=1 D6=1 D5=1 D4=0

E=1 D7=0 D6=0 D5=0 D4=0
E=1 D7=0 D6=1 D5=1 D4=0

E=1 D7=0 D6=0 D5=0 D4=0
E=1 D7=1 D6=1 D5=0 D4=0




Samsung KS0077 initialization
(The above picture)

E=1 D7=0 D6=0 D5=1 D4=1
E=1 D7=0 D6=0 D5=1 D4=1
E=1 D7=0 D6=0 D5=1 D4=1
E=1 D7=0 D6=0 D5=1 D4=0

E=1 D7=0 D6=0 D5=1 D4=0
E=1 D7=0 D6=1 D5=0 D4=0

E=1 D7=0 D6=0 D5=0 D4=0
E=1 D7=1 D6=0 D5=0 D4=1

E=1 D7=0 D6=0 D5=1 D4=0
E=1 D7=0 D6=0 D5=0 D4=0

E=1 D7=0 D6=0 D5=0 D4=0
E=1 D7=0 D6=0 D5=0 D4=0

E=1 D7=0 D6=0 D5=0 D4=0
E=1 D7=1 D6=1 D5=1 D4=0

E=1 D7=0 D6=0 D5=0 D4=0
E=1 D7=0 D6=1 D5=1 D4=0

E=1 D7=0 D6=0 D5=0 D4=0
E=1 D7=1 D6=1 D5=0 D4=0

boboco
- 19th January 2006, 08:23
Hi all,

thanks for the help.

Curious is that the first line functions exactly as it should in every way, only the second line not. If I turn the contrast up to maximal all pixels turn black, though, so at least the line isn't dead.

I've temporarily replaced the Displaytech with another type of unit. (all that work...., sob!) It worked at once so I take it that the Displaytech is bugged in some way. I've ordered a new one and hope that that will work, otherwise I'll have to change the whole construction to use some other. I'll report when I've got the results.

Another short question on LCD control +PBP. If I want to control a 4 liner, which is essentially two complete LCDs in one, I've been doing it by switching both enable lines via resistors from one port and shorting each of the enable lines respectively with another two ports to disable it.

It must be possible to program the PIC so that the selection of two enables is directly possible. (DEFINEs?) I've looked on the board but haven't found anything. Any ideas?

Greetings

Rob

boboco
- 19th January 2006, 08:30
Hi all again,

sorry Luciano, I didn't mention your post. As it would seem, the KS0077 isn't directly compatable to the HD44780. If that is the case, it would be interesting to write code for it as it is similar. If time allows, I'll try it.

Greetings,
Rob

boboco
- 19th January 2006, 08:39
Hi all,

thanks for the help.

Curious is that the first line functions exactly as it should in every way, only the second line not. If I turn the contrast up to maximal all pixels turn black, though, so at least the line isn't dead.

I've temporarily replaced the Displaytech with another type of unit. (all that work...., sob!) It worked at once so I take it that the Displaytech is bugged in some way. I've ordered a new one and hope that that will work, otherwise I'll have to change the whole construction to use some other. I'll report when I've got the results.

Another short question on LCD control +PBP. If I want to control a 4 liner, which is essentially two complete LCDs in one, I've been doing it by switching both enable lines via resistors from one port and shorting each of the enable lines respectively with another two ports to disable it.

It must be possible to program the PIC so that the selection of two enables is directly possible. (DEFINEs?) I've looked on the board but haven't found anything. Any ideas?

Greetings

Rob

Luciano
- 19th January 2006, 17:49
Hi,

Your display is not correctly initialized.
(This is why you get only one line).

In order to use your LCD (KS0070b), you will have
to manually initialize the KS0070b before you call the
first PicBasic LCDOUT.

Below you can find the pseudo code + a table.

Best regards,

Luciano


See PDF page 32 for the initialization of the KS0070B in 4 bit mode
http://www.ee.oulu.fi/research/tklab/courses/521426A/2003/LCD-driver-3316.pdf




KS0070b Initialization

2x16 LCD (KS0070b)
4 bit mode
2 lines
Display=on
Cursor=off
Blink=off
Increment mode
Entire shif=off

(Pseude-code, same as the table below).

==============================================
Power on
(PIC and LCD module).
==============================================
Wait 40 ms
==============================================

(Function Set)

------------------
Set the LCD pins:
DB7,DB6,DB5,DB4 = 0010

Toggle the Enable line:
PULSOUT Enable_Pin,100 (min.100 µs)
------------------
Set the LCD pins:
DB7,DB6,DB5,DB4 = 0010

Toggle the Enable line:
PULSOUT Enable_Pin,100 (min.100 µs)
------------------
Set the LCD pins:
DB7,DB6,DB5,DB4 = 1000 (2 lines, 5x7 dots)

Toggle the Enable line:
PULSOUT Enable_Pin,100 (min.100 µs)
------------------
==============================================
Wait 100 µs
==============================================

(Display On/Off Control)

Set the LCD pins:
DB7,DB6,DB5,DB4 = 0000

Toggle the Enable line:
PULSOUT Enable_Pin,100 (min.100 µs)

Set the LCD pins:
DB7,DB6,DB5,DB4 = 1100 (Display on, cursor off, blink off).

Toggle the Enable line:
PULSOUT Enable_Pin,100 (min.100 µs)

==============================================
Wait 100 µs
==============================================

(Clear display)

Set the LCD pins:
DB7,DB6,DB5,DB4 = 0000

Toggle the Enable line:
PULSOUT Enable_Pin,100 (min.100 µs)

Set the LCD pins:
DB7,DB6,DB5,DB4 = 0001

Toggle the Enable line:
PULSOUT Enable_Pin,100 (min.100 µs)

==============================================
Wait 2 ms
==============================================

(Entry Mode Set)

Set the LCD pins:
DB7,DB6,DB5,DB4 = 0000

Toggle the Enable line:
PULSOUT Enable_Pin,100 (min.100 µs)

Set the LCD pins:
DB7,DB6,DB5,DB4 = 0110 (Incremet mode, entire shif off).

Toggle the Enable line:
PULSOUT Enable_Pin,100 (min.100 µs)

==============================================
Wait 2 ms
==============================================


End of the KS0070b Initialization.



http://img9.picsplace.to/img9/6/ks0077b.JPG (http://picsplace.to/)

boboco
- 21st January 2006, 09:40
Hello Luciano,

Thanks, Pal. Now it works. And I've learnt something new.

Best greetings,

Rob

Jhdgkss
- 17th March 2007, 23:29
i two have purchased an lcd that uses a k0007b criver chip i tried you example of initalising the display manualy not notheing hear is my code can some one check it for me please.

'************************************************* ***************
'* Name : LCD template.BAS *
'* Author : John Hodgkiss *
'* Notice : Copyright (c) 2007 John Hodgkiss *
'* : All Rights Reserved *
'* Date : 17/03/2007 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ****************


'Template program for LCD useing a K0007b driver chip
'KS0070b Initialization

'2x16 LCD (KS0070b)
'4 bit mode
'2 lines
'Display=on
'Cursor=off
'Blink=off
'Increment mode
'Entire shif=off

start:
'Power on


'set variables

output portA
Db7 var byte
Db6 var byte
Db5 var byte
Db4 var byte
RS var byte
E var byte
PauseA var byte

PauseC var byte
'set constants

PauseA = 10 ' 100us

PauseC = 200 ' 2ms

'define
DEFINE LCD_DREG PORTA 'LCD data port

DEFINE LCD_DBIT 0 'LCD data starting bit 0 or 4

DEFINE LCD_RSREG PORTA 'LCD register select port
DEFINE LCD_RSBIT 5 'LCD register select bit

DEFINE LCD_EREG PORTA 'LCD enable port
DEFINE LCD_EBIT 4 'LCD enable bit

DEFINE LCD_BITS 4 'LCD bus size 4 or 8

DEFINE LCD_LINES 2 'Number lines on LCD

DEFINE LCD_COMMANDUS 2000 'Command delay time in us

DEFINE LCD_DATAUS 50 'Data delay time in us


pause 400 'pause for 40ms for lcd to start up




'set pins

Db7 = portA.3
Db6 = portA.2
Db5 = portA.1
Db4 = portA.0

RS = portA.4
E = PortB.3

output portA
Output portB
portA = low
PortB = low
setup:

DB7 = 0
DB6 = 0
DB5 = 1
DB4 = 0
'Toggle the Enable line:
PULSOUT E, 100
pause PauseA
E = low

DB7 = 0
DB6 = 0
DB5 = 1
DB4 = 0
'Toggle the Enable line:
PULSOUT E, 100
pause PauseA
E = low

'set 2 lines 5x7 dots
DB7 = 1
DB6 = 0
DB5 = 0
DB4 = 0
'Toggle the Enable line:
PULSOUT E, 100
pause PauseA
E = low

pause PauseA 'pause 100us

'turn display On/Off control

DB7 = 0
DB6 = 0
DB5 = 0
DB4 = 0
'Toggle the Enable line:
PULSOUT E, 100
pause PauseA
E = low

'Display cursor off, blink off
DB7 = 1
DB6 = 1
DB5 = 1
DB4 = 1
'Toggle the Enable line:
PULSOUT E, 100
pause PauseA
E = low

pause 10 ' wait 100us

'clear display

DB7 = 0
DB6 = 0
DB5 = 1
DB4 = 0
'Toggle the Enable line:
PULSOUT E, 100
pause PauseA
E = low

DB7 = 0
DB6 = 0
DB5 = 0
DB4 = 1
'Toggle the Enable line:
PULSOUT E, 100
pause PauseA
E = low

pause PauseC 'pause 2ms

'Entry mode

DB7 = 0
DB6 = 0
DB5 = 0
DB4 = 0
'Toggle the Enable line:
PULSOUT E, 100
pause PauseA
E = low

DB7 = 0
DB6 = 1
DB5 = 1
DB4 = 0
'Toggle the Enable line:
PULSOUT E, 100
pause PauseA
E = low

pause pauseC


loop:

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello
Pause 500 ' Wait .5 second

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "World"
Pause 500 ' Wait .5 second

Goto loop ' Do it forever




is this correct??

the dispaly does light up but thats it
here is a link to the displays pdf file
http://www.maplin.co.uk/Media/PDFs/N27AZ.pdf

Jhdgkss
- 18th March 2007, 10:10
hi there again i have been up all night trying to get this thing working no luck can some one please have a lok at my code or does anyone know where a example piece of code is. please iam desperate

jcleaver
- 18th March 2007, 15:50
not a expert but my problems has always been with using a higher speed osc
and not reseting lcd_dataus to match the crystal more delay for higher speeds just a thought

Jhdgkss
- 18th March 2007, 16:57
hi there iam not sure what you mean can you explane

jcleaver
- 18th March 2007, 17:12
when i have a problem with the lcd display
it has been the fact that i use a 20 osc
and what works for me is to change line

define lcd_dataus 50

to

define lcd_dataus 200

it just works for me

Jhdgkss
- 22nd March 2007, 17:50
hi there thanks for the reply.

how do you know your lcd is in working order, i have ready that if you just provide power to it you should see black boxes is this true. i tried this and all i get is the backlighting up but no boxes.

skimask
- 22nd March 2007, 18:03
Which compiler are you using? 'cause if that code above is PicBasicPro, you really, really need to get reading the PBP manual and learn it.

mister_e
- 22nd March 2007, 22:47
You don't have any Black boxes????

Or your contrast POT is crap, or you didn't installed it correctly.. or you forgot. ANY character LCD i know, once connected will produce those Black boxes.

R/W pin is left floating in the air... must be tied to gnd

Some LCD brand may need to tie unused DB<4:0> to Vss or Vdd... have a look to the datasheet

Archangel
- 23rd March 2007, 05:16
hi there thanks for the reply.

how do you know your lcd is in working order, i have ready that if you just provide power to it you should see black boxes is this true. i tried this and all i get is the backlighting up but no boxes.
Power to LCD - pin 1 ground, pin 2 is 5 volts positive, pin 3 center lug of contrast pot. these are the primary power leads, pin 4 R/s bit, pin 5 R/w and must be as mister_e said ground etc etc . . . now pin 15 Power for LED backlight, pin 16 LED backlight ground. Just because led backlight is on does not mean lcd is powered.