Reading, writing, erasing flash (16F88)


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Did you mean AND?

    Either AND or NOR...one of the two. Either way, in the end, it looks to me like something is broke
    Now I get it; you're testing me, right?

    Nope, sorry; NOR won't do it, either. To repeat my earlier examples, if $F is the "erased" value in the location and the value $A is to be written:

    %1111 OR %1010 returns %1111, so the value in the location is unchanged.

    %1111 AND %1010 returns %1010, which is the desired result.

    But . . . since the only case when NOR returns 1 is as the product of two 0s:

    %1111 NOR %1010 gives %0000 (!)

    In fact, anything NORd with $F or $FF or $FFFF is going to be . . . 0!

    The winner, still the reigning champion, is AND
    Last edited by RussMartin; - 23rd October 2008 at 22:36.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RussMartin View Post
    Now I get it; you're testing me, right?
    No need for that...

    The winner, still the reigning champion, is AND
    I believe, I've never tried it, but I think you're right. I just didn't have the ambition to do any mental boolean logic.

  3. #3
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Now I get it; you're testing me, right?

    No need for that...
    Doggone--I see I kept thinking decimal 10 (%1010) and typing $10 (%10000) instead of $A. How in heck did I manage to do that? I've corrected the posts, but why didn't you catch that and save me from raging embarrassment?

    As the Shadow says, "Who knows what evil lurks in the hearts of men?"

    I can't believe that absolutely no one else has chimed in on this topic, though.
    Last edited by RussMartin; - 23rd October 2008 at 22:58.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by RussMartin View Post
    ....I can't believe that absolutely no one else has chimed in on this topic, though.
    Possibly because PIC16's are not really designed to do what you have in mind. Of 93 PIC16's that are listed on MicroCHIP's website, only 6 have self-write capability (which is what allows you to do what you trying to do). OTOH, of 155 PIC18's, 135 of them have self-write. AFAIK, ALL 24-bit core devices (PIC24F/H, dsPIC30 and dsPIC33) have this capability - which I have used on many occassions. You may want to take a look at this App note:
    AN1095, Emulating Data EEPROM for PIC18 and PIC24 MCUs and dsPIC DSCs
    http://ww1.microchip.com/downloads/e...tes/01095b.pdf

  5. #5
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    OK, I'll add my $.02

    I have done this - but only with an 18F8722. I used ERASECODE on a 64byte boundary, then issued 32 consecutive word-size WRITECODEs

    It worked.
    Charles Linquist

  6. #6
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rmteo View Post

    Possibly because PIC16's are not really designed to do what you have in mind. Of 93 PIC16's that are listed on MicroCHIP's website, only 6 have self-write capability (which is what allows you to do what you trying to do). OTOH, of 155 PIC18's, 135 of them have self-write. AFAIK, ALL 24-bit core devices (PIC24F/H, dsPIC30 and dsPIC33) have this capability . . .
    Thanks for the suggestion. Yes, I am aware that, according to the online chart, only 6 of 99 16-series devices (the '88 and the members of the '88x family) have the capability. The 16F88 was recommended to me by another member of this forum as a good starting point for what I want to attempt since I was looking for a quick alternative to using EEPROM in a '648A.

    Charles, good to hear from you again! That's the kind of clear, concise information I appreciate. I'm going to do an empirical test of my trial hypothesis with a similar approach on a 16F88 using a counter and loop now that I have some sort of concept of what's going on "under the hood" and why.
    Last edited by RussMartin; - 24th October 2008 at 06:22.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Actually, there are 20 16F's that can write to their own flash memory.
    But there are 5 different methods, depending on the chip in use.

    > I can't believe that absolutely no one else has chimed in on this topic, though.

    After your first post, I started making a Flash movie, to show how to write to flash on a 16F88. And before I could even finish the first frame, this thread had already entered the "Confusion Zone", very similar to the "Twilight Zone".

    So I decided to expand it to include all the 16F's. Big mistake, takes too long. Should have stuck with the 16F88. Here's one of the frames which shows the different varieties. At that point the flash splits into 6 different explanations. 16F88 is #6.

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2926" /><!-- Name:  FlashChips.JPG
Views: 2041
Size:  34.7 KB -->

    It'll take too long to finish to be of help to you, and I don't think you are any closer to writing to flash on a 16F88, so I'll try to put it in Words.<hr>

    The only thing to really worry about, is that the Write to Flash only occurs when you write to the 4th word in the Block. Writing to the previous 3 words, only places the data in "Holding Registers".

    For instance, the following code which attempts to write to the 1st word and read it back ...
    Code:
    FlashAddr  VAR WORD
    FlashData  VAR WORD
    
    FlashAddr = $800
    FlashData = $123
    
    WRITECODE FlashAddr, FlashData
    READCODE  FlashAddr, FlashData
    Will return $3FFF in the FlashData variable, because the data was never written.

    However, this code ...
    Code:
    FlashAddr = $803
    FlashData = $123
    
    WRITECODE FlashAddr, FlashData
    READCODE  FlashAddr, FlashData
    Would return $123, because it wrote to the 4th word of the block.

    If you wanted to only write data to the First address, then you must also write data to the 4th address. If the 4th data is $3FFF then nothing actually gets written to that location.

    So this code ...
    Code:
    FlashAddr = $800
    FlashData = $123
    WRITECODE FlashAddr, FlashData
    
    FlashAddr = $803
    FlashData = $3FFF
    WRITECODE FlashAddr, FlashData
    
    FlashAddr = $800
    READCODE  FlashAddr, FlashData
    Will return $123, and only 1 Word has been written to memory.

    How do you know if it's the 4th word of the Block?
    By the Lowest 2-bits of the address. If they are both 1's then it's the 4th.
    Therefore, it's easy to make a subroutine to write a single word anywhere that's free.
    Code:
    WriteFlashWord: ; Set FlashAddr and FlashData before calling (Vars are Destroyed)
        WRITECODE FlashAddr, FlashData
        IF (FlashAddr & %11) != %11 THEN
            FlashAddr = FlashAddr | %11
            FlashData = $3FFF
            WRITECODE FlashAddr, FlashData
        ENDIF
    RETURN
    The chip should be Erased when it's programmed, so you only need to ERASECODE, if you need to overwrite the data.

    HTH,
    DT

  8. #8
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Thumbs up

    Darrel, much thanks.

    As always, you present a lucid, wonderfully informative yet concise solution. I printed a copy of your post and stapled it facing page 32 of the 16F88 data sheet. (My printed copy isn't duplexed.)

    I hope you will give thought to finishing the tutorial covering writing to flash for all of the 16F devices and posting it either here or on your own web site. It would be a valuable resource.

    And, of course, my apologies for straying into the Confusion Zone. "Who was that masked man?"

    If I'd seen your post sooner, I'd have saved myself the frustration (i.e., "learning experience") of my insufficiently informed empirical test . . . which, of course, returned nothing but $3FFF from every location! I did a similar loop with your guidance . . . which, of course, works as if charmed.
    Last edited by RussMartin; - 24th October 2008 at 19:44.
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,139


    Did you find this post helpful? Yes | No

    Default

    This thread put me in some thoughts about updating the firmware from a remote station.

    Is it possible to replace the existing firmware of a PIC with new one?

    And souldn't there be some kind of bootloader for this purpose?

    Ioannis

  10. #10
    Join Date
    Aug 2006
    Location
    Omaha, Nebraska USA
    Posts
    263


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Darrel Taylor View Post
    Therefore, it's easy to make a subroutine to write a single word anywhere that's free.
    Code:
    WriteFlashWord: ; Set FlashAddr and FlashData before calling (Vars are Destroyed)
        WRITECODE FlashAddr, FlashData
        IF (FlashAddr & %11) != %11 THEN
            FlashAddr = FlashAddr | %11
            FlashData = $3FFF
            WRITECODE FlashAddr, FlashData
        ENDIF
    RETURN
    The chip should be erased when it's programmed, so you only need to ERASECODE if you need to overwrite the data.
    This works like a dream!

    Thanks, Darrel!
    Russ
    N0EVC, xWB6ONT, xWN6ONT

    "Easy to use" is easy to say.

Similar Threads

  1. Writing & Reading to iButton EEPROM
    By crhomberg in forum Code Examples
    Replies: 2
    Last Post: - 6th October 2008, 19:40
  2. Writing and reading to a 24LC1025
    By Angus Anderson in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th April 2007, 11:49
  3. reading, writing, and displaying from eeprom
    By Rhatidbwoy in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th January 2006, 22:05
  4. 16F88 reading Analog Input
    By thunderstrike44 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th August 2004, 22:41
  5. Writing / Reading EEPROM 24LC256 Problem
    By schmoddel in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th February 2004, 18:55

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts