Welcome to WeetHet!


Managed Web Hosting by Liquid Web

Your IP address:
18.226.93.139
     
 
Print this page
- use Landscape
Search the
WeetHet Pages
WeetHet is being updated! - Current articles will slowly move to www.tweaking4all.com
For excellent webhosting that is reliable and affordable, we highly recommend: LiquidWeb

On this page ...

This serie of pages on this website will help you on your way with the Parallax (OEM) Basic Stamp II microcontroller.

Controlling a Hitachi 44780 based LCD display.

Tip: for Mitsubishi 50530 based displays, read the Optrex 50652N article.

In this article I'll try to explain to you how to control a LCD display with your (OEM) Basic Stamp II using an old LCD panel from an Ericsson DBC661 phone or any 44780 based LCD for that matter. For control using a PC see the LCD Project page.

The LCD panels I used are the OPTREX DMC2034 and DMC50400 which I got out two defect Ericsson phones. These are 4 x 20 (4 lines, 20 characters) panels.
This article can be downloaded as a MS Word document.

Pictures of the LCD in action can be found here.

Don't forget the Disclaimer!

Parallax: Basic Stamp II

Overview

  1. How to connect the LCD panel to your OEM Basic Stamp 2
  2. Getting Control - Sending characters
  3. Getting Control - Sending instructions
  4. Getting Control - Initializing the display
  5. Layout of the OPTREX DMC2034 and DMC50400
  6. Example code: LCDDEMO1.BS2
  7. Example code: WATCHDOG.BS2
  8. Example code: WATCHDOG2.BS
  9. My mini-BOE (Board of Education)


How to connect the LCD to you Basic Stamp II

Below you will find two tables, both containing identical data, except the first one is the proper way to display the connection. The second table is for the impatient and more experienced user showing what to connect to what.

Make these connections:

LCD Display pin LCD Functionality OEM Basic Stamp 2 pin
1
Ground Vss (= GND)
2
+5 Volt Vdd (= regulated +5V)
3
Vee (LCD contrast) Vss (= GND)
4
RS (Register Select) pin 4
5
R/W (Read/Write) Vss (= GND)
6
E (Edge Enable) pin 5
7
DB0 (databit 0) not connected
8
DB1 (databit 1) not connected
9
DB2 (databit 2) not connected
10
DB3 (databit 3) not connected
11
DB4 (databit 4) pin 0
12
DB5 (databit 5) pin 1
13
DB6 (databit 6) pin 2
14
DB7 (databit 7) pin 3

The quick and dirty notation for the impatient (like myself):

OEM Basic Stamp 2 pin
LCD Display pin
Vss (GND)
1 (GND), 3 (Vee), 5 (R/W)
Vdd (+5V)
2 (+5V)
pin 0
11 (DB4)
pin 1
12 (DB5)
pin 2
13 (DB6)
pin 3
14 (DB7)
pin 4
4 (RS)
pin 5
6 (E)

Note: the pin out is based on Jon's LCDDEMO1.BAS. However this did not work for me due to two little mistakes in the LCD connections (however: without it it would have taken me ages!).

  • LCD_Pin4 and LCD_Pin14 should not be connected to the same pin on the Basic Stamp.
  • The data transmitted from the Basic Stamp using P0 … P3 will not work, since P3 is not connected.
  • DB0 … DB3 do not need to be connected to GND to work properly.

To make the ports work properly we need a little Pbasic code:

Init:    DirL = %00111111     ' set (lower 8) pins 0-5 as outputs
         Outs = $0000         ' clear the pins
                 
                 

Getting Control - Sending text

OK, so now we hooked to LCD up to our Basic Stamp 2. How do we control a parallel controlled LCD panel by using only 6 wires?

