PDA

View Full Version : LCD cable length?



Art
- 16th January 2012, 00:46
Hi,
Just wondering if anyone has tried wiring an LCD (4 bit interface) remotely from the microcontroller, and how long the ribbon cable can be?
I know I could try this, but someone might have done it and could save me the hassle.
I want a ribbon cable from the back of my 4wd to the front of the vehicle.
Cheers, Art.

spcw1234
- 16th January 2012, 00:58
I have done it with a cat5 wire about 10' and had no problems.

ScaleRobotics
- 16th January 2012, 01:51
Here's Darrel with 25 feet of ribbon cable connected to his: http://www.picbasic.co.uk/forum/showthread.php?t=7596&p=47417#post47417

Edit: Wildbilly ran it with 40 feet. A few posts later.

Art
- 16th January 2012, 02:21
Thanks guys :)
Didn't want to do the wiring, but should have at least searched!

Art
- 18th January 2012, 02:39
It's a VFD display with the standard LCD controller.

http://img.photobucket.com/albums/v186/ArtArt/Vehicle_Comp.jpg

It's working with one metre of cable, but a bit hit & miss.
No garbled text, but sometimes it doesn't come on at all.
Maybe it just needed a longer startup time than the usual PAUSE 1000.
Ideally, I want about five metres of cable length, so I'll keep reading!

Darrel Taylor
- 18th January 2012, 06:39
In the thread where we ran them on 25/40ft cables, the LCDOUT library routines were over-ridden so the timing could be changed.

Normally, the LCDOUT command gives a 1uS pulse on the enable line.
But as the cable gets longer, 1uS isn't enough.
I used 5uS for the 25 ft length, which seemed to overcome the rounding off of the waveform on a scope.

You might try using the routines from that thread with the modified timing.
Essentially, it's the LCD_AnyPin routines with a few modifications.

Art
- 18th January 2012, 14:58
Will do, thanks :)
I think I'll have to.

Art
- 18th January 2012, 15:36
A little problem...
Installed the hijack routines and the two files in PBP directory.
When I use the include file for lcdanypin, I get an error (using MPASM)
for line 87 which is this line:
LOW LCD_RS : HIGH LCD_E

If I comment that out I then get a lot of errors

Darrel Taylor
- 18th January 2012, 18:31
LCD_RS and LCD_E should be declared in your program, along with the other LCD pins.
Something like ...

;----[ Change these to match your LCD ]---------------------------------------
LCD_DB4 VAR PORTA.0
LCD_DB5 VAR PORTB.3
LCD_DB6 VAR PORTB.7
LCD_DB7 VAR PORTC.1
LCD_RS VAR PORTD.4
LCD_E VAR PORTA.1
LCD_Lines CON 2 ' # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines)
LCD_DATAUS CON 50 ' Data delay time in us
LCD_COMMANDUS CON 2000 ' Command delay time in us
INCLUDE "LCD_AnyPin.pbp" ; *** Include MUST be AFTER LCD Pin assignments ****

Art
- 18th January 2012, 22:31
Oops! :)

Art
- 18th January 2012, 23:02
Bah! Still not having much luck here,
I have the LCD routines working, and changed the LCD_anypin file as follows:


;===============( DO NOT Change anything below this line )====================
;----[Virtual LCD Port --- 4bit mode]-----------------------------------------
ASM
LCD_Port_HNIB macro ; Port definition for LCD High Nibble
Vbit LCDCDFLAG, _LCD_RS ; Select Command/Data register
Vpin 4, _LCD_DB4 ; Put the High Nibble on the bus
Vpin 5, _LCD_DB5
Vpin 6, _LCD_DB6
Vpin 7, _LCD_DB7
PulseLow _LCD_E, 5 ; pulse the Enable Pin for 2 us
endm
;-----------------------
LCD_Port_LNIB macro ; Port definition for LCD Low Nibble
Vpin 0, _LCD_DB4 ; Put the Low Nibble on the bus
Vpin 1, _LCD_DB5
Vpin 2, _LCD_DB6
Vpin 3, _LCD_DB7
PulseLow _LCD_E, 5 ; pulse the Enable Pin for 2 us
endm
ENDASM


