完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我试图找出如何使用汇编代码在16F18854上写入初始EEPROM地址的数据。遗憾的是,数据表缺乏清晰性:HTTP://WW1.Microchip .com /…EVICEDOC/4001826B.PDF请将数据表PDF打开到第153页。第10.2节数据EEPROM存储器说,“数据EEPROM存储器由256字节的用户数据存储器组成。EEPROM为8位用户定义的数据提供存储位置。“如果真的只有8位”,为什么NVMDAth:NVMDATL寄存器对(16位)需要写入EEPROM?换句话说,如果真的8位,我是否只允许写入Low Byte,NVMDATL?第二个相关问题…以下是我的ASM代码。看起来正确吗?你发现什么不对劲了吗?
以上来自于百度翻译 以下为原文 I am trying to figure out how to WRITE data the initial EEPROM address on a 16F18854 using Assembly code. Sadly, the datasheet is lacking in clarity: http://ww1.microchip.com/...eviceDoc/40001826B.pdf Please open the datasheet PDF to page 153. Section 10.2 Data EEPROM Memory says, "Data EEPROM Memory consists of 256 bytes of user data memory. The EEPROM provides storage locations for 8-bit user defined data." If truly only "8-bit" then why is the NVMDATH:NVMDATL register pair (16-bits) required to WRITE to EEPROM? In other words, if truly 8-bit, am I allowed to WRITE to only to the Low Byte, NVMDATL? Second related question... The following is my ASM code. Does it look correct? Do you spot anything wrong or out of sequence? ; --------------- ; WRITE to EEPROM ; --------------- ; * EEPROM Code-protection must be disable to READ/WRITE (Config5 -> "_CPD_OFF") ; EEPROM Address Setup: banksel NVMCON1 ; [Bank 16] bsf NVMCON1, NVMREGS ; Access EEPROM. bsf NVMCON1, WREN ; Allow Program/Erase. movlw b'11110000' ; Address High Byte for WRITE to F000h. movwf NVMADRH clrf NVMADRL ; F000h = 11110000 00000000 ; Data to WRITE to EEPROM address above: movlw b'00000001' ; Low Byte data to WRITE movwf NVMDATL movlw b'10000000' ; High Byte data to WRITE movwf NVMDATH ; Unlock Sequence (required for WRITE to EEPROM): bcf INTCON, GIE ; Disable Interrupts (important) ; Next line not needed because WREN was already set to 1 above? ; bsf NVMCON1, WREN ; Enable WRITE/ERASE. movlw 0x55 ; Put 55h into NVMCON2 register. movwf NVMCON2 movlw 0xAA ; Put AAh into NVMCON2 register. movwf NVMCON2 bsf NVMCON1, WR ; Set WR bit to begin WRITE/ERASE. bsf INTCON, GIE ; Re-enable Interrupts. WRITEwater btfsc NVMCON1, WR ; WRITE finished? goto WRITEwater ; No. Loop. goto MainProgram ; Yes. |
|
相关推荐
14个回答
|
|
因为使用相同的寄存器来访问闪存,它是14位宽的。NVMDAH在访问EEPROM时不使用,它只有8位宽。我没有在该芯片中这样做,但是您的代码看起来不错,除非您不使用相同的代码来写入Flash,就不需要触摸NVMDAH。
以上来自于百度翻译 以下为原文 Because the same registers are used to access FLASH memory, which is 14 bits wide. NVMDATH is not used when accessing EEPROM, which is only 8 bits wide. I've not done this in that chip, but your code looks ok, except there's no need to touch NVMDATH if you aren't using the same code to write to FLASH. |
|
|
|
如果上面所说的是真的,那么你如何解释同样的数据表第156页的第十节4.3节呢?它说:一个EEPROM字是用NVMDATA写成的。很明显,这是一个数据表错误,看到“NVMDATA”是不存在的。唯一合乎逻辑的结论是,他们的意思是写:一个EEPROM字是用NVMDAth:NVMDATL寄存器对写的。因此,我将感谢你的想法。如果你认为它不是“NVMDAth:NVMDATL寄存器对”,那么什么寄存器是保存我希望写入EEPROM的数据?
以上来自于百度翻译 以下为原文 If what you say above is true, then how do you explain Section 10.4.3 on page 156 of that same datasheet? It says this: A single EEPROM word is written with NVMDATA. Clearly, that is a datasheet error, seeing "NVMDATA" is no where to be found outside that sentence. The only logical conclusion is that they meant to write this: A single EEPROM word is written with the NVMDATH:NVMDATL register pair.That is the assumption upon which my opening post is based. I would therefore appreciate your thoughts on that. If you argue that it is NOT "the NVMDATH:NVMDATL register pair," then what register is to hold the data I wish to write to EEPROM? |
|
|
|
我将解释一个EEPROM字是用NVMDATA写的。实际上,意味着一个EEPROM字是用NVMDATA写成的,我认为它们应该是“字节”而不是“Word”。这个部分可能只是从Flash区段的一个剪切和粘贴,做出了微小的变化。“Word”并不总是意味着16位。如果你阅读整个EEPROM部分,他们清楚地指出它一次写入一个字节。
以上来自于百度翻译 以下为原文 I would interpret A single EEPROM word is written with NVMDATA. to actually mean A single EEPROM word is written with NVMDATAL and I think they should have said "byte" instead of "word". That section was probably just a cut and paste from the FLASH section, with minimal changes made. "Word" does not always mean 16 bits. If you read the whole EEPROM section, they clearly spell out that it writes a byte at a time. |
|
|
|
只使用NVMDATAL编程EEPROM。好啊。有趣。正因为如此,我发现了许多其他数据表错误,所以我打开了Microchip的一张票让他们知道。(例如,在第274页,寄存器20-8应该说“CWGxCLKCON”不是“CWGXCLK”。许多蓝色链接都被破坏了,当你点击时没有带你去哪里。TimeR2“期间寄存器”在数据表中被错误地称为“PR2”,即使“PR2”没有被分配给该数据表中的任何银行,但在某些地方,这个相同的“时段”寄存器被正确地称为“T2PR”银行5。还有更多——我发现了10个。我会发布一些更新的ASM代码来帮助后来的人,但是在我这样做之前,请告诉我如何复制/粘贴代码,这样我就不会丢失空间。当我从我的纯文本编辑器复制我的ASM代码,然后粘贴到这里的一个帖子(作为“代码”),许多需要的空间被剥离。这迫使我手动添加它们以使代码正确缩进,正如您在我以前的帖子中看到的那样。这太荒谬了。我只想复制/粘贴,并有间距(我使用的空间,而不是标签)不被剥离。我也希望有一种方法来正确地格式化ASM代码,但是弹出窗口不提供ASM选项,这是荒谬的。谢谢。
以上来自于百度翻译 以下为原文 Program the EEPROM using only NVMDATAL. OK. Interesting. Well, because of that and because of the many other datasheet errors I've found, I've opened a ticket with Microchip to let them know about it. (For example, on page 274, REGISTER 20-8 should say "CWGxCLKCON" not "CWGxCLK". Many of the blue links are broken and take you no where when clicked. The Timer2 "period register" is incorrectly referred to as "PR2" throughout the datasheet even though "PR2" is not assigned to any bank in that datasheet, yet in some places this same "period" register is correctly referred to as "T2PR" Bank 5. And there are more too -- I found 10 total.) I will post some updated ASM code to help others who later come across this thread, but before I do that, please tell me how to copy/paste code so I don't lose spaces. When I copy my ASM code from my plain text editor and then paste it into a post here (as "Code"), many of the needed spaces are stripped out. That forces me to manually add them back in to make the code properly indented, as you saw in my previous post. That is ridiculously bothersome to do. I just want to copy/paste and have the spacing (I use spaces, not tabs) not be stripped away. I also wish there was a way to properly color format the ASM code too, but the popup doesn't provide an ASM option, which is ridiculous. Thanks. |
|
|
|
使用编辑器的“完整版本”,而不是“快速回复”窗口。使用“源代码”按钮(第三行中的第三个按钮)并将文本粘贴到出现的窗口中。实际上,空间剥离实际上是谷歌浏览器正在做的事情。在这个论坛上,它在Internet Explorer中工作得很好。我在Chrome支持论坛上发现了一个话题,说Chrome开发者意识到了这个问题,并且无意修复它。
以上来自于百度翻译 以下为原文 Use the "Full Version" of the editor, not the "Quick Reply" window. Use the "Source code" button (third button in third row) and paste your text into the window that appears. The space stripping actually seems to be something Google Chrome is doing. It used to work fine in Internet Explorer on this forum. I found a topic on the Chrome support forum saying the Chrome developers are aware of the problem, and have no intention of fixing it. |
|
|
|
实际上我使用了完全版本编辑器,点击了源代码按钮,但在Safari上,我的5K iMac空间被剥离了。你验证它是否在Firefox中工作(没有空间剥离)?
以上来自于百度翻译 以下为原文 I actually did use the Full Version editor and did click the Source Code button, but in Safari on my 5K iMac the spaces get stripped out. Have you verified if it works in FireFox (no space-stripping)? |
|
|
|
铬试验
以上来自于百度翻译 以下为原文 Test from Chrome ; --------------- ; WRITE to EEPROM ; --------------- ; * EEPROM Code-protection must be disable to READ/WRITE (Config5 -> "_CPD_OFF") ; EEPROM Address Setup: banksel NVMCON1 ; [Bank 16] bsf NVMCON1, NVMREGS ; Access EEPROM. bsf NVMCON1, WREN ; Allow Program/Erase. movlw b'11110000' ; Address High Byte for WRITE to F000h. movwf NVMADRH clrf NVMADRL ; F000h = 11110000 00000000 ; Data to WRITE to EEPROM address above: movlw b'00000001' ; Low Byte data to WRITE movwf NVMDATL movlw b'10000000' ; High Byte data to WRITE movwf NVMDATH ; Unlock Sequence (required for WRITE to EEPROM): bcf INTCON, GIE ; Disable Interrupts (important) ; Next line not needed because WREN was already set to 1 above? ; bsf NVMCON1, WREN ; Enable WRITE/ERASE. movlw 0x55 ; Put 55h into NVMCON2 register. movwf NVMCON2 movlw 0xAA ; Put AAh into NVMCON2 register. movwf NVMCON2 bsf NVMCON1, WR ; Set WR bit to begin WRITE/ERASE. bsf INTCON, GIE ; Re-enable Interrupts. WRITEwater btfsc NVMCON1, WR ; WRITE finished? goto WRITEwater ; No. Loop. goto MainProgram ; Yes. |
|
|
|
从Firefox测试(刚刚在“快速回复”)
以上来自于百度翻译 以下为原文 Test from Firefox (just in "Quick Reply") ; --------------- ; WRITE to EEPROM ; --------------- ; * EEPROM Code-protection must be disable to READ/WRITE (Config5 -> "_CPD_OFF") ; EEPROM Address Setup: banksel NVMCON1 ; [Bank 16] bsf NVMCON1, NVMREGS ; Access EEPROM. bsf NVMCON1, WREN ; Allow Program/Erase. movlw b'11110000' ; Address High Byte for WRITE to F000h. movwf NVMADRH clrf NVMADRL ; F000h = 11110000 00000000 ; Data to WRITE to EEPROM address above: movlw b'00000001' ; Low Byte data to WRITE movwf NVMDATL movlw b'10000000' ; High Byte data to WRITE movwf NVMDATH ; Unlock Sequence (required for WRITE to EEPROM): bcf INTCON, GIE ; Disable Interrupts (important) ; Next line not needed because WREN was already set to 1 above? ; bsf NVMCON1, WREN ; Enable WRITE/ERASE. movlw 0x55 ; Put 55h into NVMCON2 register. movwf NVMCON2 movlw 0xAA ; Put AAh into NVMCON2 register. movwf NVMCON2 bsf NVMCON1, WR ; Set WR bit to begin WRITE/ERASE. bsf INTCON, GIE ; Re-enable Interrupts. WRITEwater btfsc NVMCON1, WR ; WRITE finished? goto WRITEwater ; No. Loop. goto MainProgram ; Yes. |
|
|
|
这证明了你的代码间隔将在Chrome、Firefox和(在我的测试)Safari中被修改。更不用说颜色不正确的颜色了。哦,也许我们对这个论坛的要求太高了!
以上来自于百度翻译 以下为原文 Which proves that your code spacing will be screwed up in Chrome, Firefox and (in my test) Safari. Not to mention the way the color is improperly colored. Oh well, maybe we ask too much of this forum! |
|
|
|
如果你在老照片上使用EEPROM,这些工作方式是相同的;它们刚刚重命名所有寄存器:EECON1-GT;NVMCON1ECON2-& GT;NVMCON2EDATA & GT;NVMDATLeEADR & Gt;NVMADReLeEADR& & NVMADRHORKEDISTION/DROBULD,它们都是相同的,甚至在寄存器中使用相同的位名称。唯一的区别是你必须写0xF0到NVMADRH。
以上来自于百度翻译 以下为原文 If you've used EEPROM on older PICs, these work the same way; they've just renamed all the registers: EECON1 -> NVMCON1 EECON2 -> NVMCON2 EEDATA -> NVMDATL EEADR -> NVMADRL EEADRH ->NVMADRH Reading/writing/unlocking are all the same and even use the same bit names in the registers. The only difference is you have to write 0xF0 to NVMADRH. |
|
|
|
我们也必须写“0x00”到NVMDAH,还是它被忽略了?如果忽略了,那么你觉得我之前发布的ASM代码怎么样?命令的代码和顺序看起来正确吗?
以上来自于百度翻译 以下为原文 Must we also write "0x00" to NVMDATH, or is it simply ignored? If ignored, then what do you think of the ASM code I posted earlier? Does the code and sequence of commands look right? |
|
|
|
你的代码对我来说很好。数据表中没有什么能让我相信NVMdTh需要有一个特定的值,而且我从来没有给它写过。您的代码假定在调用时启用中断,更常见的是保存GEE状态并在返回之前恢复它。
以上来自于百度翻译 以下为原文 Your code looks fine to me. There's nothing in the data sheet that leads me to believe NVMDATH needs to have a particular value, and I've never written to it. Your code assumes interrupts were enabled when it's called; it's more common to save the state of GIE and restore it before you return. |
|
|
|
我已经在第2页回答了这个问题,我的回答没有改变。
以上来自于百度翻译 以下为原文 I already answered this back in post#2, and my answer has not changed. |
|
|
|
使用Firefox 54.0.1发布,使用快速回复和手动输入的代码标签:
以上来自于百度翻译 以下为原文 Posted with Firefox 54.0.1, using quick reply and manually entered code tags: ;/* ; --------------- ; WRITE to EEPROM ; --------------- ; * EEPROM Code-protection must be disable to READ/WRITE (Config5 -> "_CPD_OFF") ; EEPROM Address Setup: banksel NVMCON1 ; [Bank 16] bsf NVMCON1, NVMREGS ; Access EEPROM. bsf NVMCON1, WREN ; Allow Program/Erase. movlw b'11110000' ; Address High Byte for WRITE to F000h. movwf NVMADRH clrf NVMADRL ; F000h = 11110000 00000000 ; Data to WRITE to EEPROM address above: movlw b'00000001' ; Low Byte data to WRITE movwf NVMDATL movlw b'10000000' ; High Byte data to WRITE movwf NVMDATH ; Unlock Sequence (required for WRITE to EEPROM): bcf INTCON, GIE ; Disable Interrupts (important) ; Next line not needed because WREN was already set to 1 above? ; bsf NVMCON1, WREN ; Enable WRITE/ERASE. movlw 0x55 ; Put 55h into NVMCON2 register. movwf NVMCON2 movlw 0xAA ; Put AAh into NVMCON2 register. movwf NVMCON2 bsf NVMCON1, WR ; Set WR bit to begin WRITE/ERASE. bsf INTCON, GIE ; Re-enable Interrupts. WRITEwater btfsc NVMCON1, WR ; WRITE finished? goto WRITEwater ; No. Loop. goto MainProgram ; Yes. */ |
|
|
|
只有小组成员才能发言,加入小组>>
5243 浏览 9 评论
2035 浏览 8 评论
1955 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3208 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2258 浏览 5 评论
778浏览 1评论
671浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
597浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
679浏览 0评论
577浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 09:56 , Processed in 1.577973 second(s), Total 102, Slave 86 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号