When using an LCD from output pin0

Jon_

Member
I am using an LCD from output pin0 but i can't figure out what is wrong with the code. I am using the default code given in the picaxe manual but i have changed the pin numbers to correspond to correct pins when starting from 0.

However, something tells me that i need to change the masking as well as the pins are no longer the same, am i right in thinking this?

Code:
#picaxe 40x1

EEPROM 0, ("Test1 Master") ' 0 to 11
EEPROM 12, ("Test Screen") ' 12 to 22

symbol MEM_1ST_START = 0
symbol MEM_1ST_END   = 11
symbol MEM_2ND_START = 12
symbol MEM_2ND_END   = 22


gosub init

let b1 = 1        'set b1 to ‘clear display’ instruction
gosub wrins       'send instruction to LCD

for b3 = MEM_1ST_START to MEM_1ST_END  'setup a for...next loop
read b3, b1       'read letter from EEPROM into variable b1
gosub wrchr       'send character to LCD
next b3           'next loop
let b1 = 12       'set b1 to ‘hide cursor’ instruction
gosub wrins       'send instruction to LCD

let b1 = 192
gosub wrins

for b3 = MEM_2ND_START to MEM_2ND_END  'setup a for...next loop
read b3, b1       'read letter from EEPROM into variable b1
gosub wrchr       'send character to LCD
next b3           'next loop
let b1 = 12       'set b1 to ‘hide cursor’ instruction
gosub wrins       'send instruction to LCD



CLRserPTR:
	HSerPtr = 0                 'Reset (background) write pointer
	HSerInFlag = 0              'Reset reception indicator
	Ptr = 0                     'Reset read pointer
	@Ptr = 0                    'Clear the first scratchpad location
return

CLRscratchpad:
	for b0=0 to 127
		put b0,0
	next
return


init: 
let pins = 0   'Clear all output lines                  RS = 0
let b3 = 0     'Reset variable b3                       EN = 1
pause 200      'Wait 200 ms for LCD to reset.           D4 = 5
let pins = 48  'Set to 8-bit operation.                 D5 = 4
pulsout 1,1    'Send data by pulsing ‘enable’           D6 = 3
pause 10       'Wait 10 ms                              D7 = 2
pulsout 1,1    'Send data again
pulsout 1,1    'Send data again
let pins = 32  'Set to 4-bit operation.
pulsout 1,1    'Send data.
pulsout 1,1    'Send data again.
let pins = 128 'Set to two line operation
pulsout 1,1    'Send data.
let b1 = 14    'Screen on, cursor on instruction
gosub wrins    'Write instruction to LCD
return

wrchr:
let pins = b1 & 240 'Mask the high nibble of b1 into b2.
high 0              'Make sure RS is high
pulsout 1,1         'Pulse the enable pin to send data.
let b2 = b1 * 16    'Put low nibble of b1 into b2.
let pins = b2 & 240 'Mask the high nibble of b2
high 0              'Make sure RS is high
pulsout 3,1         'Pulse enable pin to send data.
return

wrins:
let pins = b1 & 240 'Mask the high nibble of b1 into b2.
pulsout 1,1         'Pulse the enable pin to send data.
let b2 = b1 * 16    'Put low nibble of b1 into b2.
let pins = b2 & 240 'Mask the high nibble of b2
pulsout 1,1         'Pulse enable pin to send data.
high 0              'Back to character mode
return
any help would be much appreciated as i cannot say i fully understand how LCDs work!
 

hippy

Ex-Staff (retired)
Yes, your masking is all screwed-up. You need to put the nibble data out on the pins used for D4-D7.

You also seem to have put D7(msb) to D4(lsb) on Pin 2 (lsb) through pin 5(msb) which will prevent a simple mask and shift/divide/multiply.

Assuming you reverse that ...

let pins = b1 & 240 becomes let pins = b1 & 240 / 4
let pins = b2 & 240 becomes let pins = b2 & 240 / 4

All other let pins = xxx become let pins = xxx / 4
 
Last edited:

Jon_

Member
You also seem to have put D7(msb) to D4(lsb) on Pin 2 (lsb) through pin 5(msb) which will prevent a simple mask and shift/divide/multiply.
I am not sure i know what you mean, in the picaxe manual the it shows:

