2

Is it possible to write a sub program in EEPROM or flash that even if you program/burn your PIC, the subprogram stays? For example, if I want to do a bluetooth connection, or turn on a LED every 2 s, and I want that subprogram to always stay in the PIC, even if I program/burn the PIC with a new code.

I know that I can write data in EEPROM memory, but may I write a program there apart from the one stored in flash?

In case that is not possible, is there another way to do that?

PIC18F4550

VC.One
  • 14,790
  • 4
  • 25
  • 57
esencia
  • 23
  • 2

2 Answers2

1

The Flash memory of the PIC18 is 16 Bit wide and the EEPROM is only 8 Bit wide, so you can't store any executable code there. The EEPROM is only for data.

When you reflash your controller you could tell MPLABx a memory range to flash. Have a look at:
Project Properies / Memories to Program
So you could put some routines in a 'save' memory range.

Mike
  • 4,041
  • 6
  • 20
  • 37
  • i have been reading the datasheet of pic18f4550 and i wonder, is it possible to "save" or write an instruction in a "x" bank of RAM memory?, RAM memory is 12 bit wide, but if i get it right, each instruction like MOVLW or MOVWF are 16 bit wide so it is not possible, correct me if im wrong plz – esencia Nov 02 '18 at 03:32
  • The RAM in the PIC18 is byte orientated. Each byte has a 12-bit address, allowing up to 4096 bytes of RAM. The RAM is divided into as many as 16 banks that contain 256 byte each. And you are right, each instruction is 16 bit wide. – Mike Nov 02 '18 at 07:11
  • So how could i save a instruction in RAM, the objective of doing this is for example, when in PORTA.R0 there is a 5v input, the program execute "x" instruction, but when the pic is power off, the "x" instruction should be erase, thats why i want to save it in RAM – esencia Nov 02 '18 at 15:21
  • You could not execute an instruction from the RAM! – Mike Nov 05 '18 at 06:38
0

From PIC18F4550 datasheet section 6.

The Flash program memory is readable, writable and erasable, during normal operation...

So why not?

GJ.
  • 10,810
  • 2
  • 45
  • 62
  • The EEPROM is a different part than the program memory and only 8 Bit wide. – Mike Oct 17 '18 at 12:27
  • @Mike: Read question again: "Is it possible to write a sub program in EEPROM or flash..." – GJ. Oct 17 '18 at 17:51