read write program memory
Moderators: David Barker, Jerry Messina
read write program memory
hello,
can any one tell me how to write and read program memory?
i am working on 18f46j50. i need to store some data coming from usart so instead of using external eeprom i wanted it to write into program memory
thank you
can any one tell me how to write and read program memory?
i am working on 18f46j50. i need to store some data coming from usart so instead of using external eeprom i wanted it to write into program memory
thank you
thanks for the link octal. but how do i write to address? like if i wanted to write 0 to address from $1000-$1400 then how to do that?octal wrote:check http://www.sfcompiler.co.uk/wiki/pmwiki ... .ROMBuffer
i saw in ROM module there is a variable "FROMAddress", i tried accessing it ROM.FROMAddress = $1000 but compiler returned error.
if you need so much granularity, check also
http://www.sfcompiler.co.uk/wiki/pmwiki ... moryAccess
http://www.sfcompiler.co.uk/wiki/pmwiki ... moryAccess
Hi octal,octal wrote:if you need so much granularity, check also
http://www.sfcompiler.co.uk/wiki/pmwiki ... moryAccess
thank you for the help, but still i am unable to get it working...
as example given in the link i made a simple program as below, its not working properly. I am trying to write 64 bytes as mentioned in datasheet but for some reason its writing 128 byte. can you please take a look at the code and memory dump, i would really appreciate it.
thank you
Code: Select all
Program RWT
Device = 18F46J50
Clock = 48
Config OSC = HSPLL
Config PLLDIV = 5 'PLL division
#option USB_SERVICE = False
#option ROM_BLOCK_SIZE = 64
Include "usbhid.bas"
Include "string.bas"
include "MemoryAccess.BAS"
Dim Address As Word
Dim index As byte
Structure TTXReport
Message As String
End Structure
Structure TRXReport
Message As String
End Structure
Dim TXReport As TTXReport Absolute TXReportRAM
Dim RXReport As TRXReport Absolute RXReportRAM
Dim Service As PORTA.0
Clear(HID.Buffer)
High(Service)
While true
HID.Service
If HID.Attached Then
Low(Service)
If DataAvailable Then
ReadReport
Select RXReport.Message
Case "0"
Address = $800
EraseBlock(Address)
For index = 0 To 63
WriteAt(Address,index)
Inc (Address)
Next
CloseWrite
TXReport.Message = "Written"
Case "1"
TXReport.Message = "Resetting Device..."
UCON = 0
UIE = 0
UCON.3 = 0
DelayMS(100)
ASM
RESET
End ASM
Else
TXReport.Message = RXReport.Message
EndSelect
WriteReport
EndIf
Else
High(Service)
EndIf
Wend
End Program
Code: Select all
07F0 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
0800 0100 0302 0504 0706 0908 0B0A 0D0C 0F0E
0810 1110 1312 1514 1716 1918 1B1A 1D1C 1F1E
0820 2120 2322 2524 2726 2928 2B2A 2D2C 2F2E
0830 3130 3332 3534 3736 3938 3B3A 3D3C F13E
0840 0100 0302 0504 0706 0908 0B0A 0D0C 0F0E
0850 1110 1312 1514 1716 1918 1B1A 1D1C 1F1E
0860 2120 2322 2524 2726 2928 2B2A 2D2C 2F2E
0870 3130 3332 3534 3736 3938 3B3A 3D3C 3F3E
0880 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
ok got it working for the 64byte block, just commented out CloseWrite
but still its not writing for the last 64th byte, it always write F1 there
what i am doing wrong... i have also tried changing index 0 to 64 still its not writing 64th byte..
but still its not writing for the last 64th byte, it always write F1 there
what i am doing wrong... i have also tried changing index 0 to 64 still its not writing 64th byte..
Code: Select all
07F0 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
0800 0000 0000 0000 0000 0000 0000 0000 0000
0810 0000 0000 0000 0000 0000 0000 0000 0000
0820 0000 0000 0000 0000 0000 0000 0000 0000
0830 0000 0000 0000 0000 0000 0000 0000 F100 <-----
0840 FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF
-
- Swordfish Developer
- Posts: 1473
- Joined: Fri Jan 30, 2009 6:27 pm
- Location: US
I don't think you're doing anything wrong. The code in MemoryAccess.bas doesn't look correct. It seems that WriteItem() is going to call CloseWrite() one byte too early, and that matches what you're seeing.
WriteItem() uses the following to actually write a byte. It uses the asm table write instruction that automatically increments the TABLEPTR register after it writes.
But, WriteItem also increments the TABLEPTR register
If the ROM_BLOCK_SIZE=64, then the constant WriteBlockSize=63, and CloseWrite() will be called when WriteItem() is called with TABLEPTR = 62.
Try changing TableWrite() to this and see if it works better
WriteItem() uses the following to actually write a byte. It uses the asm table write instruction that automatically increments the TABLEPTR register after it writes.
Code: Select all
// table write
Inline Sub TableWrite()
ASM
TBLWT*+
End ASM
End Sub
Code: Select all
{
****************************************************************************
* Name : WriteItem *
* Purpose : Write a byte to program memory *
****************************************************************************
}
Public Sub WriteItem (pValue As TABLAT)
TableWrite
If (WriteBlockSize And Byte(TBLPTRL+1)) = 0 Then
CloseWrite
EndIf
Inc(TABLEPTR)
End Sub
Try changing TableWrite() to this and see if it works better
Code: Select all
// table write
Inline Sub TableWrite()
ASM
TBLWT*
End ASM
End Sub