PDA

View Full Version : Ram management / Hi



124C41
- 23rd November 2008, 12:34
Dual purpose post,

First let me say Hi, I’m a new PIC user, migrating from the basic stamp.

Second is a question,
It may be my paranoia from the stamps but how does one keep up with the RAM usage?

I have been using statements like:

SOMEPIN VAR PORTB.0

Does the compiler just place PORTB.0 in the places I type SOMEPIN, like a CON, or is there a variable created because of that statement?

Ioannis
- 23rd November 2008, 12:40
You have direct access to the pin.

Ioannis

Acetronics2
- 23rd November 2008, 13:41
SOMEPIN VAR PORTB.0



Hi

That means "SOMEPIN" is just another name for PORTB.0

consider it as a compiler DIRECTIVE ... that doesn't change the produced code.

Compiler just replaces all the "SOMEPIN" strings it finds by the "PORTB,0" string ( it's assembler that is generated ...) so, once declared, you can use one or the other ... when you want in your program.

Alain

124C41
- 23rd November 2008, 22:21
ok thanks

Is there an easy way to see the amount RAM used?

The manual says the compiler uses about 24 bytes for system variables, if the PIC has 256 Bytes RAM is it safe to assume that the user has (256 – 24 = ) 232 bytes to use for variables?

Bruce
- 24th November 2008, 14:49
A simple way to check how much RAM is used/available is to open the .asm file generated
after compiling.

Example;


DEFINE OSC 20

X VAR PORTB
Y VAR BYTE

loop:
FOR Y = 0 TO 7
HIGH 0 'Turn on LED connected to RB0
Pause 50 'Delay for .5 seconds
Low 0 'Turn off LED connected to RB0
Pause 50 'Delay for .5 seconds
NEXT Y
GoTo loop 'Go back to loop and blink LED forever
End
File name blink.bas. Open blink.asm after compiling, and you'll see something like this;


#define OSC 20

RAM_START EQU 00020h
RAM_END EQU 001EFh
RAM_BANKS EQU 00004h
BANK0_START EQU 00020h
BANK0_END EQU 0007Fh
BANK1_START EQU 000A0h
BANK1_END EQU 000EFh
BANK2_START EQU 00110h
BANK2_END EQU 0016Fh
BANK3_START EQU 00190h
BANK3_END EQU 001EFh
EEPROM_START EQU 02100h
EEPROM_END EQU 021FFh

R0 EQU RAM_START + 000h
R1 EQU RAM_START + 002h
R2 EQU RAM_START + 004h
R3 EQU RAM_START + 006h
R4 EQU RAM_START + 008h
R5 EQU RAM_START + 00Ah
R6 EQU RAM_START + 00Ch
R7 EQU RAM_START + 00Eh
R8 EQU RAM_START + 010h
FLAGS EQU RAM_START + 012h
GOP EQU RAM_START + 013h
RM1 EQU RAM_START + 014h
RM2 EQU RAM_START + 015h
RR1 EQU RAM_START + 016h
RR2 EQU RAM_START + 017h
_Y EQU RAM_START + 018h
PBP system variables are from R0 to RR2. Your Y variable is the last one at 018h.

Depending on how complex your BASIC program is, PBP might need to create a few
temporary variables. If it does these will show up in the .asm file like the ones above.

RAM_START and RAM_END will change depending on the PIC you compile for.

124C41
- 25th November 2008, 12:31
Thank you very much :)