Re: 關於PIC24FJ16GA002 PROGRAM MEMORY 寫入問題
|
||||
---|---|---|---|---|
新會員
|
謝謝版主 已可使用
1.使用 VIEW PROGRAM MEMORY 並無法直接觀察FLASH 剛寫入的值 2. 其餘同版大所說
發表於: 2008/4/11 16:49
|
|||
|
Re: 關於PIC24FJ16GA002 PROGRAM MEMORY 寫入問題
|
||||
---|---|---|---|---|
版主
|
從 PIC24FJ Family Reference Manual Section 4. Program Memory
http://www.microchip.com/stellent/idc ... Id=1335&dDocName=en026374 所指, 自我燒錄前須作一次 512 x 24-bit 的 Block Erase後才可以每次寫入 64 x 24-bit 的指令,而且寫入是先寫到 Holding Latch 裡,待下燒錄命令時才會將整個64 Words的指令一次寫進去。 你所提的範例只會寫入一個 Word,但其餘的 63 words 因為沒有設定其內容,但也會一併寫進去,只是不知其值為何。 底下是簡體体版的 Reference Manual 所剪下來的說明: 1. 读取程序存储器的8 行(512 条指令),并存储在数据RAM 中。 2. 用所需的新数据更新RAM 中的程序数据。 3. 擦除该区块: a) 将NVMOP 位(NVMCOM<3:0>)设置为0010 以配置块擦除。将ERASE (NVMCOM<6>)和WREN (NVMCOM<14>)位置1。 b) 将要擦除的块的起始地址写入TBLPAG 和W 寄存器。 c) 将55h 写入NVMKEY。 d) 将AAh 写入NVMKEY。 e) 将WR 位置1 (NVMCOM <15>)。擦除周期开始,在擦除周期中CPU 会暂停。当 擦除结束时, WR 位会自动清零。 4. 将数据RAM 中的前64 条指令写入程序存储缓冲器(见第4.5 节“写程序存储器”)。 5. 将程序块写入闪存存储器: a) 将NVMOP 位设置为0001 以配置行编程。将ERASE 位清零,将WREN 位置1。 b) 将55h 写入NVMKEY。 c) 将AAh 写入NVMKEY。 d) 将WR 位置1。编程周期开始,在写周期中CPU 会暂停。写入闪存存储器结束时,WR 位会自动清零。 6. 通过递增TBLPAG 中的值,使用数据RAM 中的下一批可用的64 条指令重复步骤4 和5, 直到全部512 条指令写回闪存存储器中。
發表於: 2008/4/10 10:57
|
|||
|
Re: 關於PIC24FJ16GA002 PROGRAM MEMORY 寫入問題
|
||||
---|---|---|---|---|
新會員
|
但版主 以下為DATA SHEET所寫
是否可僅寫入1 WORD資料 謝謝 4.6.2 PROGRAMMING A SINGLE WORD OF FLASH PROGRAM MEMORY If a Flash location has been erased, it can be programmed using table write instructions to write an instruction word (24-bit) into the write latch. The TBLPAG register is loaded with the 8 Most Significant Bytes of the Flash address. The TBLWTL and TBLWTH instructions write the desired data into the write latches and specify the lower 16 bits of the program memory address to write to. To configure the NVMCON register for a word write, set the NVMOP bits (NVMCON<3:0>) to 0011. The write is performed by executing the unlock sequence and setting the WR bit (see Example 4-4). EXAMPLE 4-4: PROGRAMMING A SINGLE WORD OF FLASH PROGRAM MEMORY ; Setup a pointer to data Program Memory MOV #tblpage(PROG_ADDR), W0 ; MOV W0, TBLPAG ;Initialize PM Page Boundary SFR MOV #tbloffset(PROG_ADDR), W0 ;Initialize a register with program memory address MOV #LOW_WORD_N, W2 ; MOV #HIGH_BYTE_N, W3 ; TBLWTL W2, [W0] ; Write PM low word into program latch TBLWTH W3, [W0++] ; Write PM high byte into program latch ; Setup NVMCON for programming one word to data Program Memory MOV #0x4003, W0 ; MOV W0, NVMCON ; Set NVMOP bits to 0011 DISI #5 ; Disable interrupts while the KEY sequence is written MOV #0x55, W0 ; Write the key sequence MOV W0, NVMKEY MOV #0xAA, W0 MOV W0, NVMKEY BSET NVMCON, #WR ; Start the write cycle NOP ; 2 NOPs required after setting WR
發表於: 2008/4/10 8:54
|
|||
|
Re: 關於PIC24FJ16GA002 PROGRAM MEMORY 寫入問題
|
||||
---|---|---|---|---|
版主
|
CE027 :
http://www.microchip.com/stellent/idc ... NextRow=&ssUserText=ce027 CE109 & CE209 for dsPIC33F & PIC24H Run-Time Self Programming PIC24F 的 Flash Memory 讀的時候是可以自一個位址讀出資料,但寫的時候是一個小區塊的寫入,這要 Check 該元件的區塊大小,以 Table Write 寫入事先寫到 PIC24F 的暫存區裡,待整個區塊都寫入後才會正式燒錄到 Flash 裡,這一點是很重要的。
發表於: 2008/4/9 15:02
|
|||
|
關於PIC24FJ16GA002 PROGRAM MEMORY 寫入問題
|
||||
---|---|---|---|---|
新會員
|
DWORD EE_Read (void )
{ DWORD_VAL temp; TBLPAG = 0; temp.word.LW = __builtin_tblrdl(0xA0); temp.word.HW = __builtin_tblrdh(0x00); return temp.Val; } 可讀取到0X0000A0 的資料 但是並不能寫入資料到 Myvar 中 const unsigned int myVar = 0x0002; void EE_Write(WORD page, WORD addrLo, WORD dataHi, WORD dataLo) { unsigned int TBLpage; unsigned int varAddr; TBLpage = __builtin_tblpage(&myVar); TBLPAG = TBLpage; varAddr = __builtin_tbloffset(&myVar); __builtin_tblwtl(varAddr, 0xAA); //load data to write: __builtin_tblwth(varAddr, 0xAA); //load data to write: //0xAAAA NVMCON = 0x4003; //NVM word write opcode __builtin_write_NVM(); //unlock & set WR bit asm("DISI #10"); while(NVMCONbits.WR == 1); } 請問該如何做寫入動作並指定記憶體位置呢? 謝謝
發表於: 2008/4/8 22:59
|
|||
|