• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Method for directly writing to Flash 18F

Status
Not open for further replies.

Peter_wadley

New Member
Hey there,

I was wondering if there is a way to directly program the flash memory of 18F PICs

I know I can do it through the PICKIT2 screen where the flash memory is shown...

but how would you do it through assembly code?

Is there a way to do it without using TBLWT*??

is there something like for example say you want the byte at 0xFFF2 to be d'33'

0xFFF2 = d'33' --- didn't work
0FFF2 equ d'33' --- didn't work...

it would be nice if the instruction didn't take up any ROM to execute ... since i 'd like to pre program a sound file in the PIC then play it..

Thanks
 

Pommie

Well-Known Member
Most Helpful Member
You could do,

Code:
    org   0xfff2
    db    d'33'
But you would have to use the table instructions to read it.

Mike.
 
Last edited:

Peter_wadley

New Member
hey Mike

What I'm trying to do is utilize both bytes .. since retlw uses 2 bytes I can only use 32K but I'm trying to use all 64K

this code skips a byte between each value... is there a way to write to every byte

org 0xfff2
db d'01' ; 0xFFF2
db d'02' ; 0xFFF4
db d'03' ; 0xFFF6
db d'04' ; 0xFFF8
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
Each line starts on an even byte and so if you put an even number of bytes on each line they will be in consecutive bytes.

Try,
Code:
    org   0xfff2
    db    1,2,3,4,5,6,7,8
Mike.
 

Peter_wadley

New Member
Each line starts on an even byte and so if you put an even number of bytes on each line they will be in consecutive bytes.

Try,
Code:
org 0xfff2
db 1,2,3,4,5,6,7,8
Mike.
that works

however, the sound bytes are output as a series of retlw's from the program that converts .wav to 1bit sound ...:

;------------------------- 32096
retlw b'10010101' ; 95
retlw b'01010101' ; 55
retlw b'00011111' ; 1f
retlw b'11110111' ; f7
retlw b'00010001' ; 11
retlw b'00010100' ; 14
retlw b'11010101' ; d5
retlw b'10100101' ; a5
retlw b'11011000' ; d8
retlw b'10000010' ; 82
retlw b'00110011' ; 33
retlw b'01111110' ; 7e
retlw b'10110011' ; b3
retlw b'10011101' ; 9d
retlw b'10000000' ; 80
retlw b'01001101' ; 4d
retlw b'10110110' ; b6
retlw b'00000000' ; 00

I would need to go through 64k lines to change to this db X,Y format

if there is a one line code it would be much easier (just use 'replace all' on the 'retlw' to XXX????) any suggests?
 

Pommie

Well-Known Member
Most Helpful Member
When I need to change data like that I either use PFE with a keyboard macro or VB/Excel to convert it.

Is this Roman Blacks program. If so, it may be simpler to output the C code and convert that. Alternatively, he may see this post and add the db output to the program.

If your still stuck, provide a small sample file and I'll see what I can do.

Mike.
 

Pommie

Well-Known Member
Most Helpful Member
I was bored and so had a play. If you have VB this will convert the file,
Code:
Private Sub Form_Load()
    Dim FileNum As Long
    Dim OutFile As Long
    FileNum = FreeFile
    Open "Data.txt" For Input As FileNum
    OutFile = FreeFile
    Open "Out.txt" For Output As OutFile
    First = True
    Do While Not EOF(FileNum)
        Input #FileNum, temp
        temp = Trim(temp)
        If Left(temp, 5) = "retlw" Then
        num = Mid(temp, InStr(temp, "b"), 11)
            If First Then
                Print #OutFile, Chr(9) & "DB" & Chr(9) & num;
                First = False
            Else
                Print #OutFile, "," & num
                First = True
            End If
        End If
    Loop
End Sub
Edit, it assumes the format is the same as the text above. It could be made much friendlier.

Mike.
 
Last edited:

Peter_wadley

New Member
I was bored and so had a play. If you have VB this will convert the file,
Code:
Private Sub Form_Load()
    Dim FileNum As Long
    Dim OutFile As Long
    FileNum = FreeFile
    Open "Data.txt" For Input As FileNum
    OutFile = FreeFile
    Open "Out.txt" For Output As OutFile
    First = True
    Do While Not EOF(FileNum)
        Input #FileNum, temp
        temp = Trim(temp)
        If Left(temp, 5) = "retlw" Then
        num = Mid(temp, InStr(temp, "b"), 11)
            If First Then
                Print #OutFile, Chr(9) & "DB" & Chr(9) & num;
                First = False
            Else
                Print #OutFile, "," & num
                First = True
            End If
        End If
    Loop
End Sub
Edit, it assumes the format is the same as the text above. It could be made much friendlier.

Mike.
Hey Mike you the man!! Thanks!!

Works perfectly!! Now I can fill all 64K awesome :D

hope I ain't askin' too much but ... it there a way to make the program use what ever .txt file is in the same folder as the .exe (It would only be run with ONE .txt in the folder) and then output to a .txt file the same as the input but maybe with a suffix like XXXX_C.txt .

This would make it alot easier to convert songs without changing the names to Data.txt and from Output.txt

maybe something like *.txt? like a wildcard search of the first .txt file in the folder?

Yes the data is coming from Roman Blacks program also
 

Pommie

Well-Known Member
Most Helpful Member
Here you go,
Code:
Private Sub Form_Load()
    Dim FileNum As Long
    Dim OutFile As Long
    FileNum = FreeFile
    InFileName = Dir("*.txt")
    OutFileName = Left(InFileName, InStr(InFileName, ".") - 1) & "_C.[COLOR="Red"]txt1[/COLOR]"
    Open InFileName For Input As FileNum
    OutFile = FreeFile
    Open OutFileName For Output As OutFile
    First = True
    Do While Not EOF(FileNum)
        Input #FileNum, temp
        temp = Trim(temp)
        If Left(temp, 5) = "retlw" Then
        num = Mid(temp, InStr(temp, "b"), 11)
            If First Then
                Print #OutFile, Chr(9) & "DB" & Chr(9) & num;
                First = False
            Else
                Print #OutFile, "," & num
                First = True
            End If
        End If
    Loop
    [COLOR="Red"]End[/COLOR]
End Sub
Note that I made it output the file as oldname_C.txt1 so the dir command doesn't see the converted file.
Edit, it might be a good idea to change the red bit to asm or inc and also add the End instruction.

Mike.
 
Last edited:
Status
Not open for further replies.

EE World Online Articles

Loading
Top