PDA

View Full Version : LCDOUT 4-bit data on 8-bit setting



breesy
- 24th June 2006, 06:32
Hey,

Im having trouble on a PIC16F88, as far as i can tell the code should be outputting the data on all eight pins of PORTB, but pins 4-7 are allways low, see the example below:

DEFINE OSC 8

Define LCD_DREG PORTB ' Port for LCD Data
Define LCD_DBIT 0 ' Starting Data bit (0 or 4) if 4-bit bus Use LOWER 4 bits of Port
Define LCD_RSREG PORTA ' Port for RegisterSelect (RS) bit
Define LCD_RSBIT 6 ' Port Pin for RS bit
Define LCD_EREG PORTA ' Port for Enable (E) bit
Define LCD_EBIT 7 ' Port Pin for E bit
Define LCB_BITS 8 ' Using 4-bit bus
Define LCD_LINES 4 ' Using 2 line Display
Define LCD_COMMANDUS 2000 ' Command Delay (uS)
Define LCD_DATAUS 200 ' Data Delay (uS)


init:
OSCCON = %01110000 '8 MHz Internal Oscillator
Pause 2000 'Safe Start Up Delay


CMCON = 7
ADCON1 = 7
ANSEL = %00000000
TRISA = %00000000
TRISB = %00000000
PORTA = %00000000
PORTB = %00000000

main:

LCDOUT %11111111
PAUSE 1000

goto main

end

Regards,
Daniel

keithdoxey
- 24th June 2006, 13:35
Define LCB_BITS 8 ' Using 4-bit bus

The comment doesnt match the parameter specified but the real problem is that you have typed LCB instead of LCD

Because you dont have a valid DEFINE it is using the default value which is for 4 bits.

Hope that helps

Keith

breesy
- 26th June 2006, 06:59
Thanks, that was it.. Its amazing how I could miss it after reading through the code so many times..

One more quick question, is it possible to clear a single line of an lcd display, or atleast fill it with blank characters?

paul borgmeier
- 26th June 2006, 07:47
or atleast fill it with blank characters?
Not efficient and code heavy but works – there must be a better way?

Line2Clr Var Byte
X var Line2Clr 'reuse variable with alias to save RAM

Line2Clr = 148 ' clear line 3 or 4x20 LCD (for example)
Gosub ClrLine

rest of program here

ClrLine: ' subroutine
LCDOUT $FE,Line2Clr,32,32 ' clear 148 and 149 with 32 (ascii blank)
FOR X = 0 to 8 ' clear rest of line
LCDOUT 32,32
NEXT X
RETURN

Paul Borgmeier
Salt Lake City, Utah
USA

keithdoxey
- 26th June 2006, 09:32
Thanks, that was it.. Its amazing how I could miss it after reading through the code so many times..

We have all been there and done that in one way or another :)


One more quick question, is it possible to clear a single line of an lcd display, or atleast fill it with blank characters?

This is how I do it. I have a variable called "line" that I use for specifying which line of the LCD I want to go to the beginning of, and then specify CONstants for Line1, Line2 etc

This is the sub that I use to clear the LCD (actually it fills it with spaces)



Line var byte ' Line of Display to act on
Line1 con $02 ' Home position
Line2 con $C0 ' Start of Line2

.......

Line = Line2
Gosub Blankline


.......

BlankLine: ' **** This clears the whole line of the display ****
LCDOut $FE, Line, REP " "\16 ' Send 16 spaces to clear the line
Return ' **** End of BlankLine ***


This could be extended further by changing the "16" to a variable name thereby giving the ability for a varying number of repeated characters.

You could go the whole hog and change it to LCDout $FE, Line,REP Char\Charcount
which would allow you to specify the Line, Character and number of characters to write to the display but I guess than you would have to call it something other than "Blankline" :)

paul borgmeier
- 26th June 2006, 14:40
BlankLine: ' **** This clears the whole line of the display ****
LCDOut $FE, Line, REP " "\16 ' Send 16 spaces to clear the line
Return ' **** End of BlankLine ***

Keith,
Nice and clean - sweet!

Paul

keithdoxey
- 26th June 2006, 18:39
Thanks Paul, but the only thing I can really take credit for is putting in a subroutine called "BlankLine". The syntax used is clearly shown on the LCDout page of the PBP manual :)