Storing Text in EEPROM - ideas wanted


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2005
    Posts
    44

    Default Storing Text in EEPROM - ideas wanted

    Hi all,

    Im working on a project, using a PIC16F648A which monitors signals on 4x pins and automatically switches some outputs based on the inputs.

    The project also serially outputs status of the inputs and outputs every 3 seconds, but I want to be able to label (name) the inputs on the status display.

    Instead of hard coding the names, I want to be able to write the names to the eeprom and then read them back for use in the status display, but unortunately the only thing i've ever had experience with eeprom is writing and reading a couple of digits.

    Now, the port names will be limited to 8 or 10 characters x 4 ports and also a label for the physical device (ie device name)

    So say port 1 name is "Port0001" port 2 is "port0002" and so on and the device name is "Switch01".

    For me to store these names in eeprom, obviously the text names need to be converted from ascii to decimal? and then this result written and then when read, converted from decimal back to ascii chars?

    If anyone could assist in providing some help and possible code examples etc, would be appreciated.

  2. #2
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    In a way you are making this harder than it needs to be.
    You don't need to convert from ASCII to decimal, because ASCII is decimal.

    All you need to do is write/store the ASCII strings into EEPROM. Then read them back via a subroutine that includes the LCDOut command. You may want to terminate your stored strings with a 0 (decimal 0 not ASCII) to indicate end of string, this allows each string to be different lengths.

  3. #3
    Join Date
    Aug 2005
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Ok, so far i have got this code, which works fine as far as getting the input for the port name

    Code:
    INCLUDE "modedefs.bas"		' Modes for SerOut
    
    CMCON = 7					' set portA to digital
    TRISA = %00100000			' Port A all output but MCLR
    TRISB = %00001010			' Port B all output but 1 - debug in
    
    DEFINE DEBUGIN_REG PORTB		' Set Debug pin port
    DEFINE DEBUGIN_BIT 1			' Set Debug pin bit
    DEFINE DEBUGIN_BAUD 9600		' Set Debug baud rate
    DEFINE DEBUGIN_MODE 1			' Set Debug mode: 0 = true, 1 = inverted
    
    DEFINE DEBUG_REG PORTB			' Set Debug pin port
    DEFINE DEBUG_BIT 2				' Set Debug pin bit
    DEFINE DEBUG_BAUD 9600			' Set Debug baud rate
    DEFINE DEBUG_MODE 1				' Set Debug mode: 0 = true, 1 = inverted
    
    
    port1name  var byte[8] 
    
    Main: ' Display "Waiting for input" every 5 seconds if timeout period expires
        	DEBUGIN 5000, idle, [STR port1name\8\13]
    
        	DEBUG "Received: ",STR  port1name\8,13,10
    
        	Goto Main
    
    idle: 
    		DEBUG "Waiting for input"
    
    		goto main
    So from here, now i need some help on how i write the byte array to the eeprom and terminate with decimal 0, and also read the strings from the eeprom, upto the decimal 0?

    The byte array will need to be converted into a word? and then write highbyte and lowbyte?

  4. #4
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Before we get too far, are you using internal EEProm or External? What type of pic are you using?

    If its internal take a look at the DATA, and READ commands. These in combination with with a for/next loop should give you what you are looking for. The reason for 0 is as you are reading data from EEProm when you read 0 that tells the loop to stop and exit.

    If External what type is it, I2C?
    Last edited by DynamoBen; - 23rd July 2006 at 14:54.

  5. #5
    Join Date
    Aug 2005
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    I am using the internal eeprom on a 16f628a / 648a

  6. #6
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    To add your strings via the DATA command:

    DATA $00,"Switch01",0

    Example of reading the above and displaying it on an lcd:

    For CounterA = 0 to 16
    Read CounterA,value
    If CounterA=0 then goto Main
    LCDOUT value
    Next CounterA

    This should be enough to get you started.

  7. #7
    Join Date
    Aug 2005
    Posts
    44


    Did you find this post helpful? Yes | No

    Default

    Ok,
    Ive got this far:

    Code:
    INCLUDE "modedefs.bas"		' Modes for SerOut
    
    CMCON = 7					' set portA to digital
    TRISA = %00100000			' Port A all output but MCLR
    TRISB = %00001010			' Port B all output but 1,3 (Si and CCP)
    
    DEFINE DEBUGIN_REG PORTB		' Set Debug pin port
    DEFINE DEBUGIN_BIT 1			' Set Debug pin bit
    DEFINE DEBUGIN_BAUD 9600		' Set Debug baud rate
    DEFINE DEBUGIN_MODE 1			' Set Debug mode: 0 = true, 1 = inverted
    
    DEFINE DEBUG_REG PORTB			' Set Debug pin port
    DEFINE DEBUG_BIT 2				' Set Debug pin bit
    DEFINE DEBUG_BAUD 9600			' Set Debug baud rate
    DEFINE DEBUG_MODE 1				' Set Debug mode: 0 = true, 1 = inverted
    
    
    port1name  var byte[8] 
    name1		var word
    i var byte
    
    Main: ' Display "Waiting for input" every 5 seconds if timeout period expires
        	DEBUGIN 5000, idle, [STR port1name\8\13]
    
    	  	DEBUG "Received: ",STR  port1name\8,13,10
    
    for i = 1 to 8
    	write i,port1name(i)
    	pause 10
    next i
    pause 100
    
    for i = 1 to 8
    	read i, port1name(i)
    next i
    DEBUG "Read eeprom after write: ",STR  port1name\8,13,10
    
    Goto Main
    
    idle: 
    DEBUG "Waiting for input",13,10
    
    for i = 1 to 8
    	read i, port1name(i)
    next i
    DEBUG "Read from eeprom: ",STR  port1name\8,13,10
    
    goto main
    Now, it receives what i enter, and saves it, and displays it fine, however once power is cycled, and it reads from the eeprom, the 1st character is incorrect:

    Received: 12345678
    Read eeprom after write: 12345678
    Waiting for input

    then power cycle

    then i get this:

    Waiting for input
    Read from eeprom: û2345678

    any hints on what i may be doing wrong?
    Also all comms is serial @ 9600, there is no LCD, therefore the LCDout command cant be used....

  8. #8
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    When you said "I want to be able to label (name) the inputs on the status display" I thought you were talking about an LCD.

    When you use the STR command you are starting at 0 not 1.

    Try this instead

    for i = 0 to 7
    read i, port1name[i]
    next i

    AND

    for i = 0 to 7
    write i, port1name[i]
    next i

Similar Threads

  1. Can't read sequential addresses in external EEPROM
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th February 2010, 14:46
  2. How to define constants that specify eeprom addresses
    By DwayneR in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th December 2009, 04:07
  3. Problem with I2C EEPROM addressing
    By Atom058 in forum General
    Replies: 14
    Last Post: - 3rd November 2009, 03:17
  4. How to write/read strings EEPROM/LCD
    By g-hoot in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 11th February 2007, 06:26
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

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