PDA

View Full Version : code for LCD-4x20 HD44780....HELP



Martin....
- 17th June 2006, 22:44
Hi

My English is not that good....Iīm from Germany...
Has anybody written a Code in Pic Basic to use an
LCD-Display 4x20 with the controller HD44780.
I would like to use the lcd command but itīs only available in the pro version.
Where can I get it? And how much is it? I build an roboter with Steppermotors and a display. Everything is working except the diplay.
Please post some Code.......I gonna try to understand it.
My pic is the 16f627 or 16f627A But the code just nedds to be in pic basic
I can change it for my pic if itīs not working.thx

Martin

BobK
- 18th June 2006, 03:26
Hi Martin,

About the only way I think you can get an LCD to work in PicBasic is to either get an assembly code routine OR get a serial LCD. With a serial LCd you simply use the SerOut command. A 4 line display isn't hard to use at all compared to a 2 line display. You simply set up the Constants for the other 2 lines and send the appropriate commands to the display.

As far as PicBasicPro, you can get the upgrade from MELabs, Rentron, or many other places that sell PICs and microcontroller items. Bruce from Rentron has an awesome web site with alot of valuable devices and how to use them. He even lists PBP and PBC code to help you get started.

It is worth the price for the upgrade.

BobK

BobK
- 18th June 2006, 14:43
Hi Martin,

It appears I gave you the wrong information in my previous post. Yes you can use a 4x20 LCD in PicBasic. Chuck Hellebyck's book "Programming PIC Microcontrollers in Basic" has several examples in Chapter 7. This book is available from Amazon.com or from Chuck's website www.elproducts.com.

Check it out.

BobK

Martin....
- 18th June 2006, 22:33
Is this book also online available? Itīs pretty expensive or has anybody copyed the code? I found a demo version of an pro compiler but it can only compile 30 lines. Does anybody know where i can get one for free.......bittorent or sth like that

Martin

SteveB
- 18th June 2006, 23:53
Here's sample code for the PICBASIC Compiler, including a LCD demo:
http://www.melabs.com/resources/samples.htm#pbc

Steve

sammy
- 23rd June 2006, 19:13
hi:
Parallax has a very good code example and aplication in their documentation. I have included a link for you and with a few modifications you can get this working very very well. Just look through the pdf and find the aplication note that shows the interface of a key pad and LCD.

http://www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf

If you have any question let me know as i did this once before switching to the pic basic pro.


latter


sam

Martin....
- 12th July 2006, 16:01
Sorry that i didnīt answer.....internet wansīt working
I read the pdf file but it was for 4 bit displays
I need some code for an LCD with 8 datapins ,
r/w and rs I couldnīt find any code for it.
Please help me thx.

Martin

Martin....
- 12th July 2006, 16:05
An assemblercode is ok, too I just need some code to know how it works

martin

BobK
- 12th July 2006, 16:35
Hi Martin,

Are you aware that most LCDs come with the ability to be used either way? (Referring to 4-bit vs 8-bit mode) How it gets used is in the programming. Using the 4-bit mode uses less pins on the micro. In my opinion, you never have enough pins available so I've been using the 4-bit mode. The compiler handles the overhead.

If you are using the LCD in the 4-bit mode then you ground pins DB0 thru DB3 and connect the other 4 pins DB4 thru DB7 to the 4 pins on the micro you will be using. Then all you have to do is connect the E line and the RS line and you ready to go. The setup for how many lines there on the display is in the configuration setup.
You can tie the R/W line to ground if you aern't going to do any custom displays. It's use to access the LCDs internal RAM.

Break down and buy Chuck's book. Believe me it will be more than worth it. There's sample programs for both PicBasic and PicBasic Pro to help you get started. I have invested in many books over the past few years. There has been only one book that I regretted and it cost $60.00 and I wrote a critique on Amazon.com about it being a big waste of money. Nothing is free in life and if you want to get a good education you will have to spend some money to get it. Not spending the money to learn only hinders what you want to do.

BobK

Martin....
- 13th July 2006, 17:00
Thank you for answering so fast i gonna try it nox.....thx
Martin

Martin....
- 17th July 2006, 22:44
I started to programm my own programm but itīs not working. i donīt know where my error in the Code is

Some Subdeclarations are only defined but not used yet like LCD_Clear...etc
Can anybody correct the code or tell me where the Error is.......Thx Martin

Here is the code:
' LCD PICmicro
' DB0 PortB.0
' DB1 PortB.1
' DB2 PortB.2
' DB3 PortB.3
' DB4 PortB.0
' DB5 PortB.1
' DB6 PortB.2
' DB7 PortB.3
' RS PortA.1
' RW Ground
' E PortB.3

' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)





Symbol PORTA = 5 'PortA is register 5
Symbol TRISA = $85 'PortA data direction is register hexadecimal 85
Symbol PORTB = 6 'PortB is register 5
Symbol TRISB = $86 'PortB data direction is register hexadecimal 86
Symbol Lcdrs = 1 'lcd rs line is Pin3
Symbol Lcdrw = 2 'lcd rw line is Pin3
Symbol Lcden = 3 'lcd enable line is Pin3
Symbol Pic_IN= 4 'From the other Pic
Symbol pulse = W1 'Pulse read
Symbol x = b2 'a variable for the for-next loop
Symbol y = b3
Symbol signal= b4 'the signal code from the Controller Pic




Init:
Poke TrisB, 0
Poke TrisA, %00001000 'Alles Ausgänge außer 4 (Signal_in von Controller-Pic)
Poke PortA, 0
Poke PortB, 0
GoSub LCD_Init
GoSub LCD_Clear
Pause 1000
GoSub LCD_Clear
GoTo Start

Start:
GoSub Read_Def_Var
GoSub LCD_Write
GoTo Start



Read_Def_Var:
PulsIn Pic_IN,0,pulse 'read the pulse length from the IR_IN pin
IF pulse < 220 OR pulse > 260 Then START 'if it's not a 2.4ms start bit (or pretty close to it) 'aha... it was a start bit, so now we record the next seven pulses to be sent
y=1
signal=0 'set the signal variable back to zero
For x = 1 TO 7
PulsIn Pic_IN,0,pulse
IF pulse >90 Then ADD_Y 'this bit is a "one", 'so set it
'a place 'to come back to
y=y*2
Next x
IF signal=1 Then LEFT_UP 'this is the SONY code for "number 2"
IF signal=2 Then RIGHT_UP ' "number 2"
'IF signal=3 Then LEFT ' "number 3"
'IF signal=4 Then RIGHT ' "number 4"
'IF signal=5 Then HALT ' "number 5"
Return


ADD_Y:
signal=signal+y
Return

LCD_Init:
Poke PortA, 0
Poke PortB, 0
Pause 15
Poke PortA, %00000110
Pause 20
Poke PortA, %00000010
Poke PortB, %00111000
Pause 15
Poke PortB, %00000000
Pause 2
Poke PortB, %00000111
Pause 1
Poke PortB, %00001110
Pause 1
Return


LCD_Clear:

Return

LCD_Write:

Return

BobK
- 18th July 2006, 12:03
Hi Martin,

Well I'm kind of rusty with PBC but I did notice something wrong in your setup here:

Here is the code:
' LCD PICmicro
' DB0 PortB.0
' DB1 PortB.1
' DB2 PortB.2
' DB3 PortB.3 <ONCE
' DB4 PortB.0
' DB5 PortB.1
' DB6 PortB.2
' DB7 PortB.3 <TWICE
' RS PortA.1
' RW Ground
' E PortB.3 <THIRD

AND

Symbol TRISB = $86 'PortB data direction is register hexadecimal 86
Symbol Lcdrs = 1 'lcd rs line is Pin3 <FORTH
Symbol Lcdrw = 2 'lcd rw line is Pin3 <FIFTH
Symbol Lcden = 3 'lcd enable line is Pin3 <SIXTH

You have 6 pins of the LCD all connected to PortB.3 (Pin3) according to your code. Go back to the LCD.BAS program that was pointed out to you a few posts back and look closely at the LCD connections. DB0 thru DB3 should all be tied to ground. You only need to use DB.4 thru DB.7 for the 4-bit data bus. RW also gets tied to ground. The control lines RS and E get connected each to their own port pins.

Copy and Paste the code from MELabs LCD.BAS, make the necessary pin assignment changes if needed THEN use this program to test your LCD setup as this program will display "HELLO WORLD" if all is working well. Once you have the LCD working, then proceed with adding in your program section by section. Trying to do the whole program and troubleshooting the whole thing can be one very big frustration point. Start with the basics and work your way up.

Have some fun and a nice day!

Martin....
- 20th July 2006, 14:31
ok thank you i gonna try the programm...
I gonna tell you if itīs working......

Martin

Martin....
- 24th July 2006, 23:31
The programm wasnīt working. I wrote my own programm with 8-bit
Itīs working...very well.....If anybody wants to see the code just write me an e-mail at [email protected] ....

Thank you all for your help
Martin