Amson SD1602H 16x2 LCD Compatible With PicAxe?

Mad Professor

Senior Member
Good Day All.

I was just wondering if anyone could tell me if the Amson SD1602H 16x2 LCD would be compatible with PicAxe.

It has the normal 16 pin interface.

Pin 1 - Vss (Supply Ground).
Pin 2 - Vdd (Supply Voltage).
Pin 3 - Vo (Contrast Adjust).
Pin 4 - Rs (Register Select).
Pin 5 - R/W (Read/Write).
Pin 6 - E (Enable Signal).
Pin 7 - DB0 (Data Bit 0).
Pin 8 - DB1 (Data Bit 1).
Pin 9 - DB2 (Data Bit 2).
Pin 10 - DB3 (Data Bit 3).
Pin 11 - DB4 (Data Bit 4).
Pin 12 - DB5 (Data Bit 5).
Pin 13 - DB6 (Data Bit 6).
Pin 14 - DB7 (Data Bit 7).
Pin 15 - A (Back Light Voltage).
Pin 16 - K (Black Light Ground).



Amson SD1602H Datasheet

Thanks for your time.
 

SilentScreamer

Senior Member
Its compatible, look at this manual 3 page 34 (link at the top of the forum)

I personally would suggest this chip as it has worked very well for me, it connects via serial so all you need is:
Code:
serout 1,T2400,(“Hello”)
 

Mad Professor

Senior Member
SilentScreamer: Thanks for that link, I will look into getting one of them Serial LCD Firmware Chips.

At this point in time for testing only I have connected the LCD directly to my 18X chip, I have just been looking at the manuals for a sample code to test.

Code:
EEPROM 0,("Hellothere!")	‘ store the text in the EEPROM memory

gosub init				‘ initialise LCD

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

for b3 = 0 to 4			‘ setup for...next loop ("Hello" - positions 0 to 4)
read b3, b1				‘ read letter from EEPROM into variable b1
gosub wrchr				‘ send character to LCD

next b3				‘ next loop
let b1 = 192			‘ set b1 to ‘start of second line’ position
gosub wrins				‘ send instruction to LCD

for b3 = 5 to 11			‘ setup for...next loop ("there!"-positions 5 to 11)
read b3, b1				‘ read letter from EEPROM memory into variable b1
gosub wrchr				‘ send character

init:
let pins = 0			‘ Clear all output lines
let b4 = 0				‘ Reset variable b3
let dirs = 252			‘ Set pins 2-7 as output lines (Stamp only).
pause 200				‘ Wait 200 ms for LCD to reset.
let pins = 48			‘ Set to 8-bit operation.
pulsout 3,1				‘ Send data by pulsing ‘enable’
pause 10				‘ Wait 10 ms
pulsout 3,1				‘ Send data again
pulsout 3,1				‘ Send data again
let pins = 32			‘ Set to 4-bit operation.
pulsout 3,1				‘ Send data.
pulsout 3,1				‘ Send data again.
let pins = 128			‘ Set to two line operation
pulsout 3,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 2				‘ Make sure RS is high
pulsout 3,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 2				‘ 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 3,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 3,1				‘ Pulse enable pin to send data.
high 2				‘ Back to character mode
return
It does not like line 24 & 17

Line24: let dirs = 252 ‘ Set pins 2-7 as output lines (Stamp only).

Line 17: for b3 = 5 to 11 ‘ setup for...next loop ("there!"-positions 5 to 11)

Could someone please re-adjust this code for my 18x?

Thanks.
 

SilentScreamer

Senior Member
After a quick look I think I know the problem.

"let dirs" is only needed on chips which can have there pins reconfigured as inputs and outputs. So it can only be used on a 08/08M/14M/28X1/28X2/40X1/40X2. The pins on a 18X are fixed as to being inputs or outputs. Look at page 102 in manual 2 at the top of the forum.

"for" requires a "next" after it so in your case:

Code:
for b3 = 5 to 11			'setup for...next loop ("there!"-positions 5 to 11)
read b3, b1				'read letter from EEPROM memory into variable b1
next
Once again look at page 45 of manual 2 at the top of this page.

So this is overall corrected code I think.

Code:
EEPROM 0,("Hellothere!")	'store the text in the EEPROM memory

gosub init				'initialise LCD

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

for b3 = 0 to 4			'setup for...next loop ("Hello" - positions 0 to 4)
read b3, b1				'read letter from EEPROM into variable b1
gosub wrchr				'send character to LCD

next b3				'next loop
let b1 = 192			'set b1 to ‘start of second line’ position
gosub wrins				'send instruction to LCD

