'THIS MODULE IS BASED ON THE NETMEDIA CODE FOR THEIR LCD DISPLAYS 'THE CODE WAS MODIFIED TO TAKE ADVANTAGE OF THE Z-BASIC LANGUAGE FOR THE ZX-24 CPU ' This is an API for the NetMedia Serial LCD2x16 display. Public Enum LCDCommandType FormFeedCmd = 12 ResetControllerCmd = 14 SetGeometryCmd = 15 SetTabSizeCmd = 16 SetCursorPositionCmd = 17 SetContrastCmd = 19 SetBacklightCmd = 20 CommandEscapeCmd = 21 RawDataEscapeCmd = 23 End Enum Public Enum CursorStyle HiddenCursor = &HC BlockCursor = &HD UnderlineCursor = &HE End Enum Public Const MaxRow As Byte = 2 Public Const MaxColumn As Byte = 16 ' 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 Const Dummy As Byte = 32 Const InitialContrast As Byte = 20 ' This is for a worst case condition, just after powering up the LCD. Const PowerupDelay As Single = 1.0 ' A reset takes about 1 s to complete. Const ResetDelay As Single = 1.0 Call LCDInitializeSerialPort Call LCDOpenSerialPort(PortNumber, Baud, InputPin, OutputPin) ' Allow internal LCD initialization. Call Delay(PowerupDelay) ' Clear out garbage. This assumes the LCD is in an undefined state, which ' means it may be expecting characters. Call LCDPutByte(Dummy) Call LCDPutByte(Dummy) Call LCDPutByte(Dummy) Call LCDPutByte(Dummy) Call LCDPutByte(Dummy) Call LCDPutCommand(ResetControllerCmd) Call Delay(ResetDelay) Call LCDClearScreen Call LCDPutContrast(InitialContrast) Call LCDPutBrightness(0) ' 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(FormFeedCmd) ' 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) 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 Call LCDPutCommand(SetCursorPositionCmd) ' Note change from 1 base to 0 base. Call LCDPutByte(Row - 1) Call LCDPutByte(Column - 1) 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) Call LCDPutCommand(SetBacklightCmd) Call LCDPutByte(Value) End Sub '------------------------------------------------------------------------------- Public Sub LCDPutContrast( _ ByVal Value As Byte) Call LCDPutCommand(SetContrastCmd) Call LCDPutByte(Value) End Sub '------------------------------------------------------------------------------- Public Sub LCDPutCursorStyle( _ ByVal Value As CursorStyle) Call LCDPutCommand(CommandEscapeCmd) 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 LCDPutCommand(CommandEscapeCmd) Call LCDPutByte(Address) For N = 1 To 8 Call LCDPutCommand(RawDataEscapeCmd) Call LCDPutByte(BitMap(N)) Next End Sub '------------------------------------------------------------------------------- Public Sub LCDPutTabSize( _ ByVal Value As Byte) Select Case Value ' Only these values are legal. Case 1, 2, 4, 8 ' Null Case Else ' If the value is illegal, do nothing. Exit Sub End Select ' The LCD expects an 8 bit negative number in two's complement format. ' Since we don't have 8 bit signed integers, we need to synthesize the ' internal bit pattern. Value = (Not Value) + 1 Call LCDPutCommand(SetTabSizeCmd) Call LCDPutByte(Value) End Sub '///////////////////////// MACHINE DEPENDENT FEATURES ////////////////////////// '-------------------------------------------------------------------------------