Shop OBEX P1 Docs P2 Docs Learn Events
Serial LCD — Parallax Forums

Serial LCD

fzeitgeistfzeitgeist Posts: 20
edited 2005-03-02 17:10 in BASIC Stamp
I am trying to get an example code for programming a serial 4X20 LCD with the BS2p/40. Does any one know where I can find one on the parallax website(I already found one for a parallel LCD).

Thank You.

Comments

  • Erik ArendallErik Arendall Posts: 21
    edited 2005-02-17 17:37
    Who made the LCD??
  • dandreaedandreae Posts: 1,375
    edited 2005-02-17 17:39
    Hello,

    Here is a sample code that will work for you.· You 'll need to change the baud rate to 16624 in the SEROUT command and this will configure it for the BS2p.· This will only work if it has the Hitachi 44780 chip.

    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    www.parallax.com
  • fzeitgeistfzeitgeist Posts: 20
    edited 2005-02-18 00:47
    Hello Dave. I ordered the LCD directly from the parallax website. This model from Matrix Orbital comes with Errata where only two pins are connected to the BS2p/40 chip. Will the above attched code work with the Errata configuration. If not, is there any other sample code that can be used to control the LCD with Errata.

    Thank You.
  • NewzedNewzed Posts: 2,503
    edited 2005-02-18 00:54
    It takes a minimum of 3 pins to run an· LCD - Vdd, Vss and serial.· Do you have a ground wire between your Stamp and the LCD?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester?

    http://hometown.aol.com/newzed/index.html
    ·
  • dandreaedandreae Posts: 1,375
    edited 2005-02-18 00:56
    The sample code that I sent you will work just fine for the LCD that you purchased.· If you have any problems please feel free to e-mail me direct at dandreae@parallax.com.



    Dave

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Tech Support
    dandreae@parallax.com
    www.parallax.com

    ·
  • fzeitgeistfzeitgeist Posts: 20
    edited 2005-02-18 01:48
    Thanx Dave. Is there a schematic for the above code. How have you connected the Keypad, beacuse I too am using 4X4 keypad(grayhill) which I bought from parallax.
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-18 03:49
    www.parallax.com/dl/docs/prod/audiovis/molcd4x20.pdf said...
    The keypad interface takes row/column input and converts it to ASCII characters, which are delivered out
    the RS-232 or I2C port to the associated controller. Note that the keypad is not used to directly control any
    aspect of the operation of the LK204-25, which acts simply as a matrix to serial converter. If you want to
    use the keypad to control the LK204-25 display you must program your controller accordingly.

    Based upon my reading of the specs, there is no special wiring, just use the cable that they sell to plug the keypad into the LCD controller. Key presses are then transmitted to the Stamp on whatever interface you have defined between the LCD controller and the Stamp.

    Jim
  • fzeitgeistfzeitgeist Posts: 20
    edited 2005-02-19 03:22
    I have got the LCD to work. Thank you for you help guys. I have another question. I am going to connect the keypad directly to bs2p40 using a mux. This will allow the user to enter decimal values which will be used to do some calcualtions. The result of these calcualtions will be displayed on the lcd. Has anyone done something similar. If yes, your input will be very helpful.
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-19 03:54
    Just out of curiosity, why go through all the trouble? Since the controller you already own will pass straight ASCII to the Stamp without anything else (other than the interconnect cable of course) that would seem the most straight forward. Unless of course you want to use it as a learning exercise on implementing a row/column keypad interface manually.

    Jim
  • fzeitgeistfzeitgeist Posts: 20
    edited 2005-02-19 04:27
    Yes, I need to know how to implement the keypad manually, because for the second part of my project I will not have an LCD controller. I am going to use the 74C922 to connect the keypad to the Stamp. So if anyone could help with a sample code it will be appreciated.

    Thank You. [noparse]:)[/noparse]
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-19 05:21
    [noparse][[/noparse]edit] Garbage alert! Read this post. Then read my post immediately following before replying or thinking to hard about it. [noparse][[/noparse]/edit]

    I'm somewhat of a novice at the hardware side of things. But this is what I think might work.

    According to the data sheet, the 74C922 passes the key pressed as a 4 bit binary number through 4 data lines. I'd be inclined to start with something along this line:
    dataA     PIN  0
    dataB     PIN  1
    dataC     PIN  2
    dataD     PIN  3
    
    value     VAR  Byte
    
    LOOKUP INA, [noparse][[/noparse]1, 2, 3, 4, ,,, ], value
    
    



    In the above, INA is a nibble which maps to the same space as pins 0-3. There is also INB, C, and D, if you wish to use different pins. The LOOKUP you'll have to figure out for yourself as I don't have the keypad and don't feel like digging up the data sheet. But the concept is to translate the binary code the 74C922 passes you into the actual key pressed on the keypad. I specified "value" as a byte, because you'll probably be wanting to return ASCII codes for the non numeric keys that are pressed. Although you could go with a nibble to save 4 bits if necessary and use tokens for the non numeric keys.

    Jim

    Post Edited (Jim McCorison) : 2/19/2005 3:50:14 PM GMT
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-19 15:49
    Gak! Boy did I mess it up. NSLOOKUP is totally wrong. I realized it just as I was drifting off to sleep. I guess the moral is not to think up programming solutions when tired.

    Anyway, I think the following code will do instead:
    dataA     PIN  0
    dataB     PIN  1
    dataC     PIN  2
    dataD     PIN  3
    
    value     VAR  Byte
    
    keypad    DATA "123A456B789C*0#D"   ' Or whatever the correct sequence is
    
    READ keypad + INA, value
    
    



    The sequence of the characters in the keypad DATA statement is the same as my post above about NSLOOKUP. The key thing is that you map the sequence of the keypad characters with the binary values returned by the data lines.

    Sorry about the earlier brain fart.

    Jim
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-19 16:38
    Also, check out the Nuts & Volts column www.parallax.com/dl/docs/cols/nv/vol4/col/nv97.pdf which shows a project using the 74C922.

    While reviewing the column, I noticed that they used the NSLOOKUP command to solve the translation problem, assigning numeric tokens to the non-numeric keys. So I guess I was on the right track with NSLOOKUP. Although I still like the DATA / READ solution better.

    Jim
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-02-19 22:52
    Jim,

    ·· I have been watching this discussion, and I only just now decided to offer this...I once used the 74C922 in a project a long time ago.· It's been a long time, so I could be wrong, but I believe that was the cause of much grief in a project due to the way it scans the keypad.

    ·· If memory serves the 74C922 continually scans the keypad generating noise.· As I recall, when we first had this problem I replaced that chip with a 74LS374 & 74LS244.· That was fine for what were doing, and later adpated to a Commodore Surplus keyboard that Radio Shack used to carry (Or any C= VIC or 64 keyboard).

    ·· Later when I needed to scan a keypad for the Stamp, I thought about the 74C922, but instead went to the EDE1144 by E-Labs.· This chip is basically a pre-programmed pic, and so it requires a crystal.· However it does not scan the keypad continuously.· Instead it waits for a state change, then performs a scan, reducing EMI noise.· I think the price is less than, or equal to the price of the 74C922, and the EDE1144 can output either 4-bit parallel, or serial (TTL), making a great choice for the BASIC Stamp.· I believe it also has key repeat.

    Just my $.02




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --==<{Chris}>==--
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-20 00:31
    It looks from the block diagram in the data sheet like the 74C922 keeps poking at the keypad based upon the clock frequency. You can get around that by reading the keypad synchronously, but the chip is limited to a speed of 10kHz. SHIFTIN would be great, except the BS2p clocks it at about 43kHz which is way to fast.

    So I guess it depends on how much noise fzeitgeist can tolerate and whether or not the 74C922 is a requirement (i.e. school project) or just the chip in mind.

    Jim
  • fzeitgeistfzeitgeist Posts: 20
    edited 2005-02-20 08:11
    hi everyone. looking at the above posts, I rather stick with the keypad connected dirctly to the LCD controller. one issue though, I did post early that I had got it to work, but not with the keypad. The code dave posted was modified by me to just send characters to the LCD. i still have'nt figured out how to hookup the keypad directly to the LCD. This LCD comes with ERRATA (http://www.parallax.com/dl/docs/prod/audiovis/30058Errata.pdf) and that leaves me clueless as to where the matrix keypad cable is to be attached. any help with that?? also... if any of you have checked out dave's code, can you tell me if the code is assuming the connection of the keypad directly to the lcd controller or not? from what I see the code seems to assumming the direct connection?

    THANK YOU ONCE AGAIN EVERYONE.
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-20 16:48
    The keypad connection is very clearly labeled on page 7 of the manual for the LCD display. If you haven't read it yet, download it from www.parallax.com/dl/docs/prod/audiovis/molcd4x20.pdf and go through it. There is a wealth of information in there which will help you make use of the product you have purchased.

    Jim
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-02-20 22:32
    Jim,

    · Oddly enough, I only just realized that the LCD Display mentioned above has a keypad decoder built-in!· I guess I should've read back a little bit before my first post.· I caught the part about the 74C922 and jumped in.· Well, I'm sure there were some people who may have been reading along and learned about 2 new chips!· smilewinkgrin.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --==<{Chris}>==--
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-20 23:36
    Chris,

    No worries, mate. Fzeitgeist first mentioned the 74C922 anyway as he also wanted to do a version without the LCD module. But I sure learned about a bunch of new stuff which is why I read all of this.

    Jim
  • fzeitgeistfzeitgeist Posts: 20
    edited 2005-02-25 02:04
    Hello Everyone. Thank you for youe help regarding the keypad and the lcd. The program and the hardware are running like a dream.
    BUT.. its not over yet. I am trying to interface athe pcf8583 chip with with the bs2p40. it runs fine when i use the pcf8583 sample program i found on parallax. but i am trying to integrate it with my previous program, where the user is prompted to set the time and date using the lcd and keypad. when i run the program, it says not enough memory, where it points to a variable (VAR) which cannot be send to RAM. any help on this. i guess i need more memory space.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-02-25 15:15
    Have you confirmed this using the Memory Map function?



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --==<{Chris}>==--
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-02-25 21:55
    fzeitgeist,

    The stamp only has 26 bytes for variables. The error you are getting is what happens when you try and exceed this limit. I don't know if multi-bank Stamps like the BS2P have 26 bytes for each bank or not. I'm just a lowly BS2 owner. smile.gif

    You'll need to conserve memory somewhere along the line. Use only as large a variable as you really need. In otherwords, don't use a word variable (2 bytes) for a variable that only counts from 1 to 10, where a nibble (4 bits) would work instead. Also reuse or generalize variable where you can.

    Jim
  • fzeitgeistfzeitgeist Posts: 20
    edited 2005-02-26 08:11
    Thank you fer yer advise. One more thing, bs2p has "scratch ram" ... any idea on how to use that.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-02-26 08:54
    fzeitgeist -

    Take a look in the PBASIC Stamp Manual at the GET and PUT commands.

    Bruce Bates
  • K de JongK de Jong Posts: 154
    edited 2005-02-27 00:14
    fzeitgeist

    The PCF8583 also has about 200 Bytes of spare RAM inside that you could use. If you put a little battery (3V Lithium) or a large capacitor (0.1 to 1 Farad smile.gif to the PCF the extra RAM will not get lost when you switch off the Stamp and the clock will stay running. This way there will be no need to enter time and date every time you start your system.

    Regards,

    Klaus
  • fzeitgeistfzeitgeist Posts: 20
    edited 2005-03-01 18:30
    HI everyone. I have figured out how to get numbers from the keypad and store them on thr scratch pad ram. when i get these numbers from the scratchpad ram and try to multiply them by 10, it displays a wierd number on the DEBUG screen. Remember ,the keypad is connected to BS2P40 via the LCD.
    here is how the code looks like:

    GET 0, temp1
    DEBUG "before temp1 = ", temp1, CR
    temp1 = temp1 * 10
    DEBUG "after temp1 = ", temp1, CR

    'before temp1' displays the number pulled from the scratch pad, for example, if i punched in 1 on the keypad it stores 1 on the scratch pad, then i GET this values and store it in temp1. when i display it using DEBUG it shows 1... but after multiplication a wierd character is displayed. any help on this. btw... temp1 is assigned as a byte.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-03-02 06:34
    The number you have from your keypad is probably an ascii code, so number "1" is really ascii code 49. That is what is in scratchpad and also in your variable temp1 the first time around when it prints correctly on the screen. The debug screen understands ascii codes. Then you multiply it times 10, expecting 1*10=10, but what the Stamp is doing is 49*10=490, and the Stamp truncates that to 234 to fit it into a byte, so what you get is temp1=234. That ascii code displays as th "weird number" you observed.

    Try this, to convert the key to a number that multiplies the way you expect, and display it using the DEC modifier.

    GET 0, temp1
    temp1=temp1-48 ' convert to number
    DEBUG "before temp1 = ", DEC temp1, CR
    temp1 = temp1 * 10
    DEBUG "after temp1 = ", DEC temp1, CR

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jim McCorisonJim McCorison Posts: 359
    edited 2005-03-02 16:41
    If Tracy's suggestion proves out, just change your keypad interface routine to convert the ASCII to the numeric value as soon as you get it from the keypad. Saves you having to remember to do it later, as well as potentially having to do it in various places.

    Jim
  • fzeitgeistfzeitgeist Posts: 20
    edited 2005-03-02 17:10
    that worked. thanx guys.
Sign In or Register to comment.