PDA

View Full Version : Write and read to memory of PIC18F14k50



picmilan
- 19th August 2016, 06:53
Hello all,

I am trying to write and read from memory of PIC18F14k50.I have following code to write to memory location $500:


DEFINE OSC 24

X var byte
Y var word
Value var byte



mainloop:
Pause 4000
Y = $500
Value=2

erasecode Y
for X = 1 to 16
writecode Y, Value
Y = Y + 1
next X

Goto mainloop



I am trying to read from same location and turn LED on if 2 is stored at address $500.


DEFINE OSC 24

TRISC.4 = 0
LED VAR PORTC.4
X var byte
Y var word
Value var byte

mainloop:

readcode $500, Value
If Value = 2 Then
HIGH LED
goto ledout
Pause 50
Else
LOW LED
Pause 50
Endif
Goto mainloop


However It doesn't turn on the LED.Any thoughts?

Thanks

pedja089
- 19th August 2016, 10:34
You delete content of entire FLASH memory when you erase FLASH before programming PIC.
Try this:

DEFINE OSC 24

X var byte
Y var word
Value var byte

Pause 4000
Y = $500
Value=2

erasecode Y
for X = 1 to 16
writecode Y, Value
Y = Y + 1
next X

Blink:
readcode $500, Value
If Value = 2 Then
Toggle LED
Pause 500
Else
LOW LED
Endif
GOTO Blink