'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 'USING THE SPARKFUN ELECTRONICS SERIAL LCD ADAPTER. ' This module handles a single serial port For an LCD device. The module will ' handle 1 port at a time. After opening the port, you can switch to a ' different port at any time by closing and re-opening the port. ' Allocate space For 1 Byte buffers, plus 9 Bytes of overhead. Private Const InputQueueSize As Integer = 15 Private Const OutputQueueSize As Integer = 15 Private InputQueue(1 To InputQueueSize) As Byte Public OutputQueue(1 To OutputQueueSize) As Byte Private TimeoutLimit As Single Private mPortNumber As Byte Private PortIsOpen As Boolean '------------------------------------------------------------------------------- Public Sub LCDPutStr( _ ByVal Tx As String) ' This procedure transmits a text string For display on the LCD. Dim N As Integer Dim B As Byte Dim Length As Integer Length = Len(Tx) If (Length > 0) Then For N = 1 To Length B = ToByte(Asc(Tx, N)) Call PutQueueByte(OutPutQueue,B) Next End If End Sub '------------------------------------------------------------------------------- '------------------------------------------------------------------------------- Public Sub LCDInitializeSerialPort() ' This procedure initializes the serial port, and must be Called beFore any ' other Subprogram in this module. ' mPortNumber = 0 PortIsOpen = False TimeoutLimit = 0.01 End Sub '------------------------------------------------------------------------------- Public Sub LCDOpenSerialPort( _ ByVal PortNumber As Byte, _ ByVal Baud As long, _ ByVal InputPin As Byte, _ ByVal OutputPin As Byte) ' Opens a serial port at the specified baud rate. The port is connected to ' InputPin and OutputPin For ports that allow arbitrary pin numbers. ' Otherwise fixed pins are used, and InputPin and OutputPin are ignored. PortIsOpen = False ' Check port number. If (PortNumber < 1) Or (PortNumber = 2) Then Exit Sub End If Call OpenQueue(OutputQueue, OutputQueueSize) Call OpenQueue(InputQueue, InputQueueSize) ' no parity, 8 data bits. 'inverted logic = &H80 mask:1xxx-xxxx 'non-inverted logic = &H00 'even parity = &H30 mask:0011-0000 'odd parity = &H20 mask:0010-000 'no partiy = &H00 mask:0000-0000 '7 bits = &H07 mask:0000-0111 '8 bits = &H08 mask:0000-1000 'Netmedia Default: non-inverted, 8 bits... 'so, combining masks: Inv-8-N = 1000-0000 + 0000-0000 + 0000-1000 = 1000-1000 if (PortNumber > 3) then 'comchannels is necessary if ports other than just com3 are used. 'if multiple coms are used other than com1 then the numeral 1 needs to be changed Call comchannels(1,cint(baud)) End if If (PortNumber >= 3) Then 'Call DefineCom(portnumber, InputPin, OutputPin, bx1000_1000) Call DefineCom(portnumber, InputPin, OutputPin, bx0000_1000) End If Call OpenCom(PortNumber, Baud, InputQueue, OutputQueue) mPortNumber = PortNumber PortIsOpen = True TimeoutLimit = 0.01 End Sub '------------------------------------------------------------------------------- Public Sub LCDCloseSerialPort() 'This procedure shuts down the serial port. Call CloseCom(mPortNumber, InputQueue, OutputQueue) Call ClearQueue(InputQueue) Call ClearQueue(OutputQueue) mPortNumber = 0 PortIsOpen = False End Sub '------------------------------------------------------------------------------- Public Sub LCDPutByte( _ ByVal Value As Byte) ' This procedure transmits a Byte to the LCD directly, without translation. Call PutQueueByte(OutputQueue, Value) End Sub '------------------------------------------------------------------------------- Public Sub LCDPutCommand( _ ByVal Value As LCDCommandType) 'This procedure transmits an LCD-specific command to the device. Dim Temp As Byte Temp = CByte(Value) Call PutQueueByte(OutPutQueue, 254) Call PutQueueByte(OutputQueue, Temp) End Sub '------------------------------------------------------------------------------- Public Sub LCDPutChar( _ ByVal Value As Byte) ' This procedure transmits a character For display on the LCD. Dim B As Byte 'Translate character to Byte. B = ToByte(Value) Call PutQueueByte(OutputQueue, B) End Sub '------------------------------------------------------------------------------- Public Sub LCDPutTimeoutLimit( _ ByVal NewTimeoutLimit As Single) ' This procedure defines the time limit imposed on serial input operations ' For which a timeout limit applies. If (NewTimeoutLimit >= 0!) Then TimeoutLimit = NewTimeoutLimit Else TimeoutLimit = 0! End If End Sub '------------------------------------------------------------------------------- Public Sub LCDGetByte( _ ByRef Value As Byte, _ ByRef Success As Boolean) 'Inputs a Byte from the serial port, if available. Returns regardless. The 'Success flag is set depEnding on whether a Byte is available. ' Find out if anything is in the queue. Success = StatusQueue(InputQueue) ' If data is in the queue, extract it. If (Success) Then Call GetQueue(InputQueue, Value, 1) Else Value = 0 End If End Sub '------------------------------------------------------------------------------- Public Sub LCDGetIntegerTimed( _ ByRef Value As Integer, _ ByRef TimedOut As Boolean) ' This procedure receives an Integer. The procedure waits until the data is ' received, or until TimeoutLimit is reached, whichever comes first. The ' TimedOut flag is set accordingly. Call GetQueue(InputQueue, Value, 2, TimeoutLimit, TimedOut) End Sub '------------------------------------------------------------------------------- Public Sub LCDGetByteTimed( _ ByRef Value As Byte, _ ByRef TimedOut As Boolean) ' This procedure receives a Byte. The procedure waits until the data is ' received, or until TimeoutLimit is reached, whichever comes first. The ' TimedOut flag is set accordingly. Call GetQueue(InputQueue, Value, 1, TimeoutLimit, TimedOut) End Sub '------------------------------------------------------------------------------- Private Function ToByte( _ ByVal Value As Byte) As Byte ' This Function translates a character to be displayed, and translates it ' into a Byte. 'Special character mapping If (Value = ASCIITilde) Then ToByte = LCDTilde ElseIf (Value = ASCIIbackslash) Then ToByte = LCDBackslash Else ToByte = Value End If End Function '-------------------------------------------------------------------------------