Shop OBEX P1 Docs P2 Docs Learn Events
Serial (backlit) and Parallel LCD support for the SX28 on a PDB — Parallax Forums

Serial (backlit) and Parallel LCD support for the SX28 on a PDB

T&E EngineerT&E Engineer Posts: 1,396
edited 2005-11-15 01:19 in General Discussion
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.

·
«1

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-12 04:30
    Tim,

    ·· 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
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-11-12 05:39
    http://www.sxlist.com/techref/ubicom/virtperf.htm
    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
    ·
  • BeanBean Posts: 8,129
    edited 2005-11-12 13:34
    Tim,
    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.
    ·
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2005-11-12 13:48
    Thanks for all the information.

    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
  • ForrestForrest Posts: 1,341
    edited 2005-11-12 15:37
    If you want to control a serial LCD with an SX28 you'll need to first program the SX28 without a resonator installed and then install a resonator for the SX28 after programming. The reason is the internal clock on the SX28 isn't accurate enough for serial communication at a fixed baud rate.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-12 15:51
    Tim,

    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
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-12 18:20
    Peter, et al,

    ·· 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
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2005-11-12 19:33
    I really appreciate the support provided. However, what I will work on first is SX/B (maybe assembly too...later) for the Serial LCD (has SX28 surface mount circuit embedded already). Since all that is available is BS2 example code (well done), it needs SX28 (SX/B and / or assembly) code written too. I don't think this will be too difficult once I look at SX/B first. Once finished I will tackle the 4 bit conversion of BS2 code into SX/B (maybe assembly...later).

    Thanks again to all.

    Timothy Gilmore
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-12 22:28
    Tim,

    ·· 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
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2005-11-13 02:10
    SX/B "Serial" LCD firmware is written and working - No BS2 required.

    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
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-13 13:42
    Tim,

    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
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2005-11-13 14:27
    Jon,

    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
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2005-11-13 14:39
    Jon,

    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
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-13 15:20
    Your program probably works but is consuming tons of code space because SX/B is turning every instance of SEROUT into several lines of assembly code. If you move SEROUT to a subroutine, then it only gets expanded once and you save a lot of code space. And, as I showed above, you can add features when you encapsulate "big" SX/B functions into a subroutine. There are several examples in the help file that demonstrate this.

    See page 23 of the SX manual for a complete description of the IDE controls.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • BeanBean Posts: 8,129
    edited 2005-11-13 15:24
    Tim,
    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.
    ·
  • John CoutureJohn Couture Posts: 370
    edited 2005-11-13 17:59
    Tim,

    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:
    • LCD-4bit-Demo.bmp - the schematic
    • LCD-4bit-Demo.sxb - the main program
    • LCD-sxt - the LCD subroutines
    • LCD-con.sxt - the LCD constants
    • LCD-sub.sxt - the LCD subroutine declarations
    • LCD-var.sxt - the LCD variables
    • HD44780.pdf - datasheet

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-11-13 19:28
    Chris Savage (Parallax) said...
    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!· =)·
    =)· That was what I was referring to back in my message.· Guess I should've mentioned why you should do that too, huh?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2005-11-13 20:46
    I made the SEROUT into a Subroutine as Jon stated.

    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
  • John CoutureJohn Couture Posts: 370
    edited 2005-11-13 22:51
    Tim,

    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
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2005-11-13 23:22
    John,

    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
  • John CoutureJohn Couture Posts: 370
    edited 2005-11-14 00:17
    No, I made that mistake also. SX/B does all of the grunt work for you. You just have to keep track of how many variables you have and the compiler does the rest. Learn how to use Arrays and Interrupts .... its worth the effort! Opens up LOTS of new possibilities.

    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
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2005-11-14 00:54
    Here is Revision B of the SX/B Serial LCD program (attached).

    Thanks to all!

    Timothy Gilmore
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-14 04:27
    You're getting away with things in this program that you won't in some bigger programs -- what you should do is declare your subroutines. This lets the subroutine exist anywhere in memory and lets the compiler do basic syntax check of your subs for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Ken GraceyKen Gracey Posts: 7,401
    edited 2005-11-14 05:24
    Jon,

    I don't understand what you mean by declaring subroutines. Could you provide an example?

    Thanks,

    Ken Gracey
  • Mike CookMike Cook Posts: 829
    edited 2005-11-14 12:30
    On A windows PC:

    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

    smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "OEM NMEA GPS Module" Now available on ebay for only $19.99

    Product web site: http://www.allsurplus.net/Axiom/

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-14 12:49
    As of version 1.2 we have added the ability to declare a subroutine to the compiler; this helps the programmer in two ways:

    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
  • T&E EngineerT&E Engineer Posts: 1,396
    edited 2005-11-14 13:19
    If you see in the new Revision B program (attached in my last post), I did declare my subroutines as John stated. However, I did not put in min and max parameter statements after the SUB listings.

    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.
  • Mike CookMike Cook Posts: 829
    edited 2005-11-14 13:41

    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 WilliamsJon Williams Posts: 6,491
    edited 2005-11-14 16:22
    Perhaps the attached program will help -- I took our BS2 demo for the Serial LCD and directly ported it to SX/B.· The demo shows how to declare subroutines (to maximize code space and flexibility) runs exactly like the BS2 version.· I don't have a back-lit LCD so if someone will verify that the BL flashes at the end of the program I'd appreciate it.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 11/14/2005 4:31:14 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-14 18:38
    Just for fun I wrote another version of LCD_OUT that works with a byte, string constant, or label (that points to DATA string).· Note that it does compile SEROUT twice, but I still think this is a decent routine to have in your bag:

    ' 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
Sign In or Register to comment.