Since I'm only using a single display, hopefully that's all that is needed to enable the E pin for 5us.
Still the display coming on at all after startup is hit & miss.
It seems to come on straight after programming with the pickit2 (when powered by the pickit2,
but doesn't want to come on when powered by any other means (or even by the pickit2 when not being programmed).

Art
- 18th January 2012, 23:16
Seems the problem is hardware Darrel!

I wanted the pic to be able to switch on & off power to the LCD, so I used a BD649 transistor to switch the ground pin of the LCD display.

The base is connected via 2.2K resistor to a spare pic pin, collector to the LCD ground, and emitter connected to the circuit ground.
Then the idea was to set the pic pin connected to base high, and then wait the "PAUSE 1000" delay time for the LCD to be ready each time I used it.
If I now short the emitter and collector of the BD649 while powering up, the display works every time (with LCD_anypin).

I can then release the short between the transistor pins, and the display stays on! What's happening there?

It's probably become obvious it's for a car circuit.
The idea is to have the LCD (VFD) powered only when the car is started, but the pic circuit should be running all the time.

Darrel Taylor
- 19th January 2012, 00:02
Maybe ...

If the data/RS/E pins are not tri-stated while the power to the VFD is OFF, it could be trying to power it from those pins.
Then when the transistor turns on, it doesn't activate the power-on reset in the display.

When programming with the PICkit, those pins will always tri-state during programming.

Just turning off the transistor without tri-stating all the pins first may not be enough.
Then remember to clear the FLAGS variable, so PBP will re-initialize the display.

spcw1234
- 19th January 2012, 00:36
Probably not your problem, but I spent several hours trying to figure out why my one project would work fine after programming (using USB with a bootloader to program) but after a power cycle it wouldn't work. Program it again and it worked fine until I would do a power cycle again. Turns out when I programmed the bootloader into the PIC I had the extended instruction set enabled. Just a thought.

Art
- 19th January 2012, 01:20
Being the self-educated hack-git that I am, I don't know what either of those suggestions actually are.
BUT, being the self-educated hack-git that I am I figured out you can:
Defeat the 24hr Wikipedia blackout by hitting Ctrl-A followed by Ctrl-C
quickly before the blackout screen appears, then you can paste the entire page to Windows Notepad! :)

I tried to find out what tri state means... Do I need to use transistors to isolate all of the LCD control pins?
How do you reset the FLAGS var? it is an internal asm variable yes?
Will that ruin my program during execution if my own flags have critical states?

@ spcw1234, I'm not using a bootloader, just plain vanilla PBP hex loaded straight to the pic.

spcw1234
- 19th January 2012, 01:23
Disable java scripting on your browser to use Wikipedia. :)

http://meta.wikimedia.org/wiki/English_Wikipedia_SOPA_blackout/Technical_FAQ#Are_there_ways_to_circumvent_the_rea d_blackout.3F

Art
- 19th January 2012, 01:37
It "Appears" I've had some luck by inserting this code:


@ OutputPort LCD_Port_HNIB ; Set LCD bus to OUTPUT
LOW LCD_RS
HIGH LCD_E
Char = 3 : gosub LCDsendShortCOM : @ DelayUS 6000
gosub LCDsendShortCOM : @ DelayUS 1000
gosub LCDsendShortCOM : @ DelayUS 1000
Char = 2 : gosub LCDsendShortCOM : @ DelayUS 1000 ; Start 4-bit mode
Char = $28 : gosub LCDsendCOM ; Function Set, 4-bit, 2-line, 5x7
Char = $0C : gosub LCDsendCOM ; Display ON
Char = $01 : gosub LCDsendCOM ; Clear Screen
Char = $06 : gosub LCDsendCOM ; Entry Mode
LCD_Initialized = 1 ; LCD has been Initialized


after turning the transistor on.

