PDA

View Full Version : HSERIN each character cost 3 pgm words



boban
- 17th March 2008, 09:30
Hello,
I am trying to write simple Web server with 16F648A. This PIC has 4096 pgm words. I have discoverred very uneffective storing of characters in program memory using HSEROUT.

e.g.

HSEROUT ["a"] 'cost 3 pgm words
HSEROUT ["aa"] 'cost 6 pgm words

So each new character cost 3 pgm words!
So if I have 4096 pgm memory, I can use in my program just 1000 characters and that's it.
Anyone has any idea how to use the strings with HSEROUT in a better way?

Thanks for any idea, i need to use at least 2K of HTML code + program code.

skimask
- 17th March 2008, 16:21
HSEROUT ["a"] 'cost 3 pgm words
HSEROUT ["aa"] 'cost 6 pgm words
So each new character cost 3 pgm words!
So if I have 4096 pgm memory, I can use in my program just 1000 characters and that's it.
Anyone has any idea how to use the strings with HSEROUT in a better way?

Each new character takes 3 words...yes...
One to set the bank register to where the character is located
One to load the character into the working register
One to load that same character from the working register over to the serial output register

This might help...
http://www.picbasic.co.uk/forum/showthread.php?t=1999&highlight=macro+hserout

boban
- 19th March 2008, 08:17
Hello Skimask,
first thanks for the reply. I have tried http://www.picbasic.co.uk/forum/show...=macro+hserout seems it is a solution. I have played with it yesterday. But seems I have a problem with the compiler. If I have tried to compile my program for 16F877 it was successfully compiled. But if I have tried to compile it for 16F648A I have the following error:

Message[306] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 696 : Crossing pageboundary -- ensure page bits are set.
Message[306] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 624 : Crossing pageboundary -- ensure page bits are set.
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 428 : Symbol not previously defined (EEADRH)
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 442 : Symbol not previously defined (EEADRH)
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 456 : Symbol not previously defined (EEADRH)
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 470 : Symbol not previously defined (EEADRH)
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 797 : Symbol not previously defined (EEADRH)
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 428 : Symbol not previously defined (EEDATH)
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 442 : Symbol not previously defined (EEDATH)
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 456 : Symbol not previously defined (EEDATH)
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 470 : Symbol not previously defined (EEDATH)
Error[113] E:\PICDEVELOPMENTTOOLS\PBP\PBP246\PBPPIC14.LIB 795 : Symbol not previously defined (EEDATH)

Seems it is a bug of PBP lib no?

Boban

skimask
- 19th March 2008, 13:00
If I have tried to compile my program for 16F877 it was successfully compiled. But if I have tried to compile it for 16F648A I have the following error:
......
Seems it is a bug of PBP lib no?
Boban

No it doesn't.
Check the datasheets.
'877a has an eeadrh register, '648 doesn't.
'877a can read/write it's own eeprom AND flash program memory.
'648 can only read/write it's own eeprom.

boban
- 19th March 2008, 16:27
Ahhh ****, ok, so it means, that I cannot use this trick to save the strings to program flash.

OK, great, so is there any way, how could I store and use the strings more efficiently ?

skimask
- 19th March 2008, 17:47
Ahhh ****, ok, so it means, that I cannot use this trick to save the strings to program flash.

OK, great, so is there any way, how could I store and use the strings more efficiently ?

Store it in internal eeprom and read it out from there...or store it in external eeprom...or...or...or...

Darrel Taylor
- 20th March 2008, 00:35
OK, great, so is there any way, how could I store and use the strings more efficiently ?
For PIC's that can't access their own flash, the next best option is POKECODE/PEEKCODE, which will work on any chip.

http://www.picbasic.co.uk/forum/showthread.php?p=51931

Notice how the "TOO LOW " and "TOO RICH" strings are stored.
And how it's displayed in the ShowMsg: routine. Just change the LCDOUT to HSEROUT.

It uses 1 word per character stored.
Plus about 30 words for the retreival code.
<br>

boban
- 20th March 2008, 08:24
Hello, Thanks Darrel and Skimask, I had in my pocket one 16F916 where this trick to store two chars to one pgm word is working well. I was able to rapidly decrease my code space. 1.5K instead of 4K. I will also test this POKECODE/PEEKCODE on my 16F648.
Thanks both of you...

I think, the EEPROM is not solution it has just 256 bytes and I need to store there some data and also external EEPROM will complicate the design. But maybe for the storage of lot of html code this could be the solution.

My webserver with Lantronix Direct port is working pretty well now. I have even some space to make the html more nicer :))))

Boban

P.S. I am now thinking about the feature to have the possibility to store the hlml pages during runtime - kind of firmware update. My idea is to reserve the space in code memory like put there spaces and via webserver to have the service to upgrade the html code during the runtime. But I must check the assemler if it is possible to write to program code during the execution. Have no clue....

skimask
- 20th March 2008, 16:58
I think, the EEPROM is not solution it has just 256 bytes and I need to store there some data and also external EEPROM will complicate the design. But maybe for the storage of lot of html code this could be the solution.........
P.S. I am now thinking about the feature to have the possibility to store the hlml pages during runtime - kind of firmware update. My idea is to reserve the space in code memory like put there spaces and via webserver to have the service to upgrade the html code during the runtime. But I must check the assemler if it is possible to write to program code during the execution. Have no clue....
Would be a load easier just to add an external 24LCxxx serial eeprom and use that. 2 wires, I2Cread/I2Cwrite... Not much code space wasted, lots of room for add-ons...
Not much code space in a '916 as you're well aware I'm sure. Start adding HTML code as data in the program space, and you'll be out of space in no time flat...

boban
- 1st April 2008, 17:25
Hello, the external eeprom will complicate the design, and if you are writting effectively html you could store almost 10 K of HTML = 5 K words and remaining 3 k of code, I have managed to store what I wanted. I have just little bit fighted with the fact, that if you are doing something like
@ da "abcd",10,"efgh",0 the da will pack 0 and 10 and it caused the cutting of my Strings. So I have decided to put to the end of each string not 0 but 0x7F and I have modified little bit the code to skip 0 byte and use 7F as separator. And it is working pretty well!!! Thanks everyone for help!!!

StringOut:
ReadCode Addr, TwoChars
Char = TwoChars >> 7
if Char = $7F THEN StringDone
if Char <> 0 then hserout [Char]
Char = TwoChars & $7F
if Char = $7F then StringDone
if Char <> 0 then hserout [Char]
Addr = Addr + 1
goto StringOut
StringDone:
return

Darrel Taylor
- 2nd April 2008, 02:32
That'll work! http://www.picbasic.co.uk/forum/images/icons/icon14.gif

Might use a few bytes for those extra 0's

You can put the "Escape codes" in the string, and it won't use the extra bytes.

@ da "abcd\nefgh",0


\a Bell (alert) character 07
\b Backspace character 08
\f Form feed character 0C
\n New line character 0A
\r Carriage return character 0D
\t Horizontal tab character 09
\v Vertical tab character 0B
\\ Backslash 5C
\? Question mark character 3F
\' Single quote (apostrophe) 27
\" Double quote character 22
\0OO Octal number (zero, Octal digit, Octal digit)
\xHH Hexadecimal number
Might even be able to put the "Null terminator" in there too.

@ da "abcd\nefgh\x00"

But I haven't tried that yet.
<br>

boban
- 7th April 2008, 16:49
Hello Darrel, thanks a this helped I didn't know, taht I could use the escape sequences like in C or Java :)