RS = 2
SE = 3
DB7 = 4
DB6 = 5
DB5 = 6
DB4 = 7

All i have done is made that:

RS = 0
SE = 1
DB7 = 2
DB6 = 3
DB5 = 4
DB4 = 5

thanks for the help
 

hippy

Ex-Staff (retired)
There was some ambiguous information with some of the older PDF documents.

With the latest PICAXE Manual 3 ( Version 4.4 12/2010 ) the details on page 36 are correct for the example code and most other LCD code is written to conform to this wiring -

Pin 7 -> DB7
Pin 6 -> DB6
Pin 5 -> DB5
Pin 4 -> DB4
Pin 3 -> E
Pin 2 -> RS
 

Jon_

Member
oh ok, i have change over the wires but this is what i get:

Vw2Fwg
Vw%gf

I have checked my circuit again and again so i am hoping this is a software problem...
 

hippy

Ex-Staff (retired)
Did you also change the software as noted in post #2 ?

It may be best if you post a full circuit diagram and program listing.

Added : Better still ... get the LCD working as it would be wired in post #4, and then we can move on from there. If that doesn't work then it will be even harder working out what's wrong with more potential unknowns thrown into the mix.
 
Last edited:

Jon_

Member
I have attached my current circuit diagram, sorry about being pdf but the image is too big to upload unless i shrink it so much it is unreadable.

the code i am using is:

Code:
#picaxe 40x1

EEPROM 0, ("Test1 Master") ' 0 to 11
EEPROM 12, ("Test Screen") ' 12 to 22

symbol MEM_1ST_START = 0
symbol MEM_1ST_END   = 11
symbol MEM_2ND_START = 12
symbol MEM_2ND_END   = 22


gosub init

let b1 = 1        'set b1 to ‘clear display’ instruction
gosub wrins       'send instruction to LCD

for b3 = MEM_1ST_START to MEM_1ST_END  'setup a for...next loop
read b3, b1       'read letter from EEPROM into variable b1
gosub wrchr       'send character to LCD
next b3           'next loop
let b1 = 12       'set b1 to ‘hide cursor’ instruction
gosub wrins       'send instruction to LCD

let b1 = 192
gosub wrins

for b3 = MEM_2ND_START to MEM_2ND_END  'setup a for...next loop
read b3, b1       'read letter from EEPROM into variable b1
gosub wrchr       'send character to LCD
next b3           'next loop
let b1 = 12       'set b1 to ‘hide cursor’ instruction
gosub wrins       'send instruction to LCD

end

CLRserPTR:
	HSerPtr = 0                 'Reset (background) write pointer
	HSerInFlag = 0              'Reset reception indicator
	Ptr = 0                     'Reset read pointer
	@Ptr = 0                    'Clear the first scratchpad location
return

CLRscratchpad:
	for b0=0 to 127
		put b0,0
	next
return


init: 
let pins = 0   'Clear all output lines                  RS = 0
let b3 = 0     'Reset variable b3                       EN = 1
pause 200      'Wait 200 ms for LCD to reset.           D4 = 2
let pins = 48 /4 'Set to 8-bit operation.              D5 = 3
pulsout 1,1    'Send data by pulsing ‘enable’           D6 = 4
pause 10       'Wait 10 ms                              D7 = 5
pulsout 1,1    'Send data again
pulsout 1,1    'Send data again
let pins = 32 /4'Set to 4-bit operation.
pulsout 1,1    'Send data.
pulsout 1,1    'Send data again.
let pins = 128 /4'Set to two line operation
pulsout 1,1    'Send data.
let b1 = 14    'Screen on, cursor on instruction
gosub wrins    'Write instruction to LCD
return

wrchr:
let pins = b1 & 240 /4  'Mask the high nibble of b1 into b2.
high 0              'Make sure RS is high
pulsout 1,1         'Pulse the enable pin to send data.
let b2 = b1 * 16    'Put low nibble of b1 into b2.
let pins = b2 & 240 /4 'Mask the high nibble of b2
high 0              'Make sure RS is high
pulsout 3,1         'Pulse enable pin to send data.
return

