PDA

View Full Version : 16f687 - Where is the data stored?



andywpg
- 25th June 2012, 23:32
I am using a 16f687 for a project. The datasheet says it has 2048 words of flash program memory and 128 bytes of SRAM.

If I use the following commands to make an array:



BAR_PAT1 VAR BYTE[16]
ARRAYWRITE BAR_PAT1, [1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0]


Which type of memory is the 16 bytes written to? Program or SRAM? I haven't been able to figure it out on my own, and I need to know
for another project.

Thanks,

Andy

mackrackit
- 26th June 2012, 01:28
Written to SRAM as a variable.
From the manual.

Space for each variable is automatically allocated in the microcontroller=s RAM by PBP.
...
Variable arrays can be created in a similar manner to variables.

andywpg
- 26th June 2012, 19:40
Written to SRAM as a variable.

That's what I was afraid of..........guess there's an I2C EEPROM in my future!

Charlie
- 27th June 2012, 12:06
That's what I was afraid of..........guess there's an I2C EEPROM in my future!
I'm curious how that might help. But if it does, would the onboard EEPROM (256 bytes) not be sufficient?

andywpg
- 27th June 2012, 23:19
I'm curious how that might help. But if it does, would the onboard EEPROM (256 bytes) not be sufficient?

I have a BUNCH of 16 character messages (25+) that are to be displayed on an LCD. A master sends a command to a receiver (via RF) to light certain LED's, beep a piezo, and display various messages on the two lines of the LCD.

My idea was to have the master send just a code indicating what message each line should display in the receiver, and have the receiver unit read the associated messages from the EEPROM and display it. Since that would involve having another part in each receiver (possibly 40 or more of them), I have since decided that the master will transmit the two lines of the message, so I will only have to use an external EEPROM in the master.

Hopefully, my rambling explains the situation sufficiently...

Andy

rmteo
- 28th June 2012, 01:47
Why not store the messages as constant strings in program (FLASH) memory?

andywpg
- 28th June 2012, 02:41
Why not store the messages as constant strings in program (FLASH) memory?

I had sorta thought about that..........but I've always wondered how you tell what memory is not going to be used for the program. I always make the code non-relocatable when asked, but how do you..........

Wait a minute, do you just read the chip and look at the hex dump to see what spots are left blank after the program is in it? Is it that simple? Then you just pick an area that isn't being used? Am I on the right track?

That's a great idea! It would certainly lower the serial data overhead - from 39 bytes per transmission to 11. I know, not a lot of data either way, but less chance of errors when the receiver is in a race car!

Thanks

mackrackit
- 28th June 2012, 06:24
http://www.picbasic.co.uk/forum/showthread.php?t=137

HenrikOlsson
- 28th June 2012, 06:30
Hi,
Lets say the number of message to be displayed comes in and gets stored in a variable called message.

Select Case Message
Case 1
LCDOUT $FE, 1, "This is message 1"
Case 2
LCDOUT $FE, 1, "This is message 2"
Case 3
LCDOUT $FE, 1, "This is message 3"
Case Else
LCDOUT $FE, 1, "Unknown message"
End Select

Here the strings are stored in program flash (where else should it go?) and written to the LCD when the LCDOUT statement executes. It's not the most efficient way of doing it but it's probably the easiest. If the messages are partly "the same" (like in the above example) you can have subroutines to print just that part which you then GOSUB from within the Case section, that will save on flash since you don't have to store the same string ("This is message") more than one time

Case 1
GOSUB FirstPart
LCDOUT $Fe, 1, "1"
...
...
End Select
...

FirstPart:
LCDOUT $FE, 1, "This is message "
RETURN

/Henrik.

ScaleRobotics
- 28th June 2012, 16:11
Here is a thread about embedding your strings into code space:
http://www.picbasic.co.uk/forum/showthread.php?t=1999

andywpg
- 28th June 2012, 19:20
Thanks All! That helped a lot.

I love this forum, there's always somebody who's smarter than me willing to help. :biggrin:

andywpg
- 28th June 2012, 21:21
Hi,
Here the strings are stored in program flash (where else should it go?) and written to the LCD when the LCDOUT statement executes. It's not the most efficient way of doing it but it's probably the easiest. If the messages are partly "the same" (like in the above example) you can have subroutines to print just that part which you then GOSUB from within the Case section, that will save on flash since you don't have to store the same string ("This is message") more than one time[code]
/Henrik.

Love the idea, unfortunately, the messages are ALL different. Some have similar parts, but not similar enough to make that viable.

That's the reason for LOTS of messages.

I decided to store 16 characters for each message (including leading and trailing spaces) because it makes displaying them SO much easier. Each one is a complete line on the LCD, and the loop is the same, no matter if the message is " BLACK FLAG "
or " REPORT TO PIT ". I want each message centered in the display for ease of reading at race speeds.

Ciao!

Andy

rmteo
- 29th June 2012, 02:42
Storing spaces is extremely inefficient. Create a routine that pads the message with the appropriate number of leading/trailing spaces before sending it out to the LCD.

andywpg
- 29th June 2012, 03:16
Storing spaces is extremely inefficient. Create a routine that pads the message with the appropriate number of leading/trailing spaces before sending it out to the LCD.

I suppose I could store each message without spaces, then write a unique "stop character".

Then I could just count the characters to the stop character, then calculate the number of spaces needed to pad it to the center of a 16 character line.

The only thing is accessing the right message. I intended to send the message number as part of the data block. I was going to calculate the start address of the message from the message number, and retrieve 16 characters. I guess I could just send the start address as the message number, then retrieve characters until I encounter the stop character. That would work, and is WAY more efficient (in both memory space and processor cycles).

Thanks!

HenrikOlsson
- 29th June 2012, 08:32
Why not clear the screen, move the cursor to the first position, print the message?


CursorPos VAR BYTE ' 0=first line first char, 64=second line first char (I think, usally...)

CursorPos = 1
GOSUB Clear_and_set_cursor
LCDOUT "Report to pit"

Pause 2000

CursorPos = 5
GOSUB Clear_and_set_cursor
LCDOUT "STOP"

' and so on

END

Clear_and_set_cursor:
LCDOUT $FE, 1, $FE, ($80 + cursorposition)
RETURN

/Henrik.

Charlie
- 29th June 2012, 12:22
Storing spaces is extremely inefficient. Create a routine that pads the message with the appropriate number of leading/trailing spaces before sending it out to the LCD.
Of course, shipping product with unused memory is pretty inefficient too. If there's plenty of unused program store, why waste time improving efficiency, particularly for a code block that isn't very reusable?
To paraphrase old movies, "smoke 'em if you've got 'em, lads." But if things are tight, I agree completely.

andywpg
- 29th June 2012, 14:44
Why not clear the screen, move the cursor to the first position, print the message?
/Henrik.

Exactly what I plan on doing. Since each line is usually somewhat less than 16 characters, though, I want to have some leading spaces to bring each line to the center of the display. I'll just calculate how many characters less than 16 a line is, then divide that by two and use that as my pad in the front.

I just figure having it centered makes it easier for the driver to read when he's going fast a trying to avoid someone else.