'-----[ Title ]------------------------------------------------ ' ' File......LCD.BS2 ' Purpose...Stamp -> LCD (4-bit interface) ' Author....Marco Hemmerle ' Started...07.02.2003 ' Updated...07.02.2003 ' '-----[ Programm Description ]---------------------------------- ' ' This program demonstrates the various standart features of ' an LCD display that uses the Hitatchi HD44780 controller. ' ' The LCD used to test this program was the OPTREX DMC-40218 ' (2x40). ' ' LCD Connections: ' ' LCD (Function) BS2 '------------------------------------------- ' pin 1 Vss VSS ' pin 2 Vdd VDD ' pin 3 Vo ' pin 4 RS P14 ' pin 5 R/W P13 ' pin 6 E P12 ' pin 7 DB0 ' pin 8 DB1 ' pin 9 DB2 ' pin 10 DB3 ' pin 11 DB4 P11 ' pin 12 DB5 P10 ' pin 13 DB6 P9 ' pin 14 DB7 P8 '-----[ Revision History ]---------------------------------------- ' ' 07-02-2003: Version 1.0 - Marco Hemmerle ' '-----[ Directives]----------------------------------------------- ' '{$STAMP BS2sx} 'specifies a BS2 ' '-----[ Constants ]----------------------------------------------- ' E CON 12 ' LCD enable pin (1 = enabled) RS CON 14 ' Register Select (1 = char) ' ' 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 Line1 CON $80 ' addr line #1 ¦ 80H Line2 CON $C0 ' addr line #2 ¦ 80H Line3 CON $90 ' addr line #3 ¦ 80H Line4 CON $D0 ' addr line #4 ¦ 80H '-----[ Variables ]------------------------------------------------ ' outp VAR Byte ' output workspace char VAR Byte ' char sent to LCD index VAR Byte ' loop counter '-----[ Initialization ]------------------------------------------- ' DATA "THE BASIC STAMP! " ' preload EEPROM DATA "A PIC16C57 knows " DATA "P B A S I C from " ' preload EEPROM DATA "Parallax Inc. " OUT1 = %00000000 ' clear the pins DIR1 = %11111111 ' set 0-5 as outputs PAUSE 1000 ' let the LCD settle ' Initialize the LCD (Hitatchi HD44780 controller) ' LCDini: OUT1 = %00110000 ' 8-bit mode PULSOUT E, 10 PAUSE 10 PULSOUT E, 10 PAUSE 1 PULSOUT E, 10 PAUSE 1 OUT1 = %00100000 ' 4-bit mode PULSOUT E, 10 char = %00101000 ' set function for LM041 GOSUB WrLCD char = %00001100 ' disp on, crsr off, blink off GOSUB WrLCD char = %00000110 ' inc crsr, no disp shift GOSUB WrLCD char = %00000001 ' clear LCD GOSUB WrLCD HIGH RS ' LCD to character mode '-----[ Main Code ]------------------------------------------------- ' Start: FOR index = 0 TO 19 READ index, char ' get char from EEPROM GOSUB WrLCD ' write it NEXT char = Line2 ' address second line GOSUB LCDcmd FOR index = 20 TO 39 READ index, char ' get char from EEPROM GOSUB WrLCD ' write it NEXT char = Line3 ' address second line GOSUB LCDcmd FOR index = 40 TO 59 READ index, char ' get char from EEPROM GOSUB WrLCD ' write it NEXT char = Line4 ' address second line GOSUB LCDcmd FOR index = 60 TO 79 READ index, char ' get char from EEPROM GOSUB WrLCD ' write it NEXT PAUSE 1000 char = ClrLCD ' clear the LCD GOSUB LCDcmd PAUSE 500 GOTO Start ' do it all over '-----[ Subroutines ]----------------------------------------------- ' ' Send command to the LCD ' ' Load char with command value, then call ' ' Clear the LCD.........$01, %00000001 ' Home the cursor.......$02, %00000010 ' Display control.......(see below) ' Entry mode............(see below) ' Cursor left...........$10, %00010000 ' Cursor right..........$14, %00010100 ' Scroll display left...$18, %00011000 ' Scroll display right..$1C, %00011100 ' Set CG RAM address.... %01aaaaaa (Character Generator) ' Set DD RAM address.... %1aaaaaaa (Display Data) ' ' Display control byte: ' ' % 0 0 0 0 1 D C B ' | | -- blink character under cursor (1=blink) ' | ---- cursor on/off (1=on) ' ------ display on/off (1=on) ' ' Entry mode byte: ' ' % 0 0 0 0 0 1 X S ' | --- shift display (S=1), left (X=1), right (X=0) ' ----- cursor move: right (X=1), left (X=0) ' LCDcmd: LOW RS GOSUB WrLCD HIGH RS RETURN ' Write ASCII char to LCD ' WrLCD: OUT1 = OUT1 & %00001000 ' RS = 1, data bus clear outp = char & %11110000 ' mask the high nibble OUT1 = OUT1 | outp ' output the nibble PULSOUT E, 10 ' strobe the Enable line OUT1 = OUT1 & %00001000 outp = char & %00001111 ' get low nibble outp = outp << 4 OUT1 = OUT1 | outp PULSOUT E, 10 RETURN