wrins:
let pins = b1 & 240 /4 'Mask the high nibble of b1 into b2.
pulsout 1,1         'Pulse the enable pin to send data.
let b2 = b1 * 16    'Put low nibble of b1 into b2.
let pins = b2 & 240  /4'Mask the high nibble of b2
pulsout 1,1         'Pulse enable pin to send data.
high 0              'Back to character mode
return
The lcd works if wired like so :
RS = 2
SE = 3
DB7 = 4
DB6 = 5
DB5 = 6
DB4 = 7

using the default picaxe example code.
 

Attachments

hippy

Ex-Staff (retired)
The lcd works if wired like so :
RS = 2
SE = 3
DB7 = 4
DB6 = 5
DB5 = 6
DB4 = 7

using the default picaxe example code.
That's great, though I'm not sure that the LCD is wired that way because it shouldn't work if it is !

Anyway, to get to what you want I'd take that wiring and example code which works and change one thing at a time, checking it still works after each change - Move RS from pin 2 to pin 0 and modify the software, move E from pin 3 to pin 1 and modify the software, finally move pin 4-7 to pin 2-5 and modify the software. Keep a note of what was done and which lines of code changed in each step, from what to what.

If a step fails, undo what was done, check it still works. If any step doesn't work then all that will give a good indication of where to look for things which hadn't been considered and things to double-check.
 
Last edited:

westaust55

Moderator
The schematic shows:

The lcd works if wired like so :
RS = output 0
SE = output 1
DB4 = output 2
DB5 = output 3
DB6 = output 4
DB7 = output 5

going cross eyed trying to trace lines with so many cross overs.

So confusion between schematic and stated connections


@ Jon,
what stops you from connecting the LCD as per the manual
and move the Cat-5 link to lower pin numbers ???
 
Last edited:

SAborn

Senior Member
I agree with westie that you start from pin0 but i always start DB4 at pin0 and work upwards from there.

Reason being is when you call a......Let Pins =......... it sets a binary code to the pins starting at pin0, so only make sense to use DB4 to pin0, DB5 to pin1 etc, as the SE and RS pins can be anything in program as they are addressed outside the ....let pins =.... command.
 

Jon_

Member
what stops you from connecting the LCD as per the manual and move the Cat-5 link to lower pin numbers ???
The board has been made for one thing, however, it is possible to change the pins to start D4 at 0 and put RS and SE in pins 4 & 5, would that make programming it alot easier?

Unfortunately, i am having problems getting the LCD to work on my original setup as some of the wires have fractured and i can't replace them due to my soldering iron being dead
 

hippy

Ex-Staff (retired)
The board has been made for one thing, however, it is possible to change the pins to start D4 at 0 and put RS and SE in pins 4 & 5, would that make programming it alot easier?
It won't really make a lot of difference; the order of signals for the Dx data bus is what's important, whether on 0-3, 2-5 or 4-7. On 0-3 or 4-7 is optimal but the software can be made to work with any arbitrary ordering. Most important is to get to the bottom and resolve the confusion of what the pin to LCD wiring is.

It should normally be ...

Pin 4 -> DB4
Pin 5 -> DB5
Pin 6 -> DB6
Pin 7 -> DB7

But you say that this is what works ...

Pin 4 -> DB7
Pin 5 -> DB6
Pin 6 -> DB5
Pin 7 -> DB4

There's something odd there, but let's accept that's what you see and that this is 'right for you'. If you then move those down to pin 2-5 you should have the same order ...

Pin 2 -> DB7
Pin 3 -> DB6
Pin 4 -> DB5
Pin 5 -> DB4

However, looking at your .PDF circuit you're actually using ...

Pin 2 -> DB4
Pin 3 -> DB5
Pin 4 -> DB6
Pin 5 -> DB7

The confusion, regardless of how the pins are or would normally be named, is in your moving them all down two pins, which also involves a reversal from what worked on 4-7 to what you want to use on 2-5 which should not be there.

The issue is clouded by the pin to LCD connection naming not being as it would normally be used but reversed, but that is just cloud, not really important. Though it's hard to see through it, hence why the actual flaw wasn't spotted earlier.

Fix that reversal and the code ( with the /4 in ) should work. Luckily it seems your LCD is connected by flying wires which can be swapped around so this should be easy but the moral of the story is prototype and test before committing to a PCB design.
 

Jon_

Member
I would just like to follow up this thread for any others reading that hippy is right, of course ;-)

The reason why i had difficulties was due to a number of reasons which i won't go into, so follow hippy's advice and it works!!
 
Top