If you need assistance, please send an email to forum at 4hv dot org. To ensure your email is not marked as spam, please include the phrase "4hv help" in the subject line. You can also find assistance via IRC, at irc.shadowworld.net, room #hvcomm.
Support 4hv.org!
Donate:
4hv.org is hosted on a dedicated server. Unfortunately, this server costs and we rely on the help of site members to keep 4hv.org running. Please consider donating. We will place your name on the thanks list and you'll be helping to keep 4hv.org alive and free for everyone. Members whose names appear in red bold have donated recently. Green bold denotes those who have recently donated to keep the server carbon neutral.
Special Thanks To:
Aaron Holmes
Aaron Wheeler
Adam Horden
Alan Scrimgeour
Andre
Andrew Haynes
Anonymous000
asabase
Austin Weil
barney
Barry
Bert Hickman
Bill Kukowski
Blitzorn
Brandon Paradelas
Bruce Bowling
BubeeMike
Byong Park
Cesiumsponge
Chris F.
Chris Hooper
Corey Worthington
Derek Woodroffe
Dalus
Dan Strother
Daniel Davis
Daniel Uhrenholt
datasheetarchive
Dave Billington
Dave Marshall
David F.
Dennis Rogers
drelectrix
Dr. John Gudenas
Dr. Spark
E.TexasTesla
eastvoltresearch
Eirik Taylor
Erik Dyakov
Erlend^SE
Finn Hammer
Firebug24k
GalliumMan
Gary Peterson
George Slade
GhostNull
Gordon Mcknight
Graham Armitage
Grant
GreySoul
Henry H
IamSmooth
In memory of Leo Powning
Jacob Cash
James Howells
James Pawson
Jeff Greenfield
Jeff Thomas
Jesse Frost
Jim Mitchell
jlr134
Joe Mastroianni
John Forcina
John Oberg
John Willcutt
Jon Newcomb
klugesmith
Leslie Wright
Lutz Hoffman
Mads Barnkob
Martin King
Mats Karlsson
Matt Gibson
Matthew Guidry
mbd
Michael D'Angelo
Mikkel
mileswaldron
mister_rf
Neil Foster
Nick de Smith
Nick Soroka
nicklenorp
Nik
Norman Stanley
Patrick Coleman
Paul Brodie
Paul Jordan
Paul Montgomery
Ped
Peter Krogen
Peter Terren
PhilGood
Richard Feldman
Robert Bush
Royce Bailey
Scott Fusare
Scott Newman
smiffy
Stella
Steven Busic
Steve Conner
Steve Jones
Steve Ward
Sulaiman
Thomas Coyle
Thomas A. Wallace
Thomas W
Timo
Torch
Ulf Jonsson
vasil
Vaxian
vladi mazzilli
wastehl
Weston
William Kim
William N.
William Stehl
Wesley Venis
The aforementioned have contributed financially to the continuing triumph of 4hv.org. They are deserving of my most heartfelt thanks.
Registered Member #295
Joined: Tue Mar 07 2006, 06:59PM
Location:
Posts: 23
I recently aquired a 4X20 character LCD and i have been pulling my hair out trying to get the thing to work. i have plenty of experience with low level programming, and PICs, but i just can't seem to get the LCD initialized. perhapes someone more experienced in matters of this type may be able to help. i'll breifly outline exactly what i have done upto this point.
- connected LCD module and backlight to power, both turn on - programmed a pic with the following simple program intended to simply display a flashing cursor
- when powered up the backlight turns on, and i can adjust the constrast of the LCD display from black to zero, but there is no flashing cursor to be seen. - PortB of the pic is connected to the data bus of the LCD, and bits on PortA corresponding the resigter select, and read/write and connected correctly as well. - the PIC is of course powered, and it MCLR line held high.
any help remedying this problem is greatly appreciated
Registered Member #103
Joined: Thu Feb 09 2006, 08:16PM
Location: Derby, UK
Posts: 845
I would say you probably haven't got long enough delays in. Those character modules are quite slow to respond I find.
A problem I had once was caused by the oscillator not starting up quickly enough. On power up, the PIC would skip through the LCD initialization routine way too quick for the module, before the oscillator settled down, and the PIC began running properly.
Banned Registered Member #110
Joined: Fri Feb 10 2006, 12:23AM
Location: Banned City
Posts: 85
[size] I admire the effort. As for pulling your hair out, even the veterans run through a hundred compiles before it works.
Yes, LOOPY does not end. Calls to X_MS_DELAY is 320 milliseconds rather than 250, which can cause problems later. Too much going on with the X_MS_DELAY sub. If you can, keep it in one spot.
There is no need to load PORTA AND PORTB with 0's then in next line clear these bits: BCF PORTA, RW BCF PORTA, RS
Use B'xxxxxxxx' with all 8 bits, otherwise any bits not included are defaulted to 0. MOVLW B'00000' = MOVLW B'00000000'
The delay sub MS_DELAY always generates a 1280 microsecond delay because decrementing W decrements 255 times. W is initially set to 0x00 because it is defined as W EQU H'0000' in the include file. The first loop lowers that H'00' to H'FF' forcing the DELAYLOOP to be repeated 254 more times regardless what MOVLW D'xxx' is set to. DECFSZ W does not decrement the PIC's working register unless you do this DECFSZ W, 0 which would repeatedly dump H'00' in to the true working register for eternity. W is meant to be used as a Destination flag in compliment with F.
No harm in generating a full 1 millisecond delay to toggle the ENABLE line. However, since the ENABLE lines does not need that much time, needs only 10 micro seconds during pulse and after, this excess delay will cause timing issues later or at least make LCD writing extremelly slow.
BSF PORTA, ENABLE
CALL MS_DELAY
BCF PORTA, ENABLE
There is not point to reading from the LCD at the moment, therefore just tie the R/W LCD line to ground for write mode. That frees up a PIC i/o line and coding complications. If you do not have a scope, do all you can to get one, a digital one. [/size]
it is my understanding the "nop" and "decfsz" execute in a single cycle (assuming the location w is != 0) and "goto delay loop" executes in 2 cycles. adding all of these up it would seem that the "delayloop" part of the above function should execute for 255 * 1uS, which yields 1020 microseconds (pretty close to 1mS). i'm not questioning your response, but i would like to know where my logic is flawed for future reference.
Registered Member #27
Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
What he really is trying to say is that your delay function does something completely different than you imagine.
"DECFSZ W" Will decrement address 0 because W is a special variable defined by the include file and is defined to be 0. Look in the datasheet for a little surprise to see what you really are decrementing.
To get your milisecond delay (at 4 MHz) you need to:
MS_DELAY
MOVLW D'249' ;Subtract one because the call and return takes two cycles each
MOVWF DELAYCOUNT ;You must move the count into a file, DECFSZ does not work on the W register.
DELAYLOOP
NOP
DECFSZ DELAYCOUNT
GOTO DELAYLOOP ;This takes two clock cycles so remove one nop
RETURN
That should amount to a total of 1001 µs unless I counted wrong.
Registered Member #27
Joined: Fri Feb 03 2006, 02:20AM
Location: Hyperborea
Posts: 2058
There are two problems. Since W is defined to be 0 it points to the INDF register. It in turn points to an address contained in the FSR register. The FSR register has an undefined content at startup. So it may by luck be pointing to free RAM. Since it is undefined it may change at power up and/or behave differently in different models.
The other detail is that after the last DECFSZ W the content of the file will be 0 so it will loop 256 times and not 255.
If FSR=0 the Microchip simulator says that INDF will always return 0. It has been known to return the wrong result in some odd cases so it might possibly behave different in hardware.
Registered Member #30
Joined: Fri Feb 03 2006, 10:52AM
Location: Glasgow, Scotland
Posts: 6706
Bjorn is right. The decfsz instruction is only meant to be used on file registers. If you use it on the W register, it won't work. Look at the instruction set summary for a description of how it works.
Bjorn's reply made me finally realise why "W" is defined as zero in the include file. I guess it's for when you use it as an option bit with the decfsz, decf, incf, comf, etc. instructions. incf register,W gets preprocessed by the assembler into incf <address>,0
PICs have lots of fun quirks like this. But we put up with them because they're cheap and easy to buy
Registered Member #295
Joined: Tue Mar 07 2006, 06:59PM
Location:
Posts: 23
EDIT: well, my progress has halted once again, i have been able to partially initialize the LCD (as far as i can tell) i can get it to display the flashing cursor by simply sending the "turn LCD on, turn cursor on, blink cursor" instruction. but if i send the "8-bit interface instruction" or the "cursor increment direction" instrucion the cursor is not displayed. in addition i am completely unable to display characters on the LCD.
Once again, i appologize for using you guys like spellcheckers, but honestly i have been compiling/fiddling with this for hours on end and am getting no where on my own.
This site is powered by e107, which is released under the GNU GPL License. All work on this site, except where otherwise noted, is licensed under a Creative Commons Attribution-ShareAlike 2.5 License. By submitting any information to this site, you agree that anything submitted will be so licensed. Please read our Disclaimer and Policies page for information on your rights and responsibilities regarding this site.