Stamp 2 & LCD

This is the place for any magazine-related discussions that don't fit in any of the column discussion boards below.
Post Reply
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Stamp 2 & LCD

Post by Shing »

I am trying to write driver software for a 2x16 parallel LCD display. I also intend on only using a 4-bit data bus. I have a copy of the code required to do so but the code assumes that the data lines of the LCD will be connected to pins P0 to P3. I have my Stamp 2 to read from pins P2 to P5.<p>I'm hoping I can modify the code in order to use my pin configuration but looking at the code that I have, there's no obvious hints. Any ideas? Thanks.<p>Regards,
Wai Shing
bodgy
Posts: 1044
Joined: Tue Dec 04, 2001 1:01 am
Location: Australia
Contact:

Re: Stamp 2 & LCD

Post by bodgy »

Well without having seen the code or your actual circuit diagram, the only thing I can say is that in theory all you need to to is change the pin declarations in the program.<p>So long as you keep the LCD's DB4-DB7 on the same nibble of the port and reasign R/W, EN and RS all should be fine.<p>If the Stamp has a built in LCD routine then that may prove more difficult. But thne you could just write your own.<p>Colin
On a clear disk you can seek forever.
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Re: Stamp 2 & LCD

Post by Shing »

I've tried looking for pin declarations that could be changed with no luck. I have no experience with PBASIC at all. I didn't want to have to post the code but it looks like I might have to. Apologies in advance.<p>Regards,
Wai Shing
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Re: Stamp 2 & LCD

Post by Shing »

Source: Microcontroller Projects With Basic Stamps.<p>E con 7 'LCD Enable Bit.
RS con 6 'LCD Reg Select.<p>char var byte 'Char to LCD.
inum var word 'Number to write.
j var byte 'GP variable.
nozero var bit 'Set to 1 for zero suppression.
cursor var byte<p>pw con 1 'Pulse width.<p>'Set up the Stamp's I/O lines and initialise the LCD.
begin:
GOSUB i_LCD
i var word
k var word
k=100
msg:
cursor=40 'Set cursor to line 2.
gosub setcursor
i=0
ploop: 'Write the company name.
LOOKUP i,["AWC",0],char
if char=0 then main
gosub wr_LCD
i=i+1
goto ploop<p>'Main Program Loop
main:
pause 1000 'Wait a second.<p>ctloop:
gosub clear 'Clear LCD.
inum=k 'k starts at 100.
nozero=1
gosub wr_worddec 'Write out K with zero suppress.
k=k-1
cursor=39 'Move cursor to far left.
gosub setcursor
LOOKUP k//4,["*","+","-"," "],char 'Make spinner.
gosub wr_LCD
goto msg<p>'Write the ASCII character in char to LCD.
wr_LCD:
outA=char.NIB1 'OR the first 4 bits in.
pulsout E,pw 'Blip enable pin.
outA=char.NIB0
pulsout E,pw 'Blip enable.
return<p>'Write a word in decimal.
wr_worddec:
j=5
goto wr_dec<p>'Write a byte in decimal.
wr_bytedec:
j=2<p>wr_dec:
char=inum DIG j +"0"
'Supress zeros
if j<>0 AND char="0" and nozero=1 then digz
gosub wr_LCD
nozero=0 'Turn off suppression so we don't turn 102 into 12.
digz:
if j=0 then nowr
j=j-1
goto wr_dec
nowr:
return<p>'Initialise the LCD in accordance with Hitachi's instructions for 4-bit interface.
i_LCD:
outA=0 'Clear the output lines.
LOW E
LOW RS
dirA=%1111 '7 outputs.
pause 200 'Wait 200ms for LCD to reset.
'Force 8-bit op - repeating to be sure it resets.
outA=%0011
pulsout E,pw
pulsout E,pw
pulsout E,pw<p> outA=%0010 'Set to 4-bit operation from 8-bit.
pulsout E,pw<p>'Could remove this line if you wanted to.
outA=%0010 'Set to 4-bit operation from 4-bit.
pulsout E,pw
'If you want 1 line, you could comment out the next line.
outA=%1000 '2 line - use 0 for 1 line.
pulsout E,pw<p> char=14 'Set up LCD in accordance with.
'char=15 'Blinking cursor (use 14 for non-blink).
gosub wr_LCD 'Hitachi instruction manual.
char=6 'Turn on cursor and enable.
gosub wr_LCD 'Left-to-right printing.<p>clear:
char=1 'Clear the display.
gosub cmd 'Write instruction to LCD.
return<p>cmd:
low RS
gosub wr_LCD
high RS
return<p>setcursor:
char=$80 + cursor
gosub cmd
return
bodgy
Posts: 1044
Joined: Tue Dec 04, 2001 1:01 am
Location: Australia
Contact:

Re: Stamp 2 & LCD

Post by bodgy »

[QUOTE]Originally posted by Shing:
Source: Microcontroller Projects With Basic Stamps.<p>These are the pin declarations for EN and RS
E con 7 'LCD Enable Bit.
RS con 6 'LCD Reg Select.<p>'Write the ASCII character in char to LCD.
wr_LCD:
outA=char.NIB1
outA=char.NIB0

return<p>'Initialise the LCD in accordance with Hitachi's instructions for 4-bit interface.
i_LCD:
dirA=%1111 Using Port A lower 4 bits 'Force 8-
That bit doesn't seem right, i would have expected dirA=%0000 to make output.
<p>Using this code as a guide, I would suggest that for example if you want to use the lower half of PortB then declare<p>LCD con PORTB NIB.0 or for the top half NIB.1<p>You will need to check the exact syntax for the Stamp, as I'm not totally familiar with it - but that is the general direction.<p>Colin<p>[ March 09, 2003: Message edited by: bodgy ]<p>[ March 09, 2003: Message edited by: bodgy ]</p>
On a clear disk you can seek forever.
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Re: Stamp 2 & LCD

Post by Shing »

I'll check that out. Thanks.<p>Regards,
Wai Shing
wd5gnr
Posts: 104
Joined: Wed Dec 19, 2001 1:01 am
Contact:

Re: Stamp 2 & LCD

Post by wd5gnr »

I thought that code looked familiar!<p>OUTA is P0 to P3, OUTB is P4 to P7, OUTC is P8 to P11 and OUTD is P12 to P15.<p>The E and RS pins are defined near the top. Ground R/W.
Shing
Posts: 34
Joined: Tue Feb 18, 2003 1:01 am
Location: Dublin, Ireland
Contact:

Re: Stamp 2 & LCD

Post by Shing »

Wow! Are you Al Williams, the author of Microcontroller Projects with Basic Stamps? You legend! That book is helping me loads in my project so far. Thanks.<p>Regards,
Wai Shing<p>[ March 11, 2003: Message edited by: Shing ]</p>
Post Reply

Who is online

Users browsing this forum: No registered users and 55 guests