Serial (backlit) and Parallel LCD support for the SX28 on a PDB
T&E Engineer
Posts: 1,396
I just got the SX Tool Kit Pro (with a Professional Development board). I also bought the 2x16 backlit Serial LCD from Parallax (built in SX28 controller). I also bought a 2x16 non backlit parallel LCD. In case I could not find support for one, I would have the other to start with.
The problem I have is not finding any program for the SX28 for either. What I found wants to have a BS2 connected (only BS2 software provided - nothing for SXB with schematics).
Please help if you can.
Thanks.
·
The problem I have is not finding any program for the SX28 for either. What I found wants to have a BS2 connected (only BS2 software provided - nothing for SXB with schematics).
Please help if you can.
Thanks.
·
Comments
·· Perhaps you can be the first to write an SX/B code for using the Parallel Display!· It shouldn't be too hard to convert the BS2 code over to it.· It's really a matter of sending Data or Instructions to the LCD by setting the proper control lines (RS and R/W), making the data available to the 4-bit interface (DB4-DB7) and toggling the Enable line (Twice for each, since it's 4 bit).· Put the whole thing in a subroutine so that all you have to do is set a variable and call it!· ·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Scroll down to 8bit LCD interface, there is also a 4bit LCD interface
An serial LCD example is in the SX/B IDE help section.
regards peter
·
In the help file there is a "Serial LCD" project. This is NOT about using a serial LCD, it is about MAKING a serial LCD using a standard parallax LCD.
That should get you started.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
Those that would give up freedom for security will have neither.
·
Perhaps I will be the first to create this. We'll see.
I guess what I was looking for is a way to control either the parallel or serial (sx28 modified already - it looks like) directly by the SX28 without having to use a BS2. If nothing is out there, that's fine but I just would have thought that it would have been done already since the PDB supports both the BS2 and SX28 (having an LCD parallel port).
I'll see what I can come up with after I learn the SX28 some more. So much to remember with SX28 Assembly language. This will take some time...
I have already read through the downloaded manual "Exploring the SX microcontroller with Assembly and Basic v3".
Are·there any other guides / books that go into the SX/B BASIC coding more than just the help file?
Thanks again,
Timothy Gilmore
You'll find a few examples in the SX/B help file that use the SEETRON serial LCD -- this will give you a starting point for using the Parallax LCD (you will need to make some modifications, but the examples show how to send bytes). And as Bean pointed out, there is a full-fledged DIY serial LCD project in the help file as well, so that will show you how to do 8-bit parallel interfacing.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
·· Yes, there is an SX/B LCD example using 8-bit mode (Which I prefer), but for the 4-bit mode (Using less I/O) there is no SX/B example to complement our BS2 version.· It's slightly more difficult to do than 8-bit, since you have to do two 4-bit transfers for each byte sent.· By doing this, Tim may learn more about using the SX/B compiler than just copying the existing 8-bit example, while at the same time saving some I/O (Just in case).·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Thanks again to all.
Timothy Gilmore
·· If you look carefully at the many BS2 4-bit LCD programs, you will notice that the ones Parallax has written have the code for sending the data out to the LCD stuffed into a subroutine.· Both nibbles of the data are sent out to the LCD during each transaction, making it fairly easy to understand.· I think you can do it, and then get fame for it!· · At least here on the forums!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
I have written SX/B code to work with·a SX28 (NO BS2 REQUIRED) and the Parallax Serial LCD. Either Parallax model (#27976 Non Backlit) or (#27977 Backlit version) will work well. It works almost identically to the Parallax docomentation with example subroutines provided to display a DATA message , create custom characters and turn the backlight off or on. Other subroutines can be easiliy created using my example subroutines and the Parallax documentation.
http://www.parallax.com/detail.asp?product_id=27976
http://www.parallax.com/detail.asp?product_id=27977
It was a good first SX/B project to work on.
Let· me know what you think and if you want to use it on the Parallax website (as is or modified is ok).
Thanks,
Timothy Gilmore
You'll find as your programs start to grow that you'll want to embed SEROUT into a subroutine as we do in the help file demos.· Why?· Because SX/B is an inline (some call macro) compiler, and each high-level command (like SEROUT) is directly translated into assembly.· So in your program, you have lots of redundant assembly code.· The cool thing about embedding big commands into a subroutine is that you save code space and you can add features.· This subroutine, for example, will transmit one character, or if specified, that same character up to 255 times.
' Use: TX_BYTE theByte {, repeats }
' -- first parameter is byte to transmit
' -- second (optional) parameter is number of times to send
TX_BYTE:
· temp1 = __PARAM1····························· ' char to send
· IF __PARAMCNT = 1 THEN······················· ' if no repeats specified
··· temp2 = 1·································· ' - set to 1
· ELSE
··· temp2 = __PARAM2
· ENDIF
· DO WHILE temp2 > 0
··· SEROUT Sout, Baud, temp1··················· ' send the character
··· DEC temp2
· LOOP
· RETURN
If you think about it, when we do this we're becoming somewhat Stamp-like.· Inside the BASIC Stamp is·one core assembly routine that gets called from our program as we need it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I really appreciate the insight to this. As I am new to this...Do I "Compile" or "Program" the SX/B code first and then look at the assembly language to change it. What if I re-"compile" or "program" it? Does it change my program?
Can you explain the process to which you are refering to?
Thanks,
Timothy Gilmore
Are you just saying that I should rewrite the SX/B code to use one subroutine for the SEROUT process and this would fix the problem...or do I have to go into the actual .SRC code and change that?
PS: What does "Compile", "Program" and "Run" do?
When I click on Compile, I don't see it doing anything.
When I click on Program, it erases and reprograms the SX28.
When I click on Run, it erases and reprograms the SX28 but it also stated that the SX-Key is generating a 4 MHz signal (can't remember exact wording).
Thanks,
Timothy Gilmore
See page 23 of the SX manual for a complete description of the IDE controls.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
It won't do any good to change the .SRC file, because when you "compile" again it will get recreated.
Jon isn't saying to change the code generated by the compiler, he's saying to put the SX/B SEROUT command inside an SX/B subroutine.
If you want to put assembly in your SX/B program you can prefix each assembly line with a "\" or use the ASM...ENDASM commands.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
Those that would give up freedom for security will have neither.
·
If I may so humbly add to this conversation.· Attached is a schematic and code for sending data to·an LCD using the 4 bit technique.· I designed the code to handle any geometry (1x16, 4x20, etc) LCD and also demonstrate a couple of techniques that Jon Williams, Bean, Gunther·Daubach·and Aristides Alvarez have presented on things such as interrupts, arrays and such.· These guys are the greatest!
Also included is a data sheet on the Hitachi HD44780 chip (Most LCD's are based on this chip)· and a links to an article from Practical Electronics that talks about how to program an LCD.
The file is a zip file because it consists of seven files:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
However, now it appears that I am still running out of program space. I can't believe this as the program is not that big. Do I have to change to another memory bank or something? I have attached my SX/B code that programs fine. However, if you un-comment the
char3 DATA line and / or the CustomCharacter3 subroutine and try to program, it comes back with an error message:
Line 216, Error 44, Pass 2: Address 260 is not within lower half of memory page.
What does this exactly mean and how do I fix it besides commenting out my program?
Thanks,
Timothy Gilmore
There is indeed a limited of variables that you can have with the SX (SX28=20 and SX48=18). However, the good news is that you can reuse variables by using aliases (see SX/B under HELP / Reference / Aliases). Another trick is to use arrays. I used both tricks in my code above.
Also, you need to declare you surbroutines and how many parameters they should expect (HELP / Reference / Definitions / Subroutine Declaration)
Add the following lines right after your BAUD con statement.
DisplayingText SUB
CustomCharacter0 SUB
CustomCharacter1 SUB
CustomCharacter2 SUB
CustomCharacter3 SUB
Lighton sub
lightoff sub
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College
That worked. I have been reading all day about memory pages, Assembly stuff and not quite getting a good picture. It's nice when you can call on the forum and get great support.
PS: I put the SUB·statements you provided·in the 'Subroutine Declarations' area of my program which is listed in the SX/B template. So that's what that was for.
Do we have switch pages in memory using Assembly MOV FSR or BANK type commands for subroutines or does the SUB statements do that?
Thanks again!
Timothy Gilmore
I did the LOAD commands because I was getting tired of VERY LONG programs. By breaking it up into modules, I can debug that portion then forget about it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College
Thanks to all!
Timothy Gilmore
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
I don't understand what you mean by declaring subroutines. Could you provide an example?
Thanks,
Ken Gracey
Start>Programs>Parallax Inc>SX-Key v3.1>SX-Key v3.1
Menu Bar: Help>SX/B Help
SX/B Online Help>Reference>Definitions>Subroutine Declaration
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"OEM NMEA GPS Module" Now available on ebay for only $19.99
Product web site: http://www.allsurplus.net/Axiom/
1) Subroutines can exist anywhere in memory now
2) The compiler will check for the proper number of parameters.
In one of the posts above I showed a the subroutine code for TX_BYTE.· Here's how that's declared to the compiler:
TX_BYTE··· SUB··· 1, 2
The "1, 2" section tells the compiler that this subroutine requires one parameter, and could take two.· So if you do something like this:
· TX_BYTE aVal, bVal, cVal
The compiler will flag it as too many parameters.· Notice too that I didn't need to use GOSUB -- this is optional with declared subroutines and saves a bit of typing.· Really, it's like adding your own commands.
For an example, have a look at this [noparse][[/noparse]early] version of the Serial Inkjet Printer drive code.
··· http://forums.parallax.com/attachment.php?attachmentid=39038
You'll see a bunch of declared subroutines -- some with no parameters, so with mandatory and optional parameters.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
When I try to enter them in I get an error message:
Error 10, Pass 1: Invalid Number of Parameters.
If I leave them out, it compiles fine.
(e.g.·· SEROUTSXB SUB 1, 3) -- gets the error
(e.g.·· SEROUTSXB SUB 3) --- gets the error
(e.g.·· SEROUTSXB SUB) -- works fine.
Any guidance?
Thanks,
Timothy Gilmore
See Rev C, attached - which compiles fine.
Timothy,
Put this in your "varables" section of your program:
temp1··· VAR···· BYTE······ ·' subroutine work vars
Redefine your:
SEROUTSXB SUB
to:
SEROUTSXB SUB 1··········· ' Subroutine has one parameter passed
Modify:
SEROUTSXB:
· SEROUT TxPin, Baud, char
· RETURN
to:
SEROUTSXB:
· temp1 = __PARAM1·················· ' Capture the passed byte
· SEROUT TxPin, Baud, temp1··· ' Tx·byte
· RETURN········································ ' return to caller
Now replace all of your:
GOSUB SEROUTSXB
With
SEROUTSXB 13······· ' transmits a carrage return
It would be better to define carrage returns or whatever in your constants section like:
Cr··· CON··· 13······· ' ASCII Carrage Return
This way you don't have to assign char before you call you SUB·and you could use a statement like:
SEROUTSXB·Cr······· ' transmits a carrage return
If you look at some of Jon's examples, that use subroutines, you'll notice that he defines temp1 and others as work variables. These work varables get assigned by the __PARAMx Aliases, with parameters passed to the subroutine, see "SX/B Online Help>Reference>Aliases>SX/B Variables"
Mike
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"OEM NMEA GPS Module" Now available on ebay for only $19.99
Product web site: http://www.allsurplus.net/Axiom/
Post Edited (Mike Cook) : 11/14/2005 2:57:42 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 11/14/2005 4:31:14 PM GMT
' Use: LCD_OUT [noparse][[/noparse] aByte | string | label ]
' -- "aByte" is single-byte constant or variable
' -- "string" is an embedded literal string
' -- "label" is DATA statement label for stored z-String
LCD_OUT:
· temp1 = __PARAM1···························' byte or offset
· IF __PARAMCNT = 2 THEN·················· ··' string specified?
··· temp2 = __PARAM2·························' yes, save base
··· DO
····· READ temp2 + temp1, temp3············ ·' read a character
····· IF temp3 = 0 THEN EXIT················ ' if 0, string complete
····· SEROUT LcdTx, LcdBaud, temp3········· ·' send the byte
····· INC temp1···························· ·' point to next character
····· temp2 = temp2 + Z···················· ·' update base on overflow
··· LOOP
· ELSE
··· SEROUT LcdTx, LcdBaud, temp1·············' transmit to LCD
· ENDIF
· RETURN
This subroutine could replace LCD_OUT and LCD_STR from the other program.· Note that the "count" feature is no longer applied, so instead of this:
· LCD_OUT "*", 5
you would do this:
· LCD_OUT "*****"
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Post Edited (Jon Williams (Parallax)) : 11/14/2005 6:43:23 PM GMT