How to write/read strings EEPROM/LCD


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Dec 2005
    Posts
    46

    Default How to write/read strings EEPROM/LCD

    Hello,
    Im using a 16F648A and my program has a bunch of LCDOUT commands so that the user can select different settings. Well, I am adding new features, and am out of space. I saw Melanies post "Making Program Code Space your playground" for program space, but this chip won't allow that, so I'm thinking EEPROM is the Solution?

    Here's part of the code I cut out to give a better idea of what I'm doing. Each time a certain button is pushed, it loops back through this part of the code:

    Case 2
    Refresh = Refresh + 1
    IF Refresh = 9 Then Refresh = 1
    ref:
    Select Case Refresh
    GoSub lcdone ' Position cursor at home
    LCDOut "Refresh"
    GoSub lcdsec
    Case 1
    LCDOut "None"
    RefTime = 0
    Case 2
    LCDOut "30 Sec"
    RefTime = 30 ' Move to 2nd line on LCD
    Case 3
    LCDOut "2.5 Min"
    RefTime = 140
    Case 4
    LCDOut "7 Min"
    RefTime = 400
    Case 5
    LCDOut "15 Min"
    RefTime = 900
    Case 6
    LCDOut "30 Min"
    RefTime = 1700
    Case 7
    LCDOut "1 Hour"
    RefTime = 3500
    Case 8
    LCDOut "2 Hour"
    RefTime = 7000

    End Select
    Pause 400

    I have several of these menus throughout the program and the strings for most LCDOUT commands are different. I have played a little with EEPROM, but am not sure the easiest way to us it. Here's the only thing that I've gotten to work, but I'm afraid in may take more space (and a ton of work). I'm using values 0-15 for other stuff, so "A" is at 16. The code below displays "BAD" on the LCD.

    EEPROM 0, [1,1,10,0,0,0,24,1,1,150,0,250,0,1,1,0,"A","B","C", "D","E","F","G","H","I","J","K","L","M"]

    testmem VAR BYTE[8]

    Read 17, testmem[0]
    Read 16, testmem[1]
    Read 19, testmem[2]
    testmem[3] = " "
    testmem[4] = " "
    testmem[5] = " "
    testmem[6] = " "
    testmem[7] = " "

    LCDOut STR testmem

    I had to add all of the blank spaces in the last 5 spots of the array to keep "wierd" characters from being displayed. In the manual where it talks about strings in EEPROM, it says "No lenghth or terminator is automatically added", so I assume that's the reaon for the wierch characters, but don't really know how to fix it. I'm using the array of 8 since the LCD is a 2x8 display. Anyway, am I wasting my time here? Would I be better off just saying:

    LCDOUT "BAD"

    Sure could use some ideas on how to free up some space. Thanks,
    Gary
    Last edited by g-hoot; - 27th January 2007 at 17:32.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default I never tried this

    Greetings g-hoot,
    I never tried this but here is my idea.
    StringVar var byte

    Stringvar = testmem[3]
    gosub string

    Stringvar = testmem[4]
    gosub string

    Stringvar = testmem[5]
    gosub string

    Stringvar = testmem[6]
    gosub string

    String:
    LCDOUT stringvar
    return

    What I am thinking is the lcdout commands are using up your codespace, so put them into a loop and make the string a variable, give the variable the value you wish to display and then call the display subroutine. Also see select case instructions in the manual.
    JS
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Hi ghoot,
    Not sure if it would save any code space overall, but you might want to look into the "LOOKUP" command too.

    Also, in your code where you limit "Refresh" to 8...
    Code:
    Refresh = Refresh + 1
    IF Refresh = 9 Then Refresh = 1
    You might want to do this instead...
    Code:
    Refresh = Refresh + 1
    IF Refresh > 8 Then Refresh = 1
    That way if the Pic ever has some glitch and makes "Refresh" any value greater than 8, the code will revert back to "Refresh=1"

    Arch
    "Data sheets? I ain't got no data sheets. I don't need no data sheets. I don't have to read any stinking data sheets!"

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Different ways... use an external EEPROM to store your strings and some variable values (reftime etc etc) Or work around something like
    http://www.picbasic.co.uk/forum/show...bedded+strings

    it's up to you!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Dec 2005
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    Joe,
    I got "rid" of all of the LCD out commands with a sub and sure thought that would do the trick, but my program only went from 3934 to 3931. Here's what I did:


    IF Refresh > 8 Then Refresh = 1
    ref:
    Select Case Refresh
    GoSub lcdone ' Position cursor at home
    T[0]="R":T[1]="e":T[2]="f":T[3]="r":T[4]="e":T[5]="s":T[6]="h":T[7]=" "
    GoSub LCDout1
    GoSub lcdsec
    Case 1
    T[0]="N":T[1]="o":T[2]="n":T[3]="e":T[4]=" ":T[5]=" ":T[6]=" ":T[7]=" "
    GoSub LCDout1
    RefTime = 0
    Case 2
    T[0]="3":T[1]="0":T[2]=" ":T[3]="S":T[4]="e":T[5]="c":T[6]=" ":T[7]=" "
    GoSub LCDout1
    RefTime = 30

    etc........

    LCDout1:
    LCDOut STR T
    Return


    What did you mean by "Also see select case instructions in the manual."...am I missing something there?

    Arch,
    I fixed the "IF Refresh > 8 " problem. Thanks for that. I've looked at the LOOKUP command, but really don't don't understand it. I guess if I set up the alphabet as constants, that won't use any space, but once I use lookup to read them into an array, woukldn't that take up the same space as above?

    mister_e,
    This board design has been done for a while, so I can't use external on this one, but if I do it on another design, when I retrieve the strings to go into the LCDOUT command, won't that put me in the same boat? As you can see, I'm quite a rookie at this. :-) I don't think I can do the embedded strings either since this chip won't let me use program space. "Flash Program Write" is disabled when I select that chip in the EPIC Programmer.
    Gary

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Ah crap! So the RTFM of the day goes to me

    Using an external EEPROM solve the problem, the only thing you have to keep in your PIC is the EEPROM start address of your string. From there, you just call and display routine.

    Anyways, i'm pretty sure there's something to do around this without changing your actual stuff... let me sleep on this. If you want, you can post your whole code here or, if you can't for some privacy and/or commercial reason, send it on my e-mail.
    Last edited by mister_e; - 29th January 2007 at 04:40.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Red face To quote Homer S

    Quote Originally Posted by g-hoot View Post
    Joe,



    What did you mean by "Also see select case instructions in the manual."...am I missing something there?
    Dohe!
    Well it's like this, these coke bottle thick glasses . . . I didn't see you had used select case already, Just ignorant of me, sorry.
    JS
    EDIT: You might check with Darrel, I think he has something that measures the code size for each bit of code, but understand this, my memory isn't worth much.
    Last edited by Archangel; - 29th January 2007 at 05:33. Reason: add
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  8. #8
    Join Date
    Dec 2005
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    "the only thing you have to keep in your PIC is the EEPROM start address of your string"

    Ahh, I think it's starting to sink in to my thick melon. What I was trying to do was set up the alphabet in upper and lower case, and numbers and a few other characters in eeprom, and then call each one individually. I noticed in many places that people were looping through like this:
    for i = 0 to 7
    read i, LCDtext(i)
    next i

    but that wouldn't work with the alphabet deal since I had to jump around to different, non-sequential eeprom locations.
    So, what you are saying is that I would save each actual string in eeprom and then just give the loop the starting location of the string. I'm only using about 16 locations of eeprom right now, and this chip has 256, so that leaves me enough room for about thirty 8 character strings, so that should help a bunch. I'll give that a shot tonight.
    Thanks all,
    Gary

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Joe S. View Post
    You might check with Darrel, I think he has something that measures the code size for each bit of code, but understand this, my memory isn't worth much.
    I think you talk about...

    How much code would a code hog hog
    http://www.picbasic.co.uk/forum/showthread.php?t=2418
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Parsing Strings...
    By TerdRatchett in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 15th February 2009, 04:13
  2. Please help with storing strings in codespace
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th May 2008, 01:02
  3. Processing lengthy strings
    By sougata in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st March 2006, 05:27
  4. I2CWRITE writing Strings to EEPROM
    By NavMicroSystems in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th March 2005, 19:45
  5. reading 2c strings
    By beto in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 22nd December 2004, 15:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts