PDA

View Full Version : memory full



Gevo
- 20th March 2026, 11:33
Hi all,

I have a application with the 16F882 and have add some data. But the memory is run over.
The '882 = 2048 words, "883 is only 4096 words.

I drive a LCD (1602) RS485 and some LEDs and buttons. Not really exciting.

But, I have 30 Hub's (0 to 29) to Open and Close and show on the LCD.

All 30 Open and Close strings are different.


After 8 Hub's in the program the memory ("882) runs out. Any advice?


Hub_ID = 0 ' Hub Open

high EN_RS485 ' Enable RS485
pause 5
hserout [0,2,0,16,67,45,255,15,222,3] ' Bus open
LCDOut $fe,$C0,"Hub ",dec Hub_ID, " is Open "
pause 5 ' Wait for last byte out
low EN_RS485 ' Disable RS485

pause 1000

high EN_RS485 ' Enable RS485
pause 5
hserout [0,2,0,16,67,47,255,15,220,3] ' Bus close
LCDOut $fe,$C0,"Hub ",dec Hub_ID, " is Close "
pause 5 ' Wait for last byte out
low EN_RS485 ' Disable RS485

pause 1000


' Do next Hub

Jerson
- 21st March 2026, 03:25
Are you repeating the same code 30 times since the messages differ? Then, possibly, you could be facing this issue as strings gobble up memory pretty fast.

I would look at the feasibility of building subroutines that take the hubid and printing out messages that would be/could be common. That will bring in some reduction.

By your description, the picture is not entirely clear, so, I could be off on my diagnoses.

HenrikOlsson
- 21st March 2026, 06:21
Yeah, lots of repeating code there...
For starters, move the LCDOUT commands to a subroutine.
Unless you're running HSEROUT at 150baud or something you can most likely remove the PAUSE 5 after LCDOUT since LCDOUT will take way more time to execute that what it takes the USART to spit out that last byte.



Main:
Hub_ID = 0 ' Hub Open

high EN_RS485 ' Enable RS485
pause 5
hserout [0,2,0,16,67,45,255,15,222,3] ' Bus open
GOSUB ShowHubOpen
low EN_RS485 ' Disable RS485

pause 1000

high EN_RS485 ' Enable RS485
pause 5
hserout [0,2,0,16,67,47,255,15,220,3] ' Bus close
GOSUB ShowHubClosed
low EN_RS485 ' Disable RS485

pause 1000

' Do next Hub

Goto Main

ShowHubOpen:
LCDOut $fe,$C0,"Hub ",dec Hub_ID, " is Open "
RETURN

ShowHubClosed:
LCDOut $fe,$C0,"Hub ",dec Hub_ID, " is Close "
RETURN

Next, how different are the HSEROUT strings for each hub? I see only two bytes differ in the open/close commands for Hub 0, what do they look like for Hub 1? What's the "pattern"?

If only two bytes changes between hub and command then have an array with the 10 bytes, change what's needed and GOSUB a subroutine that spits out the array. Like:


Cmd VAR BYTE[10]
Cmd[0] = 0
Cmd[1] = 2
Cmd[2] = 0
Cmd[3] = 16
Cmd[4] = 67
Cmd[5] = 45
Cmd[6] = 255
Cmd[7] = 15
Cmd[8] = 222
Cmd[9] = 3

GOSUB SendCmd


SendCmd:
HSEROUT [STR Cmd\10]
RETURN

For the next hub/command, you simply change the bytes that needs changing (or re-write them all if you're not THAT tight on space) and then GOSUB SendCmd.

/Henrik.

Gevo
- 26th March 2026, 10:40
Dear Jerson and Henrik,

Thanks for you input. It was 2 x 30 (1 x open and 1x close) routine's with all the same code.

I have made two routine's with four sub's linke Henrik code.

Close, Open and the two LCD routines. This increase the code with 80%.

A lott of thanks,
Regards Gerben