|
|
| Author |
Message |
pcleats
Joined: 12 Dec 2005
Posts: 35
|
|
Posted: 11 July 2006, 17:39 PM Post subject: Seetron BPI-216 |
|
|
Hello all,
I just received my new ZX-24, and now I would like to interface it with a Seetron BPI-216. Does anybody have some sample code so I could see how to best send data to this LCD display.
Thanks for the help
Patrick |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 11 July 2006, 19:09 PM Post subject: |
|
|
Below is some code (untested) that may help you to get started. I put it together pretty quickly so I may have missed something or misinterpreted the documentation for the device. It does compile without error, though.
[Edit: the code below was modified to use inverted serial mode which the LCD requires.]
Not all of the display functions that you might want are implemented but you should be able to add to what is here. Note that this code contains a test stub that can be included. Alternately, you can place the test code in another module.
| Code: | ' definitions for the serial connection
Private Const LCD_Port as Byte = 3
Private Const LCD_Speed as Long = 9600
Private Const LCD_Serial_Mode as Byte = &H88 ' 8-bit, inverted
Private Const LCD_Tx_Pin as Byte = 5
' definitions for the BPI-216
Private Const LCD_Cmd_Prefix as Byte = 254
Private Const LCD_Cmd_Clear as Byte = 1
Private Const LCD_Cmd_Cursor_Off as Byte = 12
Private Const LCD_Cmd_Cursor_Block as Byte = 13
Private Const LCD_Cmd_Cursor_Underline as Byte = 14
' the output queue
Private oq(1 to 20) as Byte
' This is a test stub. Change #if 1 to #if 0 to omit it.
#if 1
Sub Main()
Call LCD_Init()
Call LCD_DisplayStr("Hello, world!")
Call LCD_DisplayStrAt("1234", 2, 7)
End Sub
#endif
'-------------------------------------------------------------
'
'' LCD_Init
'
' Initialize the display.
'
Public Sub LCD_Init()
' initialize the queue and comm port
Call OpenQueue(oq, SizeOf(oq))
Call DefineCom(LCD_Port, 0, LCD_Tx_Pin, LCD_Serial_Mode)
Call OpenCom(LCD_Port, LCD_Speed, 0, oq)
Call Delay(0.7)
' clear the display
Call LCD_Clear()
' uncomment one or the other of the following lines
' depending on which cursor type is desired
Call sendCmd(LCD_Cmd_Cursor_Underline)
' Call sendCmd(LCD_Cmd_Cursor_Block)
End Sub
'-------------------------------------------------------------
'
'' LCD_Clear
'
' Clear the display. A 1 mS delay following the command
' is necessary only at 9600 baud.
'
Sub LCD_Clear()
Call sendCmd(LCD_Cmd_Clear)
Call Delay(1.0e-3)
End Sub
'-------------------------------------------------------------
'
'' LCD_DisplayStr
'
' Send the characters of a string to the display. Note
' that this is done character by character instead of
' attempting to send the entire string to the queue at
' once in order to avoid a deadlock situation if the
' string happens to be longer than the data space of
' the queue.
'
Public Sub LCD_DisplayStr(ByVal str as String)
Dim strLen as Integer
Dim i as Integer
strLen = Len(str)
For i = 1 to strLen
Call PutQueueByte(oq, Asc(str, i))
Next i
End Sub
'-------------------------------------------------------------
'
'' LCD_DisplayStrAt
'
' Display a string at a given position. The row/column
' values are 1-based.
'
Public Sub LCD_DisplayStrAt(ByVal str as String, ByVal row as Byte, ByVal col as Byte)
Call LCD_SetPos(row, col)
Call LCD_DisplayStr(str)
End Sub
'-------------------------------------------------------------
'
'' LCD_DisplayChar
'
' Send a character to the display.
'
Public Sub LCD_DisplayChar(ByVal ch as Byte)
' don't send the command prefix code
If (ch <> LCD_Cmd_Prefix) Then
Call PutQueueByte(oq, ch)
End If
End Sub
'-------------------------------------------------------------
'
'' LCD_DisplayCharAt
'
' Display a character at a specified position. The
' row and column numbers are 1-based.
'
Public Sub LCD_DisplayCharAt(ByVal ch as Byte, ByVal row as Byte, ByVal col as Byte)
' don't send the command prefix code
If (ch <> LCD_Cmd_Prefix) Then
Call LCD_SetPos(row, col)
Call PutQueueByte(oq, ch)
End If
End Sub
'-------------------------------------------------------------
'
'' LCD_SetPos
'
' Position the cursor at the row/column indicated. Both
' values are 1-based. If an invalid row or column are
' requested, no action is taken.
'
Public Sub LCD_SetPos(ByVal row as Byte, ByVal col as Byte)
If ((row >= 1) And (row <= 2) And _
(col >= 1) And (col <= 16)) Then
Call sendCmd(IIF(row = 1, 128, 192) + col - 1)
End If
End Sub
'-------------------------------------------------------------
'
'' sendCmd
'
' Send a command code to the display preceded by the
' command prefix code.
'
Private Sub sendCmd(ByVal cmd as Byte)
Call PutQueueByte(oq, LCD_Cmd_Prefix)
Call PutQueueByte(oq, cmd)
End Sub |
Last edited by dkinzer on 12 July 2006, 15:16 PM; edited 1 time in total |
|
| Back to top |
|
 |
