完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
所以我知道位置200000到200007是ID位置,每个位置只有4位宽。我知道在我的源代码中使用IDOLC擦除这些位置,但是如何在运行时擦除这些位置呢?我希望周期性地动态地改变这些位置。我使用的方法是首先擦除0x20000行,然后将My3字节写入这些位置,每次一个字节(占用6个位置)。但是,它损坏了我的引导代码,或者因为我的引导程序开始奇怪。例如,A(x=0;x& lt;50;x++){dodo}}在调试器中显示,x虽然递增很好,但却超过50。所以事情搞砸了。如果我不给用户ID位置写,for循环是按设计的那样工作的。有人有例子,至少在最新的情况下,如何删除用户ID空间“适当”的方式吗?它擦除64个字节开始在0x20 000或只有8个位置?静态空隙EraseUsRID(UtiT32×T ADDR){UIT88T GiBITValue= ItCnBITS.GIE;//保存中断启用TBLPTRU=(UIT88T)((ADDR & GT;16)和0xFF);TBLPTRH=(UIT88T)((ADDR & Gt;8)和0xFF);TBLPTRL=(UIT88T)(ADDR和0xFF);ECON1BITS=1;ECON1BITE我的擦除功能:PGD=1;ECON1BIT。CFGS=0;ECON1BIT。WRN=1;ItCONTITES。GEE=0;//禁用中断ECON2= 0x55;EECON2= 0xAA;EECON1BITS=1;//擦除像风一样!IGCONBITI.GIE比特值;//恢复中断启用ECON1BITS=0;//禁用写入内存;静态空隙写入器ID(UINT8*T*Flash WBUFPTR){INTI;UINT8YT GiBIT值=INTCONBITS。GIE;//保存中断使能TBLPTRU=(UINT8YT)0x20;TBLPTRH=(UINT8YT)0;TBLPTRL=(UINT8YT)0;/写入3个字节,使用6个LOC单元(每个1个字节)。AT=(Flash WrBFPTR(0)& 0x0f);ASM(TBLWT*+);TablAT=(Flash WrBfpTr[ 1 ] & gt;4);ASM(TBLWTTR(1)& 0x0f);ASM(“TBLWT*+”);TablAT=(Flash WrBufPTR[2)& gt;4);ASM(TBLWT*+);TablAT=(FllWrBu)TablAT=(Flash WrBufpTR〔0〕& gt;4);ASM(“TBLWT*+”);〔2〕和(0x0f);TBLPTRU=(UIT88T)0x20;TBLPTRH=(UIT88T)0;ECON1TBIT= EPEGD=1;EECON1BITS=0;ECON1BITS=1;ICONTITES。GIE=0;//禁用中断ECON2= 0x55;EECON2= 0xAA;EECON1BITS。WR=1;/写得像风一样!FPTRGie= GiBIT值;//Read中断启用ECON1BITS=0;/ /禁用写入到内存}
以上来自于百度翻译 以下为原文 So I understand locations 200000 to 200007 are ID locations and are only 4 bits wide per location. I know to erase these locations using IDLOC in my source code but how do I erase these locations at run time? I want to dynamically change these locations periodically. An approach I used was to first erase the row at 0x200000, then write my 3 bytes to these locations, a nibble at a time [taking up 6 locations]. This worked however it damaged my boot code or something because my bootloader started acting weird. For example, a for(x = 0; x < 50; x++) {do something} showed in the debugger that X, although incrementing fine, went WAY past 50.. so something got messed up. If I don't write to the User Id location, the for-loop works as designed. Does anyone have examples of, at the very VERY least, how to erase User ID space the "proper" way? Does it erase 64-bytes starting at 0x200000 or only the 8 locations? My erase function: static void eraseUserID(uint32_t addr) { uint8_t GIEBitValue = INTCONbits.GIE; // Save interrupt enable TBLPTRU = (uint8_t) ((addr >> 16) & 0xff); TBLPTRH = (uint8_t) ((addr >> 8) & 0xff); TBLPTRL = (uint8_t) (addr & 0xff); EECON1bits.FREE = 1; EECON1bits.EEPGD = 1; EECON1bits.CFGS = 0; EECON1bits.WREN = 1; INTCONbits.GIE = 0; // Disable interrupts EECON2 = 0x55; EECON2 = 0xAA; EECON1bits.WR = 1; // Erase like the wind! INTCONbits.GIE = GIEBitValue; // Restore interrupt enable EECON1bits.WREN = 0; // Disable writes to memory } static void writeUserID(uint8_t *flashWrBufPtr) { int i; uint8_t GIEBitValue = INTCONbits.GIE; // Save interrupt enable TBLPTRU = (uint8_t) 0x20; TBLPTRH = (uint8_t) 0; TBLPTRL = (uint8_t) 0; // Write 3 bytes which uses 6 LOC cells (1 nibble each). TABLAT = (flashWrBufPtr[0] >> 4); asm("TBLWT*+"); TABLAT = (flashWrBufPtr[0] & 0x0f); asm("TBLWT*+"); TABLAT = (flashWrBufPtr[1] >> 4); asm("TBLWT*+"); TABLAT = (flashWrBufPtr[1] & 0x0f); asm("TBLWT*+"); TABLAT = (flashWrBufPtr[2] >> 4); asm("TBLWT*+"); TABLAT = (flashWrBufPtr[2] & 0x0f); asm("TBLWT*"); TBLPTRU = (uint8_t) 0x20; TBLPTRH = (uint8_t) 0; TBLPTRL = (uint8_t) 0; EECON1bits.EEPGD = 1; EECON1bits.CFGS = 0; EECON1bits.WREN = 1; INTCONbits.GIE = 0; // Disable interrupts EECON2 = 0x55; EECON2 = 0xAA; EECON1bits.WR = 1; // Write like the wind! INTCONbits.GIE = GIEBitValue; // Restore interrupt enable EECON1bits.WREN = 0; // Disable writes to memory } |
|
相关推荐
8个回答
|
|
我从来没有尝试在运行时写入ID位置,但是我知道配置寄存器中的WDT后标器在写入之前不需要被擦除:HTTP://www. McCHIP.COM/FUMMS/FUNDSPE/6962477可以在一天内尝试ID位置,但是现在我没有时间。
以上来自于百度翻译 以下为原文 I have never tried to write to the ID Locations during runtime, but I do know that the WDT postscaler in the configuration register does NOT need to be erased before written: http://www.microchip.com/forums/FindPost/696477 I might try the ID Locations one day, but now I don't have the time. |
|
|
|
OP正在讨论ID位置。从PIC18数据表:ID位置SETHOLD内存位置(200 000 0H-200 00 7H)被指定为ID位置,用户可以在其中存储校验和或其他代码标识号。在正常执行过程中,TBRD和TBLWT指令在程序/验证过程中都是可读的和可写的。当设备受代码保护时,ID位置可以被读取。
以上来自于百度翻译 以下为原文 OP is talking about the ID Locations. From a PIC18 datasheet: ID Locations Eight memory locations (200000h-200007h) are designated as ID locations, where the user can store checksum or other code identification numbers. These locations are both readable and writable during normal execution through the TBLRD and TBLWT instructions or during program/verify. The ID locations can be read when the device is code-protected. |
|
|
|
别开玩笑了。我很难找出如何从C读取ID位置。我得到编译器或链接错误。有人能告诉我怎么做吗?我使用PIC 18F66 K22与XC8编译器。我已经尝试声明const变量@ 0x20000,但那些只导致链接错误。我已经玩了各种变体的TracePracm配置,看看它是否会起作用。变量名称IDLoCX似乎未被编译器识别。PICC.IN文件有一个USEIDMEM部分,所以我假设链接器知道这个ID内存。编译程序吗?我必须学习PIC汇编程序吗?
以上来自于百度翻译 以下为原文 No kidding. I am totally frustrated trying to figure out how to read the ID locations from C. I get either compiler or linker errors. Can anyone tell me how to do this? I'm using a PIC 18F66K22 with the XC8 compiler. I've tried declaring const variables @ 0x200000 but those only result in linker errors. I've played with variations of the #pragma config to see if that would work. Variable name IDLOCx does not appear to be recognized by the compiler. The picc.ini file has a USERIDMEM section so I presume the linker knows about this ID memory. Does the compiler? Do I have to learn PIC assembler? |
|
|
|
你是否已经测试了CONST未签名的char IDORCs(8)@ 0x20000;确保它是全局的,而不是函数内的。
以上来自于百度翻译 以下为原文 Have you tried const unsigned char idlocs[8] @ 0x200000; Make sure it's global, not inside a function. |
|
|
|
这是我试过的第一件事。似乎如此合乎逻辑。程序内存变量在一个固定的地址。但是,我得到以下链接器错误::0:错误:(1346)在类“IDLoC”(最大未使用的连续范围0x0)中找不到PSXCT“IDLoc”的0x8字。
以上来自于百度翻译 以下为原文 That's the first thing I tried. Seems so logical. Program memory variable at a fixed address. But I get the following linker error: :0: error: (1346) can't find 0x8 words for psect "idloc" in class "IDLOC" (largest unused contiguous range 0x0) |
|
|
|
HiIT不咬。它可以帮助很多熟悉的人。从第14页到第110页,我不希望编译器生成特殊代码来访问ID位置,但是你可以尝试搜索“PLIB”来达到这个目的。如果你找不到它们,那么是时候学习一点ASM了。将其内嵌在“C”函数的主体中。
以上来自于百度翻译 以下为原文 Hi It doesn't bite. It can help a lot beeing familiar with. From post #14 by 1and0 I won't expect the compiler to generate special code to access the ID locations, but you can try searching the "plibs" for some function(s) for that purpose. If you don't find them, then its time to learn a little ASM and inline it in the body of a 'C' function. Best regards Jorge |
|
|
|
你需要的一切都是在PIC数据表和编译器手册中。试试这个:
以上来自于百度翻译 以下为原文 Everything you need is in the PIC datasheet and compiler manual. Try this: extern const unsigned char userID[8] @ 0x200000; uint8_t ReadFlash(uint32_t addr) { TBLPTR = addr; asm("TBLRD"); return TABLAT; } |
|
|
|
另一条消息线程在MCC中对我有可能访问ID内存。我找到了内存组件,它创建了一个几乎和1AND0写的一样的函数。它需要一个小的修复,因为它没有把EECON1位放在正确的状态。我有问题验证ID读函数是工作的,因为XC8配置语法似乎不起作用。但是我认为是MPLAB ICD加载总是擦除我的芯片上所有导致ID的闪存。读到总是读0xFFS.“豪尔赫,不幸的是,我发现PIC汇编程序非常困难。我脑子里有很多其他的处理器(英特尔、摩托罗拉、ARM),似乎没有空间来填补PIC Sad。
以上来自于百度翻译 以下为原文 Another message thread clued me in that MCC might have something for accessing ID memory. I found the memory component and it created a function that looks almost exactly like what 1and0 wrote. It needed a little fixing because it didn't put the EECON1 bits in the correct state. I had problems verifying the ID read function was working because the XC8 config pragmas didn't seem to work. But I think it is the MPLAB ICD loading that is always erasing all flash on my chip that is causing the ID read to always read 0xFFs. @Jorge Unfortunately, I've found PIC assembler very difficult. I have so many other processors in my head (Intel, Motorola, ARM) that there seems to be no room for PIC sad: . |
|
|
|
只有小组成员才能发言,加入小组>>
5170 浏览 9 评论
2001 浏览 8 评论
1931 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3176 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2228 浏览 5 评论
737浏览 1评论
622浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
509浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
635浏览 0评论
531浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 16:56 , Processed in 1.488290 second(s), Total 92, Slave 76 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号