for b3 = 5 to 11			'setup for...next loop ("there!"-positions 5 to 11)
read b3, b1				'read letter from EEPROM memory into variable b1
next
gosub wrchr				'send character

init:
let pins = 0			'Clear all output lines
let b4 = 0				'Reset variable b3
pause 200				'Wait 200 ms for LCD to reset.
let pins = 48			'Set to 8-bit operation.
pulsout 3,1				'Send data by pulsing ‘enable’
pause 10				'Wait 10 ms
pulsout 3,1				'Send data again
pulsout 3,1				'Send data again
let pins = 32			'Set to 4-bit operation.
pulsout 3,1				'Send data.
pulsout 3,1				'Send data again.
let pins = 128			'Set to two line operation
pulsout 3,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 2				'Make sure RS is high
pulsout 3,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 2				'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 3,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 3,1				'Pulse enable pin to send data.
high 2				'Back to character mode
return
 

Mad Professor

Senior Member
SilentScreamer: Thanks again for your reply and time.

I must admit that this code is above my understanding, but thats all apart of learning.

I have programed the edited code to my 18x, but no text is displayed, when the unit is powered up the bottom row on the lcd is darker then the top.

I ran the edited code in Simulation mode, it runs but after a few seconds it stops at line 38 (return) with an error: Stack error - return without gosub!

Thanks again for your time.
 

MPep

Senior Member
The reason it stops/errors is that after the just before the "init:" sudroutine, you need a "goto Main" or "end" or something.

What currently happens is that once the program reaches "gosub wrchr" (just before the 'init:"), and returns from the WRCHR subroutine it will carry on through the INIT: in a downward fashion.

You need to find a way to stop the program in its tracks.:D. Once it gets into the subroutines, they all end with a RETURN but there is nothing to return to!
 

SilentScreamer

Senior Member
Simple to fix, use goto instead of return/gosub

Code:
EEPROM 0,("Hellothere!")	‘ store the text in the EEPROM memory

goto init				‘ initialise LCD

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

for b3 = 0 to 4			‘ setup for...next loop ("Hello" - positions 0 to 4)
read b3, b1				‘ read letter from EEPROM into variable b1
gosub wrchr				‘ send character to LCD

next b3				‘ next loop
let b1 = 192			‘ set b1 to ‘start of second line’ position
gosub wrins				‘ send instruction to LCD

for b3 = 5 to 11			‘ setup for...next loop ("there!"-positions 5 to 11)
read b3, b1				‘ read letter from EEPROM memory into variable b1
gosub wrchr				‘ send character

init:
let pins = 0			‘ Clear all output lines
let b4 = 0				‘ Reset variable b3
let dirs = 252			‘ Set pins 2-7 as output lines (Stamp only).
pause 200				‘ Wait 200 ms for LCD to reset.
let pins = 48			‘ Set to 8-bit operation.
pulsout 3,1				‘ Send data by pulsing ‘enable’
pause 10				‘ Wait 10 ms
pulsout 3,1				‘ Send data again
pulsout 3,1				‘ Send data again
let pins = 32			‘ Set to 4-bit operation.
pulsout 3,1				‘ Send data.
pulsout 3,1				‘ Send data again.
let pins = 128			‘ Set to two line operation
pulsout 3,1				‘ Send data.
let b1 = 14				‘ Screen on, cursor on instruction
gosub wrins				‘ Write instruction to LCD
goto main

wrchr:
let pins = b1 & 240		‘ Mask the high nibble of b1 into b2.
high 2				‘ Make sure RS is high
pulsout 3,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 2				‘ 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 3,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 3,1				‘ Pulse enable pin to send data.
high 2				‘ Back to character mode
return
 

kym

Member
First , Remove this Line , Not really sure why this is still in the manual ?

let dirs = 252 ‘ Set pins 2-7 as output lines (Stamp only).
Secondly this line should be b3

let b4 = 0 ‘ Reset variable b3
Then after you have written to the display , you have a
goto main statement , which will continually re_write to the display?

for b3 = 5 to 11 ‘ setup for...next loop ("there!"-positions 5 to 11)
read b3, b1 ‘ read letter from EEPROM memory into variable b1
gosub wrchr ‘ send character
Put a goto ( somewhere ) after this section.
and wait or loop there, so the data is only written once to the LCD

Kym
 

Vroom

Member
I see manual 3 page 3, but what is serial LCD firmware? what name IC? meaning rest picaxe 18A to LCD?
 

SilentScreamer

Senior Member
Top