'THIS MODULE IS COMMAND-COMPATIBLE WITH THE NETMEDIA(TM) SERIAL LCD DISPLAYS 'THE CODE IS OPTIMIZED TO TAKE ADVANTAGE OF THE Z-BASIC LANGUAGE FOR THE ZX FAMILY PROCESSORS '*-----------------------------------------------------------------------------* '* The user should define the appropriate row and column settings here * '*-----------------------------------------------------------------------------* #DEFINE MAXROW = 4 'only 2 or 4 rows supported #DEFINE MAXCOLUMN = 16 'only 16 or 20 supported #DEFINE FIXED_DISPLAY = 1 'comment out this define if you have a serial controller that is not set to a fixed size Public Enum LCDCommandType ClearDisplay = 1 Set20CharWide = 3 Set16CharWide = 4 Set4Lines = 5 Set2Lines = 6 HitachiCommand = 17 SetGeometryCmd = 124 SetCursorPositionCmd = 128 End Enum Public Enum CursorStyle HiddenCursor = &HC 'bx0000_1100 BlockCursor = &HD 'bx0000_1101 UnderlineCursor = &HE 'bx0000_1110 End Enum ' Special mapping for backslash. Public Const ASCIIBackslash As Byte = 92 Public Const LCDBackslash As Byte = 6 ' Special mapping for tilde. Public Const ASCIITilde As Byte = 126 Public Const LCDTilde As Byte = 7 '------------------------------------------------------------------------------- Public Sub LCDInitialize( _ ByVal PortNumber As Byte, _ ByVal Baud As long, _ ByVal InputPin As Byte, _ ByVal OutputPin As Byte) Dim BitMap(1 To 8) As Byte ' This is for a worst case condition, just after powering up the LCD. Const PowerupDelay As Single = 1.0 Call LCDInitializeSerialPort() Call LCDOpenSerialPort(PortNumber, Baud, InputPin, OutputPin) ' Allow internal LCD initialization. Call Delay(PowerupDelay) #if FIXED_DISPLAY = 0 #if MAXCOLUMN = 20 call LCDPutByte(124) call LCDPutByte(3) #elseif MAXCOLUMN = 16 call LCDPutByte(124) call LCDPutByte(4) #else #error ERROR:ONLY 16 OR 20 COLUMN LCD IS SUPPORTED #endif #if MAXROW = 4 call LCDPutByte(124) call LCDPutByte(5) #elseif MAXROW = 2 call LCDPutByte(124) call LCDPutByte(6) #else #error ERROR:ONLY 2 or 4 ROW LCD IS SUPPORTED #endif #endif Call LCDClearScreen() 'Define backslash ( \ ) BitMap(1) = bx0000_0000 BitMap(2) = bx0001_0000 BitMap(3) = bx0000_1000 BitMap(4) = bx0000_0100 BitMap(5) = bx0000_0010 BitMap(6) = bx0000_0001 BitMap(7) = bx0000_0000 BitMap(8) = bx0000_0000 Call LCDDefineCustomCharacter(LCDBackslash, BitMap) 'Define tilde ( ~ ) BitMap(1) = bx0000_0000 BitMap(2) = bx0000_0000 BitMap(3) = bx0000_1000 BitMap(4) = bx0001_0101 BitMap(5) = bx0000_0010 BitMap(6) = bx0000_0000 BitMap(7) = bx0000_0000 BitMap(8) = bx0000_0000 Call LCDDefineCustomCharacter(LCDTilde, BitMap) 'set up a rotating slash 'Define backslash ( \ ) BitMap(1) = bx0000_0000 BitMap(2) = bx0001_0000 BitMap(3) = bx0000_1000 BitMap(4) = bx0000_0100 BitMap(5) = bx0000_0010 BitMap(6) = bx0000_0001 BitMap(7) = bx0000_0000 BitMap(8) = bx0000_0000 Call LCDDefineCustomCharacter(0, BitMap) ' Define horizontal ( - ) BitMap(1) = bx0000_0000 BitMap(2) = bx0000_0000 BitMap(3) = bx0000_0000 BitMap(4) = bx0001_1111 BitMap(5) = bx0000_0000 BitMap(6) = bx0000_0000 BitMap(7) = bx0000_0000 BitMap(8) = bx0000_0000 Call LCDDefineCustomCharacter(1, BitMap) ' Define fwdslash ( / ) BitMap(1) = bx0000_0000 BitMap(2) = bx0000_0001 BitMap(3) = bx0000_0010 BitMap(4) = bx0000_0100 BitMap(5) = bx0000_1000 BitMap(6) = bx0001_0000 BitMap(7) = bx0000_0000 BitMap(8) = bx0000_0000 Call LCDDefineCustomCharacter(2, BitMap) ' Define upslash ( | ) BitMap(1) = bx0000_0100 BitMap(2) = bx0000_0100 BitMap(3) = bx0000_0100 BitMap(4) = bx0000_0100 BitMap(5) = bx0000_0100 BitMap(6) = bx0000_0100 BitMap(7) = bx0000_0100 BitMap(8) = bx0000_0000 Call LCDDefineCustomCharacter(3, BitMap) End Sub '------------------------------------------------------------------------------- Public Sub LCDTerminate() Call LCDCloseSerialPort End Sub '------------------------------------------------------------------------------- Public Sub LCDClearScreen() Call LCDPutCommand(ClearDisplay) ' The LCD needs a minimum of 2 ms after clearing the screen. 'Delay (0.002) End Sub '------------------------------------------------------------------------------- Public Sub LCDMoveCursor( _ ByVal Row As Byte, _ ByVal Column As Byte) Dim position as byte If (Row < 1) Then Row = 1 ElseIf (Row > MAXROW) Then Row = MAXROW End If If (Column < 1) Then Column = 1 ElseIf (Column > MAXCOLUMN) Then Column = MAXCOLUMN End If column = column - 1 ' the display uses zero as the first position #if MAXCOLUMN = 16 if row = 1 then position = 0 elseif row = 2 then position = 64 elseif row = 3 then position = 16 else position = 80 end if #elseif MAXCOLUMN = 20 if row = 1 then position = 0 elseif row = 2 then position = 64 elseif row = 3 then position = 20 else position = 84 end if #endif position = position + column + 128 LCDPutByte(254) LCDPutByte(Position) End Sub '------------------------------------------------------------------------------- Public Sub LCDPutCell( _ ByVal Value As Byte, _ ByVal Row As Byte, _ ByVal Column As Byte) ' Writes a byte to the cell specified by the row and column number. ' ' Upon return, the cursor position is undefined. Call LCDMoveCursor(Row, Column) Call LCDPutChar(Value) End Sub '------------------------------------------------------------------------------- Public Sub LCDPutBrightness( _ ByVal Value As Byte) 'SET THE BACKLIGHT BRIGHTNESS 'THE NETMEDIA(TM) DISPLAYS TAKE A VALUE OF 0-255, SO IT NEEDS TO BE TRANSLATED 'TO THE 128-157 LEVEL OF THE SPARKFUN UNITS VALUE = 128 + VALUE\8 IF VALUE > 157 THEN VALUE = 157 END IF Call LCDPutByte(124) Call LCDPutByte(Value) End Sub '------------------------------------------------------------------------------- Public Sub LCDPutContrast( _ ByVal Value As Byte) 'THESE DISPLAYS HAVE NO SOFTWARE CONTRAST SETTING. 'SO JUST RETURN, HAVING DONE NOTHING End Sub '------------------------------------------------------------------------------- Public Sub LCDPutCursorStyle( _ ByVal Value As CursorStyle) Call LCDPutByte(254) Call LCDPutByte( CByte(Value) ) End Sub '------------------------------------------------------------------------------- '///////////////////////// MACHINE DEPENDENT FEATURES ////////////////////////// Public Sub LCDDefineCustomCharacter( _ ByVal CharacterNumber As Byte, _ BitMap() As Byte) ' Allows characters 0 .. 7 to be defined as custom bitmaps. Each character ' is 8 pixels high and 5 pixels wide. ' BitMap is an 8 byte array. Element 1 of the array corresponds to the top ' row of pixels, element 2 is the next row down, and so forth. Pixel values ' are taken from the lower 5 bits of each byte. The upper 3 bits are ignored. Dim N As Byte Dim Address As Byte Const AddressOffset As Byte = &H40 ' Check for legal character number. If (CharacterNumber < 0) Or (CharacterNumber > 7) Then Exit Sub End If ' Map the character to the internal address. Address = (CharacterNumber * 8) + AddressOffset Call LCDPutByte(254) Call LCDPutByte(Address) For N = 1 To 8 Call LCDPutByte(BitMap(N)) Next call LCDMoveCursor(1,1) End Sub '------------------------------------------------------------------------------- Public Sub LCDPutTabSize( _ ByVal Value As Byte) 'THESE DISPLAYS HAVE NO SOFTWARE TAB SIZE SETTING. 'SO JUST RETURN, HAVING DONE NOTHING End Sub '///////////////////////// MACHINE DEPENDENT FEATURES ////////////////////////// '-------------------------------------------------------------------------------