pcleats
Joined: 12 Dec 2005
Posts: 35
|
|
Posted: 11 July 2006, 20:31 PM Post subject: Nope not working |
|
|
Hey Don,
I just tried the code it does compile, and download, but I get nothing on the display.
Sorry for the dumb question, but what pin is the data going out on? I am used to the basic Atom, and its different.
Thanks for the help
Patrick |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 11 July 2006, 20:44 PM Post subject: Re: Nope not working |
|
|
| pcleats wrote: | | ...what pin is the data going out on? |
Near the top of the code you'll find a constant definition that controls the pin number.
| Code: | | Private Const LCD_Tx_Pin as Byte = 5 |
There are other constant definitions near the top that you may need to modify as well. The serial port is configured for non-inverted output. I believe that is what the Seetron LCD needs but I may be wrong.
There are lots of things that may prevent it from working. Your best bet, I think, is to go through the code that I offered, figure out what its trying to do, and make any changes that you think are necessary. If some of the code isn't clear, post a question and I'll do my best to answer it.
As I mentioned, there are other functions that you might want to add. When you get it working, post the result in the Files forum, if you please. |
|
| Back to top |
|
 |
pcleats
Joined: 12 Dec 2005
Posts: 35
|
|
Posted: 11 July 2006, 22:33 PM Post subject: BPI-216 |
|
|
Don,
Let me get this stright I am confused about the software com port
First you need to create an the output Queue
Then you need to open a Queue
Then Define a Com Port
Open a Com Port
Then send the data from the Queue
I shortened up your code and all this is doing is sending garbage to the display.
Sorry again if I sound new to this I am.
Thanks Patrick
' the output queue
Private oq(1 to 20) as Byte
' This is a test stub. Change #if 1 to #if 0 to omit it.
Sub Main()
Call LCD_Init()
Call LCD_DisplayStr("Hello, world!")
End Sub
'-------------------------------------------------------------
'
'' LCD_Init
'
' Initialize the display.
'
Public Sub LCD_Init()
' initialize the queue and comm port
Call OpenQueue(oq, SizeOf(oq))
Call DefineCom(3, 0, 5, &H08)
Call OpenCom(3, 2400, 0, oq)
Call LCD_Clear()
End Sub
Sub LCD_Clear()
Call sendCmd(1)
End Sub
Public Sub LCD_DisplayStr(ByVal str as String)
Dim strLen as Integer
Dim i as Integer
strLen = Len(str)
For i = 1 to strLen
Call PutQueueByte(oq, Asc(str, i))
Next i
End Sub
Private Sub sendCmd(ByVal cmd as Byte)
Call PutQueueByte(oq, 254)
Call PutQueueByte(oq, cmd)
End Sub |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 11 July 2006, 23:04 PM Post subject: Re: BPI-216 |
|
|
| pcleats wrote: | | I am confused about the software com port. First you need to create an the output Queue [...] |
Perhaps the best way to understand the setup that is required is to work your way backward from the OpenCom() routine. That routine requires a channel number, a speed and 1 or 2 queues. Before you can call OpenCom(), you must define the configuration of the channel that you're opening. That means that you have to call DefineCom() specifying the Rx and Tx pins and operating mode for a particular channel.
Moreover, the queues have to be properly initialized before calling OpenCom(). That means that you must first call OpenQueue(). Finally, the byte arrays that hold the queues must be defined before you call OpenQueue().
Note that it does not matter whether you call OpenQueue() to initialize the queues first or call DefineCom() to define the COM parameters first but both of those initialization steps must be called before invoking OpenCom().
| pcleats wrote: | | [...]all this is doing is sending garbage to the display. |
It's time to employ some problem analysis skills. From reading the code, you can see that it configures the COM port for 9600 baud. The LCD that you have can be configured for either 2400 baud or 9600 baud. If the software configuration doesn't match the hardware configuration, it's not going to work.
The second reason that garbage might be displayed is if the LCD requires inverted serial data and the ZX is sending non-inverted (or vice versa). Looking at the Basic Stamp code again, I now believe that the BPI-216 requires inverted serial data. If that is the case, the fourth parameter to DefineCom() needs to be changed to specify inverted mode. Use &H88 for inverted mode, &H08 for non-inverted mode. |
|
| Back to top |
|
 |
pcleats
Joined: 12 Dec 2005
Posts: 35
|
|
Posted: 12 July 2006, 3:56 AM Post subject: BPI-216 |
|
|
Don,
Thanks for being patient.
Patrick |
|
| Back to top |
|
 |
pcleats
Joined: 12 Dec 2005
Posts: 35
|
|
Posted: 12 July 2006, 13:09 PM Post subject: BPI-216 |
|
|
Don,
Just wanted to let you know that the sample code you provided works just fine when you invert the mode with &H88. Thanks for the help.
Patrick |
|
| Back to top |
|
 |
dkinzer Site Admin
Joined: 03 Sep 2005
Posts: 2593
Location: Portland, OR
|
|
Posted: 12 July 2006, 15:17 PM Post subject: |
|
|
| I edited the original post, adding a constant definition for the serial mode and changing it to inverted. |
|
| Back to top |
|
 |
|