This maybe just rubbish... I'll have to try to get the pic to turn the LCD off and back on again to be sure of anything.

Art
- 19th January 2012, 01:45
Ok, that IS working, I can use the pic to cycle the power to the VFD display ie. turn off, wait three secs,
turn on again and print. I will try to follow any other suggestions to clean it up.

Maybe the LCD controller is recieving power from other lines to keep it running... not sure.

Darrel Taylor
- 19th January 2012, 04:29
That initialization code is already in the LCD_AnyPin file.

To invoke it, simply use this after turning it on.

FLAGS = 0
That tells PBP that the LCD hasn't been initialized yet, and it will do so on the next LCDOUT.

Art
- 19th January 2012, 11:14
Seems you can ignore the last few posts.. I had the transistor shorted the whole time I was supposed to be turning it on & off!

Charlie
- 19th January 2012, 11:33
A quick thought - rather than try to run ribbon cable around a vehicle, where noise will certainly be an issue, why not simply put a small PIC co-located with the display to communicate with your main device using an (RS232ish) serial link and display it on your display? You only need to run a single wire (or 3 wires if you also want to include power for the device) and it should be cheaper and more robust. You won't need driver devices; simply connect the output pin you choose to use on your main PIC to the input pin you choose to use on the display driver PIC. I've done this for over 30 feet without issues.

Art
- 19th January 2012, 15:42
Couple of reasons, but most importantly, to keep the program cycling fast.
A hardware serial port might overcome the speed issue,
But would make it more difficult to do fancy things with the display.

Art
- 21st January 2012, 01:53
Problem Solved!!!

Here's the current circuit I was describing with the LCD data bus obviously omitted:

http://img.photobucket.com/albums/v186/ArtArt/pwr_LCD_pic.jpg

It does drive a 12 Volt relay this way if the other end of the relay coil is connected to a 12 Volt source.



.................................................. ...............................


I used the same transistor to switch the positive line to the LCD this way:

http://img.photobucket.com/albums/v186/ArtArt/pwr_LCDx_pic.jpg

I could always use the first circuit to drive a relay that in turn switches the LCD,
but that wouldn't be very solid state would it? :D

Q for Darrel, Does resetting the FLAGS var affect any other PBP related stuff?
I have my own flags set and variables stored in RAM while I'm turning the VFD on & off.
It's working perfectly, but I don't want it to break anything else software-wise.
Cheers, Brek.

Darrel Taylor
- 21st January 2012, 02:14
Clearing the FLAGS variable will not affect anything else.
There are some I2C bits in there, but they are only used during an I2CREAD/I2CWRITE command.

The only time it could be bad is from within an interrupt handler, since an I2C command may have been interrupted.

Art
- 21st January 2012, 02:21
Great, no plans for I2C for this project :) Thanks for all your help too.

Oh, and before I forget.... This:
http://www.youtube.com/watch?v=lpduqsea5Kk
For old time sake!!

Still waiting for a sine wave version in that old odometer thread.
I used a pseudo sine lookup table to get the next vertical offset when I did it on my LED scroller.


LOOKUP si,[0,0,1,1,2,2,2,3,3,4,4,3,3,2,2,2,1,1,0,0],offset

Anyways, the rolling clock gets to stay :) it isn't blocking execution.

Darrel Taylor
- 21st January 2012, 03:46
Cool, I'm glad the odometer display got some use.

I tried the wavey one, but never did figure out a good way to do it.

Art
- 21st January 2012, 06:58
Tried it, it looked silly.
You just add something like this:


LOOKUP si,[0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,6,5,5,5, 4,4,4,3,3,3,2,2,2,1,1,1,0,0,0],offset'
si = si + 1
IF si = 41 THEN si = 0

before you lookup the eeprom address where the character tables are on eeprom.
add offset to the address you're reading from. Not worth it for LCD though I think.

Art
- 14th February 2012, 15:35
Greater than 5 metres of 10 conductor shielded computer cable wired across
a dashboard, to a compartment in the back of a large vehicle :)