'--------------------------------------------------------- ' '4_bit_character.bas 'Program For Writing To Newhaven Display Character LCD ' ' (c)2008 Curt Lagerstam - Newhaven Display International , LLC. ' ' This program is free software; you can redistribute it and/or modify ' it under the terms of the GNU General Public License as published by ' the Free Software Foundation; either version 2 of the License, or ' (at your option) any later version. ' ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details. ' '--------------------------------------------------------- '2x16 Dot-Matrix Module '4 Bit interface ' 'DB7-DB4 is P1.7-P1.4 'E is P3.4 active LOW 'WR is P3.7 ***GND*** 'D/I is P3.0 ' '----------------------------------------------------------------------------- Declare Sub Writecom Declare Sub Writedata Declare Sub Nybble Dim A As Byte Dim Com As Byte Dim Count As Byte 'Start' Do Set P3 Reset P3.0 Waitms 100 A = &H30 P1 = A Call Nybble 'wake up Waitms 100 Call Nybble 'wake up Waitms 10 Call Nybble 'wake up Waitms 10 A = &H20 '4-bit interface P1 = A Call Nybble Com = &H28 '4-bit, 2 lines Call Writecom Com = &H10 'cursor shift Call Writecom Com = &H0F 'display on Call Writecom Com = &H06 'entry mode Call Writecom Com = &H01 'home Call Writecom Restore Dta1 For Count = 1 To 16 Read A Call Writedata Next Count Com = &HC0 '2nd line Call Writecom Restore Dta2 For Count = 1 To 16 Read A Call Writedata Next Count Wait 5 Loop End Dta1: Data "Newhaven Display" Dta2: Data "4-bit interface " Sub Nybble Reset P3.4 'E Waitms 1 'enable pulse width >= 300ns Set P3.4 'E End Sub Sub Writecom P1 = Com 'move data to Port 1 Reset P3.0 'RS = Instruction register Call Nybble 'write high 4 bits Rotate Com , Left , 4 'rotate P1 = Com 'move data to Port 1 Call Nybble 'write low 4 bits End Sub Sub Writedata P1 = A Set P3.0 'RS=Data register Call Nybble Rotate A , Left , 4 P1 = A Call Nybble End Sub