LCD on 18X questions...(4-bit mode)

Grogster

Senior Member
Hi all.
:)

I've built and programmed an 18X as an experiment, based on the PICAXE book("Programming and customizing the PICAXE microcontroller - David Lincoln), and once I sorted out the error in the program on pages 230 and 231("loop" used as a routine label, which the programmer quickly rejected with a: "loop without do" error - one of several errors or layout problems I have found in this book(what ever happened to revising a work before printing it...)), I have got the LCD showing the two programmed lines in the code - great. :)

Now, I am using a 4-row LCD(20x4), and although both lines are correctly aligned on the first two rows of the LCD, I was playing around with the code, and am trying to work out what byte I need to send to the LCD to make it shift to the 3rd and 4th lines.

Obviously, $80 is line1, and $C0 is line two, and this works, but what are the codes for lines 3 and 4?

The LCD manual that came with the module does not give this information, so I am hoping that someone can give me some hints that I can try out.

Cheers.
:)
 
Last edited:

BeanieBots

Moderator
Without a datasheet, the only way to find out is experiment.
Many LCD units have line lengths of 20 or 40 irrespective of how many characters are on the actual display.
I would simply keep throwing characters at it until they start to appear. If you did in blocks of say 10, then it won't take too long to get an approximate value which can be fine tuned later.

Some LCDs need the lower line(s) to be explicitly enabled. If sending a massive string of characters never appear on the lower lines, then you will have to research further and try to find a datasheet.
 
Last edited:

eclectic

Moderator
@grogster.
This might help.
I've just tried a 4 x 20, with serial firmware, using the following program;
Code:
 serout 0,n2400,(254,1)
pause 100

serout 0,n2400, (254,128,"128 line1") '$80

serout 0,n2400, (254,192,"192 line2") '$C0

serout 0,n2400, (254,148,"148 line3") '$94

serout 0,n2400, (254,212,"212 line4") '$D4
Worth a try, using $94 and $D4 ?

e
 

Attachments

westaust55

Moderator
The information eclectic gives is in line with my 4x20 LCD module.

Line 3 is a follow-on from Line 1 and Line 4 is a follow-on from Line 2.
Believe that is pretty much the norm - but there may be some variations.

If you just keep sending characters to the LCD it will fill the lines in the order:
line 1, line 3, line 2 and then line 4.

Edit: just looked at the link for the LCD in question and it is as described above. See page 9 of the datasheet.
 
Last edited:

hippy

Ex-Staff (retired)
Obviously, $80 is line1, and $C0 is line two, and this works, but what are the codes for lines 3 and 4?
That can depend on manufacturer and actual size of LCD being used. I've seen $A0/$E0, $90/$D0, and $94/$D4 is mentioned above.

Often the easist thing to do if the 'obvious guesses' do not work is to write a test program which works its way through the addresses one at a time while you sit there and note which characters get written to where.
 

Grogster

Senior Member
$94 and $D4 work perfectly.
:)

@ westaust55: I don't really understand the display map on page 9 of the instruction sheet.

It says that line 2 position 1 is 40h. I assume that the small h is just an indication that the number is in base-16, or HEX. 40 hex translates to 64 decimal, and this is not the 94 sent by the code. Subsequently, row 4 position one according to the datasheet is 54 HEX which is 84 decimal, yet the D4 sent for line 4 is 212 decimal.
:confused:

I think I am totally lost with respect to the conversions of units going on in this experiment, so could someone help me understand what is going on?

I normally only use base-10 for just about everything, but I well know that every computer on the planet since 8-bit use HEX to represent the decimal numbers up to 255, it's just I never needed to translate into it before I needed to write data to one of these LCD's!
:D
 
Last edited:

westaust55

Moderator
LCD display character addresses and base conversion

Yes you are correct, the “h’ indicates it is a hexadecimal number.

It would be worth learning the conversions.

Decimal numbers are to base 10 with the possible numbers 0 to 9 for each digit position. Decimal numbers do not have any prefix or suffix.

Binary numbers are to base 2 with the only possibilities being 0 and 1 for each digit location. Binary numbers use the percent (%) character as a prefix to indicate it is a binary number.
Hexadecimal numbers are to base 16 and use the digits/characters 0 to 9 and A to F, where A = 10 through to F = 15.
Hexadecimal numbers can use several formats including 0Xaa or $aa, aah, aaH or Haa where “aa” is a 2 character hexadecimal number.
In the PICAXE BASIC, the first two are used but other documentation may include the other formats.

The conversion between decimal hex and binary is in the following format:
Code:
 0 = $00 = %0000 0000
 1 = $01 = %0000 0001
 2 = $02 = %0000 0010
 3 = $03 = %0000 0011
 4 = $04 = %0000 0100
 5 = $05 = %0000 0101
 6 = $06 = %0000 0110
 7 = $07 = %0000 0111
 8 = $08 = %0000 1000
 9 = $09 = %0000 1001
10 = $0A = %0000 1010
11 = $0B = %0000 1011
12 = $0C = %0000 1100
13 = $0D = %0000 1101
14 = $0E = %0000 1110
15 = $0F = %0000 1111
16 = $10 = %0001 0000
17 = $11 = %0001 0001
18 = $12 = %0001 0010
:
:
32 = $20 = %0010 0000
40 = $28 = %0010 1000
64 = $40 = %0100 0000
65 = $41 = %0100 0001
:
:
128 = $80 = %1000 0000
:
:
255 = $FF = %1111 1111
As you can see from this table part table, the first (left most = most significant) 4 digits of the binary number always match up with the first hexadecimal digit and the least significant 4 binary digits always match up with the second hexadecimal digit.
 
Last edited:
Top