The answer is actually pretty simple (thanks to Jon's work): the LCD panel can be controlled using 8-bits or 4-bits. 4-bit mode is working identical to 8-bit mode mode, however we transmit the upper 4 bits and the lower 4 bits in sequence instead of 8 bits parallel.


Practical example:

Say we would like to send the character 'A' which is in binary code:
0100 0001 (hexadecimal $41, decimal 65).

First we send the upper 4 bits called a nibble (now this will be confusing when you start with it, but you'll get used to it). Second we send the lower 4 bits.
The upper 4 bits are in fact the first 4 bits in our binary representation: 0100 !!
The lower 4 bits are in fact the last 4 bits in our binary representation. So this is what we send:

0100
0001

Which will result in a character 'A' on your LCD display.


This all sounds pretty hard to do, but be assured. The Basic Stamp 2 has some neat routines that will help us with this task.

Let's say that a character uses the space of one byte (=8 bits) and we define a variable for that purpose. In Pbasic that would like this:

char  VAR  Byte            ' character sent to LCD

Here we define the variable ('var'-statement) called 'char' of type 'Byte'.
Pbasic offers a nice function for the byte: HIGHNIB (high nibble) and LOWNIB (lower nibble). The statement shown below will return the upper 4-bits of the character:

OutA = char.HIGHNIB        ' output high nibble

Similar, the next statement will output the lower 4 bits:

OutA = char.LOWNIB        ' output lower nibble

To get read/write activity we just need to add a little additional code to get a pulse to the 'E'-pin of the LCD panel, which we connected to pin5 of the Basic Stamp 2, after sending the nibble. Once more Pbasic shows it's power. Sending a simple 'high' (=1) to pin5 is done with this little piece of:

PULSOUT 5, 1             ' strobe the Edge Enable line

To get the LCD to know that we are sending data (not a instruction) we must raise the 'RS'-pin of the LCD high as well. Since we leave RS high, you might wonder why we keep doing it, but that soon will be clear once we implement a routine for sending instructions.
Setting RS high involves setting pin4 of the Basic Stamp 2 to high:

HIGH 4                   ' goto write-character mode

That's it for sending characters. However that's not enough to get the display operational. See the next paragraph for sending instructions.

Below you will find the gosub-routine for sending characters:

' =-=-=-=-=-=-=-=-=-=-=-=                  
' Write ASCII char to LCD 
' =-=-=-=-=-=-=-=-=-=-=-= 
LCDwr: 
OutA = char.HIGHNIB ' output high nibble
PULSOUT 5, 1 ' strobe the Enable line
OutA = char.LOWNIB ' output low nibble
PULSOUT 5, 1
HIGH 4 ' return to character mode
RETURN

Getting Control - Sending instructions

Sending instructions is basically the same as sending characters. The only difference is that pin4 (RS of the LCD) should be LOW instead of HIGH. The LCD panel uses this to distinct between text and instructions.
The only difference therefore is to set RS low:

LOW 4            ' enter command mode

Next step is to send the actual instruction. The instruction however is basically a character, so we can use our 'LCDsendchar' routine to send the instruction.

Our gosub-routine could look like this:

' =-=-=-=-=-=-=-=-=-=-=-=-                  
' Write instruction to LCD 
' =-=-=-=-=-=-=-=-=-=-=-=- 
LCDcmd: LOW RS ' enter command mode
LCDsendchar ' then write the character


What instructions are supported you might wonder. Take a look at this table:

Binairy value Purpose
0
0
0
0
0
0
0
1
Clear display and return cursor to home position.
0
0
0
0
0
0
1
X
Return cursor to home position.
The value of ‘X’ does not matter.
0
0
0
0
0
1
D
S
Entry mode.
Set cursor move directions and whether or not display can scroll.
D=1: cursor moves to the right
D=0: cursor moves to the left
S=1: scroll the cursor in the direction set by ‘D’ when the cursor is at the edge of the display.
0
0
0
0
1
D
C
B
On/Off control.
D=1: display ON
D=0: display OFF
C=1: cursor (underscore) ON
C=0: cursor (underscore) OFF
B=1: blinking cursor ON
B=0: blinking cursor OFF
0
0
0
1
S
R
X
X
Cursor/Shift control.
Move cursor or scroll display without changing display data.
S=1: scroll display
S=0: move cursor
R=1: to the right
R=0: to the left
The value of ‘X’ does not matter.
0
0
1
D
B
F
X
X
Function Settings.
Set interfacing data length, mode and font.
D=1: 8-bit interface
D=0: 4-bit interface
N=1: 1/16 duty (>1 line mode)
N=0: 1/8 or 1/11 duty (1 line mode)
F=1: 5x11 matrix font
F=0: 5x8 matrix font
0
1
A
A
A
A
A
A
Set character RAM address.
For defining custom characters.
1
A
A
A
A
A
A
A
Set display RAM address.
Used for quick repositioning cursor.
On 2 line models 1LAAAAAA ‘L’ can be used to identify line.
Note: 4 line models have only 2 lines. Lines 1 and 3 are 1 single line, and lines 2 and 4 are a single line!

AAAAAA can be interpreted as a 6 bit column number.


So now we can control the display a bit more …
To keep your code readable, you might want to define some constants for this purpose:

' LCD control characters
'
ClrLCD CON %00000001   ' clear the LCD
CrsrHm CON $00000010   ' move cursor to home position
CrsrLf CON $00010000   ' move cursor left
CrsrRt CON $00010100   ' move cursor right
DispLf CON $00011000   ' shift displayed chars left
DispRt CON $00011100   ' shift displayed chars right
DDRam  CON $10000000   ' Display Data RAM control

So how do we use the instructions?

Well, having defined some constants, an gosub-routines for writing characters and one instructions, things should work pretty easy.


Practical example:

Let's clear the display:

Char = ClrLCD
GOSUB LCDcmd

Or let's move the cursor to the left:

Char = CrsrLf
GOSUB LCDcmd

You might think that's it, but it isn't. Before we can do ANYTHING with the LCD display, we need to initialize it.

Generic Control - Initializing the LCD

The gosub-routines we just defined are very useful for this particular task: initializing the LCD display.

We need to keep in mind that the display must be initialized in 4-bit mode. Using the reference manual of Hitachi, this should be the way to do it:

Stap Actie Code (=binary value)
1
Power ON
-
2
Set 8-bit mode (yes)
00000011
3
Set 8-bit mode (yes)
00000011
4
Set 8-bit mode (yes)
00000011
5
Set 4-bit mode
00000010
6
Set duty mode*
00101100
7
Display/Cursor/Blink OFF*
00000000
8
Display/Cursor/Blink ON*
00001111
9
Set input mode*
00000110
* = Use instructions table to customize to your needs


So what does the initialization look like in basic?

LCDini:  
  pause 50 ' Wait for LCD init 
  ' =================================
  ' STANDARD HITACHI 44780 4-BIT INIT
  ' =================================
  char=%00000011   ' Set 8-bit mode (1)
  GOSUB LCDcmd
  char=%00000011   ' Set 8-bit mode (2)
  GOSUB LCDcmd
  char=%00000011   ' Set 8-bit mode (3)
  GOSUB LCDcmd
  char=%00000010   ' Set 4-bit mode
  GOSUB LCDcmd
  char=%00101111   ' Set duty cycle 11xx = 5x11 matrix
  GOSUB LCDcmd     ' 10xx = 5x8 matric
  char=%00000000   ' Display control mode
  GOSUB LCDcmd
  char=%00001000   ' Set display OFF, cursor OFF, blink OFF
  GOSUB LCDcmd
  char=%00000000   ' Display control mode
  GOSUB LCDcmd
  char=%00001111   ' Set display ON, cursor ON, blink ON
  GOSUB LCDcmd     ' 11CB -> C=1 cursor on, B=1 blink on
  char=%00000000   ' Entry control mode
  GOSUB LCDcmd
  char=%00000110   ' Set cursor right, no display shift
  GOSUB LCDcmd     ' 01IS -> I=1 cursor right, S=1 shift display
  char = ClrLCD    ' Clear LCD
  GOSUB LCDcmd

The official LCD FAQ and Hitachi documentation mention al lot about the execution timing. Using the Basic Stamp 2 that appears not be an issue.

OPTREX DMC2034 and DMC50400 - A 4x20 LCD layout

I used both these Optrex 4x20 LCD display-types, which both use the Hitachi 44780 controller. The pin-layout of this display is basic for all Hitachi-based LCD displays. The character layout of the display is pretty basic for all 4x20 displays.

For 4x20 LCD's you will generally find two types of layout, more recent displays support the layout you find below.

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
..
..
..
..
..
..
..
..
..
30
..
..
..
..
..
..
..
..
39
40
..
..
..
..
..
..
..
..
..
50
..
..
..
..
..
..
..
..
59
60
..
..
..
..
..
..
..
..
..
70
..
..
..
..
..
..
..
..
79

When filling the character positions, starting in the upper left corner, the display will be filled starting in the upper left corner and end in the lower right corner.

Older 4x20 LCD displays, like the Optrex I'm using, have different line layout:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
40
..
..
..
..
..
..
..
..
..
49
..
..
..
..
..
..
..
..
59
20
..
..
..
..
..
..
..
..
..
30
..
..
..
..
..
..
..
..
39
60
..
..
..
..
..
..
..
..
..
70
..
..
..
..
..
..
..
..
79

Notice that the lines 1 and 3 follow each other. Line 2 is followed by line 4. So basically when filling all character positions, the lines will be filed in this order: line 1, line 3, line 2 and finally line 4.

This makes it a bit harder to control the position of the cursor on the LCD display. You can take a look at this gosub-routine I wrote (see Example 3 for a demo) which uses the cursor repositioning functionality of the display:

                 ' ============================
                 ' Write char at position (X,Y)
                 ' ============================
                 ' Usage:
                 ' X=10 ' horizontal position or column (X)
                 ' Y=2 ' vertical position or line (Y)
                 ' char="A" ' character to write
                 ' GOSUB LCDpos ' position cursor and write char
                 '
LCDpos:
                 char2=char ' Save char
                 char=CrsrHm                  ' Set cursor to home location
                 GOSUB LCDcmd
                 
                 counter=%00000000            ' Reset counter (=position 0)
                 IF Y=1 THEN done             ' 4x20: row1 starts at position 0 
                 IF Y=2 THEN pos_row2
                 IF Y=3 THEN pos_row3
                 IF Y=4 THEN pos_row4
pos_row2:        ' 4x20: row2 starts at position 64
                 counter=%01000000
                 GOTO position
pos_row3:        ' 4x20: row3 starts at position 20
                 counter=%00010100
                 GOTO position
pos_row4:        ' 4x20: row4 starts at position 84
                 counter=%01010100
                 GOTO position
position:        
                 counter=counter+X-1          ' Add X to Y position minus 1 (pos 1 = 0)
                 char=%10000000+counter
                 GOSUB LCDcmd
done:            char=char2                   ' restore old char
                 GOSUB LCDwr                  ' and write it
                 RETURN

Hitachi 44780 Pin layout

Hitachi based LCD display have a very common connector to the outer world:

LCD print connector LCD Function
1
GND
2
+5 Volt
3
Vee (LCD Drive)
4
RS (Register Select)
5
R/W (Read/Write)
6
E (Edge Enabled)
7
DB0 (data bit 0)
8
DB1 (data bit 1)
9
DB2 (data bit 2)
10
DB3 (data bit 3)
11
DB4 (data bit 4)
12
DB5 (data bit 5)
13
DB6 (data bit 6)
14
DB7 (data bit 7)

Example 1: LCDDEMO1.BS2

This is an adapted version of Jon Williams (http://members.aol.com/jonwms) his LCDDEMO1.BS2. It basically initializes the LCD display and sends a text to the display over and over again (download here):

' -----[ Constants ]-------------------------------------------------------
' Ports used
                 RS CON 4 ' Register Select (1 = char)
                 E CON 5  ' LCD Enable pin (1 = enabled)
' LCD control characters
'
                 ClrLCD CON $01 ' clear the LCD
                 CrsrHm CON $02 ' move cursor to home position
                 CrsrLf CON $10 ' move cursor left
                 CrsrRt CON $14 ' move cursor right
                 DispLf CON $18 ' shift displayed chars left
                 DispRt CON $1C ' shift displayed chars right
                 DDRam CON $80  ' Display Data RAM control
' -----[ Variables ]-------------------------------------------------------
'
                 char VAR Byte  ' character sent to LCD
                 index VAR Byte ' loop counter
' -----[ EEPROM Data ]-----------------------------------------------------
'
                 Msg DATA "BASIC Stamp 2 LCD in action"   ' preload message
' -----[ Initialization ]--------------------------------------------------
'
Init:            DirL = %00111111   ' set pins 0-5 as outputs
                 Outs = $0000       ' clear the pins
' Initialize the LCD (Hitachi HD44780 controller)
'
LCDinit:         pause 500 ' Wait for LCD init 
                 ' =================================
                 ' STANDARD HITACHI 44780 4-BIT INIT
                 ' =================================
                 char=%00000011 ' Set 8-bit mode (1)
                 GOSUB LCDcmd
                 char=%00000011 ' Set 8-bit mode (2)
                 GOSUB LCDcmd
                 char=%00000011 ' Set 8-bit mode (3)
                 GOSUB LCDcmd
                 char=%00000010 ' Set 4-bit mode
                 GOSUB LCDcmd
                 char=%00101111 ' Set duty cycle 11xx = 5x11 matrix
                 GOSUB LCDcmd   ' 10xx = 5x8 matric
                 char=%00000000 ' Display control mode
                 GOSUB LCDcmd
                 char=%00001000 ' Set display OFF, cursor OFF, blink OFF
                 GOSUB LCDcmd
                 char=%00000000 ' Display control mode
                 GOSUB LCDcmd
                 char=%00001111 ' Set display ON, cursor ON, blink ON
                 GOSUB LCDcmd   ' 11CB -> C=1 cursor on, B=1 blink on
                 char=%00000000 ' Entry control mode
                 GOSUB LCDcmd
                 char=%00000110 ' Set cursor right, no display shift
                 GOSUB LCDcmd   ' 01IS -> I=1 cursor right, S=1 shift display
                 char = ClrLCD  ' Clear LCD
                 GOSUB LCDcmd
' -----[ Main Code ]-------------------------------------------------------
'
Start: 
                 FOR index = 0 TO 39
                   READ Msg + index, char ' get character from memory
                   GOSUB LCDwr            ' write it to the LCD
                 NEXT
                 PAUSE 1000               ' wait 2 seconds
                 char = ClrLCD            ' clear the LCD
                 GOSUB LCDcmd
                 PAUSE 500
                 GOTO Start               ' do it all over
' -----[ Subroutines ]-----------------------------------------------------
'
' Send command to the LCD
'
LCDcmd:          LOW RS ' enter command mode
                 
'
' Write ASCII char to LCD 
'
LCDwr: 
                 OutA = char.HIGHNIB ' output high nibble
                 PULSOUT E, 1        ' strobe the Enable line
                 OutA = char.LOWNIB  ' output low nibble
                 PULSOUT E, 1
                 HIGH RS             ' return to character mode
                 RETURN




Example 2: WATCHDOG.BS2

In this example a gauge is running up and down using a routine to reposition the cursor on the display.

' -----[ Constants ]-------------------------------------------------------
' Ports used
                 RS CON 4 ' Register Select (1 = char)
                 E CON 5  ' LCD Enable pin (1 = enabled) 
' LCD control characters
'
                 ClrLCD CON $01 ' clear the LCD
                 CrsrHm CON $02 ' move cursor to home position
                 CrsrLf CON $10 ' move cursor left
                 CrsrRt CON $14 ' move cursor right
                 DispLf CON $18 ' shift displayed chars left
                 DispRt CON $1C ' shift displayed chars right
                 DDRam CON $80  ' Display Data RAM control 
' -----[ Variables ]-------------------------------------------------------
'
                 char VAR Byte    ' character sent to LCD
                 char2 VAR Byte   ' Duplicate character store
                 index VAR Byte   ' loop counter
                 counter VAR Byte ' 2nd counter
                 X VAR Byte       ' X position
                 Y VAR Byte       ' Y position  
'-----[ Initialization ]--------------------------------------------------
'
                 Init: DirL = %00111111 ' set pins 0-5 as outputs
                 Outs = $0000           ' clear the pins 
                 '=================================
                 ' STANDARD HITACHI 44780 4-BIT INIT
                 ' ================================= 
LCDinit:         pause 500      ' Wait for LCD init 
                 char=%00000011 ' Set 8-bit mode (1)
                 GOSUB LCDcmd
                 char=%00000011 ' Set 8-bit mode (2)
                 GOSUB LCDcmd
                 char=%00000011 ' Set 8-bit mode (3)
                 GOSUB LCDcmd
                 char=%00000010 ' Set 4-bit mode
                 GOSUB LCDcmd
                 char=%00101111 ' Set duty cycle 11xx = 5x11 matrix
                 GOSUB LCDcmd   ' 10xx = 5x8 matric
                 char=%00000000 ' Display control mode
                 GOSUB LCDcmd
                 char=%00001000 ' Set display OFF, cursor OFF, blink OFF
                 GOSUB LCDcmd
                 char=%00000000 ' Display control mode
                 GOSUB LCDcmd
                 char=%00001100 ' Set display ON, cursor ON, blink ON
                 GOSUB LCDcmd   ' 11CB -> C=1 cursor on, B=1 blink on
                 char=%00000000 ' Entry control mode
                 GOSUB LCDcmd
                 char=%00000110 ' Set cursor right, no display shift
                 GOSUB LCDcmd   ' 01IS -> I=1 cursor right, S=1 shift display

                 char = ClrLCD  ' Clear LCD
                 GOSUB LCDcmd   
                 PAUSE 500 
'-----[ Main Code ]-------------------------------------------------------
'
Start: 
                 Y=2
                 FOR X=6 TO 15
                   char="0"+X-6
                   GOSUB LCDPos
                 NEXT

start2:
                 Y=1
                 char=255
                 FOR X=6 to 15
                   GOSUB LCDPos
                   pause 50
                 NEXT                   

                 char=" "
                 FOR X=6 to 15
                   GOSUB LCDPos
                   pause 50
                 NEXT                   

                 goto start2 

'-----[ Subroutines ]-----------------------------------------------------                  
' ============================ ' Write char at position (X,Y) ' ============================ ' Usage: ' X=10 ' horizontal position or column (X) ' Y=2 ' vertikal position or line (Y) ' char="A" ' character to write ' GOSUB LCDpos ' position cursor and write char ' (note: this is the SLOW version! look at the next example for a better way!) LCDpos: char2=char ' Save char char=CrsrHm ' Set cursor to home location GOSUB LCDcmd counter=0 ' Reset counter IF Y=1 THEN position IF Y=2 THEN pos_row2 IF Y=3 THEN pos_row3 IF Y=4 THEN pos_row4 pos_ row2: ' 4x20: row2 starts at position 40 counter=40 GOTO position pos_row3: ' 4x20: row3 starts at position 20 counter=20 GOTO position pos_row4: ' 4x20: row4 starts at position 60 counter=60 GOTO position position: ' 4x20: row1 starts at position 0 counter=counter+X-1 ' Add X to Y position minus 1 (pos 1 = 0) IF counter=0 THEN done ' work around the loop for pos (0,0) for index=1 to counter ' move cursor x steps to the right char=CrsrRt GOSUB LCDcmd NEXT done: char=char2 ' restore old char GOSUB LCDwr ' and write it RETURN '======================= ' Send command to the LCD ' ======================= LCDcmd: LOW RS ' enter command mode '======================= ' Write ASCII char to LCD ' ======================= LCDwr: OutA = char.HIGHNIB ' output high nibble PULSOUT E, 1 ' strobe the Enable line OutA = char.LOWNIB ' output low nibble PULSOUT E, 1 HIGH RS ' return to character mode RETURN




Example 3: WATCHDOG2.BS

This example is similar to the previous example with the difference to be found in the positioning routine, which is considerably faster in this demo.

' -----[ Constants ]-------------------------------------------------------
' ports used
                 RS CON 4 ' Register Select (1 = char)
                 E CON 5 ' LCD Enable pin (1 = enabled)
' LCD control characters ' ClrLCD CON $01 ' clear the LCD CrsrHm CON $02 ' move cursor to home position CrsrLf CON $10 ' move cursor left CrsrRt CON $14 ' move cursor right DispLf CON $18 ' shift displayed chars left DispRt CON $1C ' shift displayed chars right DDRam CON $80 ' Display Data RAM control ' -----[ Variables ]------------------------------------------------------- ' char VAR Byte ' character sent to LCD char2 VAR Byte ' Duplicate character store index VAR Byte ' loop counter counter VAR Byte ' 2nd counter X VAR Byte ' X position Y VAR Byte ' Y position ' -----[ Initialization ]-------------------------------------------------- ' Init: DirL = %00111111 ' set pins 0-5 as outputs Outs = $0000 ' clear the pins ' ================================= ' STANDARD HITACHI 44780 4-BIT INIT ' ================================= LCDinit: pause 500 ' Wait for LCD init char=%00000011 ' Set 8-bit mode (1) GOSUB LCDcmd char=%00000011 ' Set 8-bit mode (2) GOSUB LCDcmd char=%00000011 ' Set 8-bit mode (3) GOSUB LCDcmd char=%00000010 ' Set 4-bit mode GOSUB LCDcmd char=%00101111 ' Set duty cycle 11xx = 5x11 matrix GOSUB LCDcmd ' 10xx = 5x8 matric char=%00000000 ' Display control mode GOSUB LCDcmd char=%00001000 ' Set display OFF, cursor OFF, blink OFF GOSUB LCDcmd char=%00000000 ' Display control mode GOSUB LCDcmd char=%00001100 ' Set display ON, cursor ON, blink ON GOSUB LCDcmd ' 11CB -> C=1 cursor on, B=1 blink on char=%00000000 ' Entry control mode GOSUB LCDcmd char=%00000110 ' Set cursor right, no display shift GOSUB LCDcmd ' 01IS -> I=1 cursor right, S=1 shift display char = ClrLCD ' Clear LCD GOSUB LCDcmd PAUSE 500 ' -----[ Main Code ]------------------------------------------------------- ' Start: Y=2 FOR X=6 TO 15 char="0"+X-6 GOSUB LCDPos NEXT start2: Y=4 char=255 FOR X=6 to 15 GOSUB LCDPos pause 50 NEXT char=" " FOR X=6 to 15 GOSUB LCDPos pause 50 NEXT goto start2 ' -----[ Subroutines ]----------------------------------------------------- ' ============================ ' Write char at position (X,Y) ' ============================ ' Usage: ' X=10 ' horizontal position or column (X) ' Y=2 ' vertical position or line (Y) ' char="A" ' character to write ' GOSUB LCDpos ' position cursor and write char ' (this is the faster version - compared to example 2 LCDpos: char2=char ' Save char char=CrsrHm ' Set cursor to home location GOSUB LCDcmd counter=%00000000 ' Reset counter (=position 0) IF Y=1 THEN done IF Y=2 THEN pos_row2 IF Y=3 THEN pos_row3 IF Y=4 THEN pos_row4 pos_row2: ' 4x20: row2 starts at position 64 counter=%01000000 GOTO position pos_row3: ' 4x20: row3 starts at position 20 counter=%00010100 GOTO position pos_row4: ' 4x20: row4 starts at position 84 counter=%01010100 GOTO position position: ' 4x20: row1 starts at position 0 counter=counter+X-1 ' Add X to Y position minus 1 (pos 1 = 0) char=%10000000+counter GOSUB LCDcmd done: char=char2 ' restore old char GOSUB LCDwr ' and write it RETURN ' ======================= ' Send command to the LCD ' ======================= LCDcmd: LOW RS ' enter command mode ' ======================= ' Write ASCII char to LCD ' ======================= LCDwr: OutA = char.HIGHNIB ' output high nibble PULSOUT E, 1 ' strobe the Enable line OutA = char.LOWNIB ' output low nibble PULSOUT E, 1 HIGH RS ' return to character mode RETURN

My mini BOE - Board Of Education

Here you will find what I did to create a so called BOE (Board Of Education) for purposes like this (LCD testing).

BOM - Bill Of Materials

1x DIL 40 chip socket
1x Experimentation board
Some soldering stuff and some wire

First I mounted a regular chip-socket (DIL-40) which I cut into two pieces. This will be used as a mount connector for the OEM Basic Stamp 2 board.

Next I soldered to other part of the DIL-40 (only 8 pins of them) upside down on the board, so it would function as a socket kind of thing. This socket I have numbered the pins of: pin 1 to 8 and wired them to the OEM Basic Stamp 2 socket.

Next I wired the connections of the LCD panel to a connector that fit's the socket I created for the LCD hookup;

Pin BasicStamp 2 pin LCD connector pin
1
Vss (GND)
1, 3, 5
2
Vdd (+5V)
2
3
Pin 0 (DB4)
11
4
Pin 1 (DB5)
12
5
Pin 2 (DB6)
13
6
Pin 3 (DB7)
14
7
Pin 4 (RS)
4
8
Pin 5 (E)
6

Pictures of this BOE can be found here.


 

 


Klik hier om te wisselen naar nederlandstalige pagina's You are currently on the English pages.