PBasic Serout to Zbasic SerialOut

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
DieselPower
Posts: 3
Joined: 06 June 2008, 21:07 PM

PBasic Serout to Zbasic SerialOut

Post by DieselPower »

I am trying to convert a PBasic program for controlling a serial VFD display over to run on the ZX24n. Here's the problem.

The PBasic command to initialize the display

Code: Select all

SEROUT VFDpin, Baud, [$1b, $40]
My new Zbasic code

Code: Select all

Call SerialOut(&H1B & &H40, VFDpin, Baud)
But it is not actually controlling the LCD, it just displays the commands as a number, I guess the commands are not getting formatted correctly, and are not being received by the lcd as hex. What am I not doing?
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: PBasic Serout to Zbasic SerialOut

Post by dkinzer »

DieselPower wrote:What am I not doing?
There are a couple of issues. Firstly, in an earlier version of your post, you indicated that you were getting a back-end build error. That is caused by a compiler issue that can be worked around.

Code: Select all

Const baud as UnsignedInteger = 9600
Const pin as Byte = 12

#c
#if !defined(ZB_PORT_OUT_REG)
#define ZB_PORT_OUT_REG(p)		PORT ## p
#endif
#endc

Sub Main()
	Call SerialOut(&H1b, pin, baud)
End Sub
Adding the lines that begin with #c and end with #endc will work around the compiler issue - those lines add a needed definition whose absence is causing the back end issue.

Once this is in place, you can modify the program to send multiple characters by specifying the characters to send as a string.

Code: Select all

Const baud as UnsignedInteger = 9600
Const pin as Byte = 12
Const initStr as String = Chr(&H1b) & Chr(&H40)

#c
#if !defined(ZB_PORT_OUT_REG)
#define ZB_PORT_OUT_REG(p)		PORT ## p
#endif
#endc

Sub Main()
	Call SerialOut(initStr, pin, baud)
End Sub
- Don Kinzer
DieselPower
Posts: 3
Joined: 06 June 2008, 21:07 PM

Post by DieselPower »

Thanks Don, I'm sorry I edited my post so many times, I was trying to keep the stuff I didn't think was important out of the way....:) and I figured the compiler error may have been due to some other code problems and didn't want to bring it up if it was. I'll add the C, and go from there, Thanks!
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

DieselPower wrote:I was trying to keep the stuff I didn't think was important out of the way.
In many cases, it is difficult to know what observations are germane to a particular problem. It is probably better to add to your post (either by editing or by another post to the thread) rather than to delete previously posted information.

Even if you later discover that something you originally posted is incorrect it is probably better to make a new post with updated information. Doing so allows others to understand and learn from the progression of events.
- Don Kinzer
Post Reply