James Wages
2016-09-28 03:03:37 UTC
I've almost completed my 16F1508 code to generate square wave audio tones. The only thing left is the code required to save 1 of 16 different user-programmable settings as a single 8-bit word/byte into non-volatile memory. I've written ASM code for EEPROM PICs in the past, but my 16F1508 has FLASH -- storage normally used as program memory. So I am trying to figure out how to properly code flash ERASE-WRITES and READS.
I have read the entire section on Flash, pages 90-105 of the datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/40001609E.pdf
And I have also read the unfortunately C-oriented information given in AN1673:
http://ww1.microchip.com/downloads/en/AppNotes/00001673A.pdf
NOTE: I am a PIC Assembly guy, and although I know some of you may wish to persuade me to learn C in light of the FLASH libraries available, I wish to stick with ASM. I am not going to consider C, so let's stick with a strictly ASM discussion.
Here are my questions:
1. RESERVING HIGH-ENDURANCE FLASH MEMORY. Note page 7 in the AN1673 pdf linked above where it mentions a setting only useful when programming in C. Naturally, I want to know how I write the equivalent of that within my ASM code. Surely there must be a way to reserve the High Endurance Flash using ASM code inside my program, akin to how I can write CONFIG BIT settings in my code. I know that High Endurance Flash on the 16F1508 consists of 4 rows (32 bytes in each row), addressed from 1F80 to 1FFF. What ASM code do I use to ensure my MPASM won't overwrite 1F80 to 1FFF when it writes my program code to the PIC?
2. The Flash code I have written closely follows the 16F1508 Datasheet. I modified the code only slightly, and I improved the notes. You can review my code here (ERASE, WRITE and READ code):
https://cl.ly/442m3y1E263s
I feel confident my ERASE code is correct, but please have a close look at it anyway. The question I have primarily centers on my WRITE code. For example:
movlw LOW DATA_ADDR ; Load initial data address
movwf FSR0L
movlw HIGH DATA_ADDR ; Load initial data address
movwf FSR0H
Are those LOW and HIGH "DATA_ADDR" considered to be user RAM locations that I must define and then fill with something? Or do I just write those 4 lines of code as-is? If user RAM locations that I must define, what do I fill them with? My data? (But it seems to want an "Address" not data.)
Also within the WRITE code (as per the code given in the datasheet), it says:
"64 bytes of data are loaded"
But I don't see how "64 bytes" (as opposed to 32 or even 128 bytes) is established in the datasheet's WRITE code.
In my application, I only need to deal with a single row (32 bytes), not two rows (64 bytes). I need to WRITE & READ a single 8-bit word to/from Flash. The device I am creating will be powered ON/OFF often, and there are settings that need to survive that ON/OFF cycle, which I want to store in that single 8-bit word in Flash. There will be a total of 16 settings stored in only a single 8-bit byte of FLASH, exactly as follows:
00000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
00001011
00001100
00001101
00001110
00001111
The user will use DIP switches to tell the MCU which of the 16 settings they wish to program. For example, if they select setting 3, I would need to WRITE "00000010" into a single 8-bit word of Flash. And yes, I fully understand Flash must be programmed by rows, which means 32 words, rather than just the 1 word that I need. But again, I am unsure of how to properly put together the WRITE code in ASM, hence this post.
So if I want to WRITE "00000010" to Flash, I would put "00000010" into a RAM that I defined named "LOW DATA_ADDR" (or whatever name I want to give it) and then either store "0" in "HIGH DATA_ADDR" or simply not use "HIGH DATA_ADDR" at all, since I only need to store one 8-bit word in Flash?
I look forward to your thoughts and advice.
Thank you,
James W.
I have read the entire section on Flash, pages 90-105 of the datasheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/40001609E.pdf
And I have also read the unfortunately C-oriented information given in AN1673:
http://ww1.microchip.com/downloads/en/AppNotes/00001673A.pdf
NOTE: I am a PIC Assembly guy, and although I know some of you may wish to persuade me to learn C in light of the FLASH libraries available, I wish to stick with ASM. I am not going to consider C, so let's stick with a strictly ASM discussion.
Here are my questions:
1. RESERVING HIGH-ENDURANCE FLASH MEMORY. Note page 7 in the AN1673 pdf linked above where it mentions a setting only useful when programming in C. Naturally, I want to know how I write the equivalent of that within my ASM code. Surely there must be a way to reserve the High Endurance Flash using ASM code inside my program, akin to how I can write CONFIG BIT settings in my code. I know that High Endurance Flash on the 16F1508 consists of 4 rows (32 bytes in each row), addressed from 1F80 to 1FFF. What ASM code do I use to ensure my MPASM won't overwrite 1F80 to 1FFF when it writes my program code to the PIC?
2. The Flash code I have written closely follows the 16F1508 Datasheet. I modified the code only slightly, and I improved the notes. You can review my code here (ERASE, WRITE and READ code):
https://cl.ly/442m3y1E263s
I feel confident my ERASE code is correct, but please have a close look at it anyway. The question I have primarily centers on my WRITE code. For example:
movlw LOW DATA_ADDR ; Load initial data address
movwf FSR0L
movlw HIGH DATA_ADDR ; Load initial data address
movwf FSR0H
Are those LOW and HIGH "DATA_ADDR" considered to be user RAM locations that I must define and then fill with something? Or do I just write those 4 lines of code as-is? If user RAM locations that I must define, what do I fill them with? My data? (But it seems to want an "Address" not data.)
Also within the WRITE code (as per the code given in the datasheet), it says:
"64 bytes of data are loaded"
But I don't see how "64 bytes" (as opposed to 32 or even 128 bytes) is established in the datasheet's WRITE code.
In my application, I only need to deal with a single row (32 bytes), not two rows (64 bytes). I need to WRITE & READ a single 8-bit word to/from Flash. The device I am creating will be powered ON/OFF often, and there are settings that need to survive that ON/OFF cycle, which I want to store in that single 8-bit word in Flash. There will be a total of 16 settings stored in only a single 8-bit byte of FLASH, exactly as follows:
00000000
00000001
00000010
00000011
00000100
00000101
00000110
00000111
00001000
00001001
00001010
00001011
00001100
00001101
00001110
00001111
The user will use DIP switches to tell the MCU which of the 16 settings they wish to program. For example, if they select setting 3, I would need to WRITE "00000010" into a single 8-bit word of Flash. And yes, I fully understand Flash must be programmed by rows, which means 32 words, rather than just the 1 word that I need. But again, I am unsure of how to properly put together the WRITE code in ASM, hence this post.
So if I want to WRITE "00000010" to Flash, I would put "00000010" into a RAM that I defined named "LOW DATA_ADDR" (or whatever name I want to give it) and then either store "0" in "HIGH DATA_ADDR" or simply not use "HIGH DATA_ADDR" at all, since I only need to store one 8-bit word in Flash?
I look forward to your thoughts and advice.
Thank you,
James W.
--
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist