• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users




(1) 2 3 »


Re: 請問有關c18斷電存取內建ROM的方法
#26
中級會員
中級會員


查看用戶資訊
請問還有什麼方法除了movf,movff,movlw

可以把資料丟到TABLAT

謝謝

發表於: 2009/9/18 17:05
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問有關c18斷電存取內建ROM的方法
#25
中級會員
中級會員


查看用戶資訊
參照:

Ryang 寫道:
1.我的變數的內容該怎麼去存到WREG裡(其他的指令都有依照正確的方向走
ANS: movf DK,0,0 這樣會將變數 DK 存到 Wreg 裡,如果無法正確的用 Watch Window 看到那依定不知哪裡有設錯了,或對 MPLAB IDE 的操作不甚清楚。


WREG有變化 卻不規則
void WRITE_ROM(unsigned char DK)
{
_asm

CLRF TBLPTRL, 0
CLRF TBLPTRH, 0
MOVLW 0x1
MOVWF TBLPTRU, 0

BSF EECON1, 0x2,0 //WREN EN
BSF EECON1, 0x4, 0 //FREE EN
BSF EECON1, 0x5, 0 //WPROG EN
BCF INTCON, 0x7, 0 //GIP UN
MOVLW 0x55
MOVWF EECON2 , 0
MOVLW 0xAA
MOVWF EECON2 , 0

BSF EECON1, 0x1, 0 //WR EN
BSF INTCON, 0x7, 0 //GIP EN
BCF EECON1, 0x2, 0 //WREN UN

CLRF TABLAT, 0
TBLWTPOSTINC
MOVF DK ,0 ,0
MOVWF TABLAT ,0
TBLWTPOSTDEC
BSF EECON1, 0x2, 0 //WREN EN
BSF EECON1, 0x5, 0 //WPROG EN
BCF INTCON, 0x7, 0 //GIP UN
MOVLW 0x55
MOVWF EECON2,0 // write 55h
MOVLW 0xAA
MOVWF EECON2,0 // write AAh
BSF EECON1, 0x1, 0 //WR EN
BCF EECON1, 0x2, 0 //WREN EN
BCF EECON1, 0x3, 0 //WRERR UN
BCF EECON1, 0x5, 0 //WPROG UN

BSF INTCON, 0x7, 0 //GIP EN
_endasm

return ;
}
unsigned char READ_ROM(void)
{ unsigned char WORD_EVEN,WORD_K,WORD_C;
_asm
CLRF TBLPTRL, 0
CLRF TBLPTRH, 0
MOVLW 0x1
MOVWF TBLPTRU, 0

TBLRD
movf TABLAT, 0, 0
movwf WORD_EVEN,0
TBLRDPOSTINC
movf TABLAT, 0, 0
movwf WORD_K,0

TBLRDPOSTDEC
movf TABLAT, 0, 0
movwf WORD_C,0
_endasm
return (WORD_EVEN);
}

void main()
{ char dd = 'S';
WRITE_ROM(dd);
while(1);
Nop();
}

Attach file:



jpg  (0.00 KB)


發表於: 2009/9/17 13:03

Edited by wdszd on 2009年09月17日 13:28:45
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問有關c18斷電存取內建ROM的方法
#24
版主
版主


查看用戶資訊
1.我的變數的內容該怎麼去存到WREG裡(其他的指令都有依照正確的方向走
ANS: movf DK,0,0 這樣會將變數 DK 存到 Wreg 裡,如果無法正確的用 Watch Window 看到那依定不知哪裡有設錯了,或對 MPLAB IDE 的操作不甚清楚。

2.該怎麼讓C語的變數(UNSIGNED CHAR) 跟崁入式組語互通
ANS: In-Line Assembly 無法宣告變數,所以變數的宣告是由C來做的。它可以看到函數名稱及使用C的變數的。

3.我該另外宣告一個組語變數嗎? 如果需要又要該怎麼做? 告訴我去哪看就好 謝謝
ANS: 別自找麻煩用組與宣告變數,在C底下所宣告的 unsigned char Global Variable, In-Line Assembly 都可以使用的。

發表於: 2009/9/17 9:57
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問有關c18斷電存取內建ROM的方法
#23
中級會員
中級會員


查看用戶資訊
我也是參考上述的指令在撰寫的

MOVF DK ,0 ,0

我從WATCH視窗裡看個每指令,上面這條指令DK的資料卻沒有放
到WREG裡請問

1.我的變數的內容該怎麼去存到WREG裡(其他的指令都有依照正
確的方向走

2.該怎麼讓C語的變數(UNSIGNED CHAR) 跟崁入式組語互通

3.我該另外宣告一個組語變數嗎? 如果需要又要該怎麼做? 告訴我
去哪看就好 謝謝

發表於: 2009/9/17 9:42
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問有關c18斷電存取內建ROM的方法
#22
版主
版主


查看用戶資訊
現在才知道你用 PIC18F46J50。
W400 用的是 PIC18F452,雖然都是 PIC18 系列但Flash 的製程卻差很多。EECON1 暫存器的內容也不一樣的。

看一下 Data Sheet :EXAMPLE 6-4: SINGLE-WORD WRITE TO FLASH PROGRAM MEMORY
MOVWF TBLPTRH
MOVLW CODE_ADDR_LOW     
The table pointer must be loaded with an even address
MOVWF TBLPTRL
[color=ff0000]
MOVLW DATA0         LSB of word to be written
MOVWF TABLAT
TBLWT
*+
MOVLW DATA1         MSB of word to be written
MOVWF TABLAT
TBLWT
*             ; The last table write must not increment the table
                      
;pointerThe table pointer needs to point to the
                      
;MSB before starting the write operation.
                      ;
PROGRAM_MEMORY[/color]
BSF EECON1WPROG     enable single word write
BSF EECON1
WREN     enable write to memory
BCF INTCON
GIE     disable interrupts
MOVLW 55h
Required MOVWF EECON2     
write 55h
Sequence MOVLW 0AAh
MOVWF EECON2         
write AAh
BSF EECON1
WR         start program (CPU stall)
BSF INTCONGIE     re-enable interrupts
BCF EECON1
WPROG     disable single word write
BCF EECON1
WREN     disable write to memory


紅色部分就是 Write 1 word to the Holding Register 的動作。

發表於: 2009/9/16 17:49
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問有關c18斷電存取內建ROM的方法
#21
中級會員
中級會員


查看用戶資訊
unsigned char dk <====宣告dk

MOVF dk,0,0 <====將dk 存入WREG

MOVWF TABLAT, 0<====我用奸視器看的時候,我的WREG沒

有我DK的值。

我該如何將DK的丟入TABLAT

發表於: 2009/9/16 17:19
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問有關c18斷電存取內建ROM的方法
#20
中級會員
中級會員


查看用戶資訊
我從PIC18F46J50 系列裡看到wprog這個在eecon1的暫存器

我理解沒錯的話在6.2的說明,它是為1的時候可以只寫入單字

(2byte),為0是寫入整個BANK(64BYTE)

我上傳eecon1的說明 而且在MPLAB裡從WATCH EECON1得確也

沒有W400裡所寫的EEPGD、CFGS、RD 這三個暫存器

Attach file:



jpg  (0.00 KB)


發表於: 2009/9/16 14:35

Edited by wdszd on 2009年09月16日 15:07:48
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問有關c18斷電存取內建ROM的方法
#19
版主
版主


查看用戶資訊
摘錄一下 PIC18F4520 Data Sheet 裡對 Flash Memory 的說明:
The minimum programming block is 32 words or
64 bytesWord or byte programming is not supported.

6.5.1 FLASH PROGRAM MEMORY WRITE
SEQUENCE
The sequence of events 
for programming an internal
program memory location should be
:
1. Read 64 bytes into RAM.
2. Update data values in RAM as necessary.
3. Load Table Pointer register with address being
erased
.
4. Execute the row erase procedure.
5. Load Table Pointer register with address of first
byte being written
.
6. Write the 64 bytes into the holding registers with
auto
-increment.
7. Set the EECON1 register for the write operation:
&
#8226; set EEPGD bit to point to program memory;
&#8226; clear the CFGS bit to access program memory;
&#8226; set WREN to enable byte writes.
8. Disable interrupts.
9. Write 55h to EECON2.
10. Write 0AAh to EECON2.
11. Set the WR bitThis will begin the write cycle.
12. The CPU will stall for duration of the write (about
2 ms using internal timer
).
13. Re-enable interrupts.
14. Verify the memory (table read).
This procedure will require about 6 ms to update one
row of 64 bytes of memory
An example of the required
code is given in Example 6
-3.

發表於: 2009/9/16 11:00
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問有關c18斷電存取內建ROM的方法
#18
版主
版主


查看用戶資訊
1.我固定在0x10000這個位址做存取的動作,怎麼查看我有沒有存進去flashrom裡 有地方可以看嗎?(單單檢查寫入有沒有錯誤)
從你問的問題終就可以瞭解你對 PIC18 系列的 Flash Memory 沒有讀完。PIC18F 的 Flash 無法一次只寫入一個 Byte 的。以 PIC18F452 來說: 清一個 Block 為 64-byte,一次寫入的動作需連續8-byte 才行。

2.我程式寫了1個字元 讀出來卻沒有東西,我發現我使用wprog=1 一次是寫入2個字元 跟讀出有關系嗎?
Flash 寫入時是暫時先寫到Holding Register 的,何種時機會再寫到Flash去呢? 你的操作對象是 Flash 不是一般一個byte就可以直接操作的 EEPROM.

3.這種c & asm穿插的程式有夠難看得
沒辦法,有些低階的東西,C 語言做不到的。

發表於: 2009/9/16 10:55
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請問有關c18斷電存取內建ROM的方法
#17
中級會員
中級會員


查看用戶資訊
void WRITE_ROM(unsigned char dk)
{ TBLPTR=0x010000;
EECON1bits.WPROG = 1;
EECON1bits.WREN = 1;
EECON1bits.FREE = 1;
INTCONbits.GIE = 0;
_asm
MOVLW 0x55
MOVWF EECON2 , 0
MOVLW 0xAA
MOVWF EECON2 , 0
_endasm
EECON1bits.WR = 1;
TABLAT = dk;
_asm
TBLWTPOSTINC
CLRF TABLAT, 0
TBLWT
MOVLW 0x55
MOVWF EECON2,0 // write 55h
MOVLW 0xAA
MOVWF EECON2,0 // write AAh
_endasm
EECON1bits.WR = 1; // start program (CPU stall)
INTCONbits.GIE = 1; // re-enable interrupts
EECON1bits.WPROG = 0; // disable single word write
EECON1bits.WREN = 0;
return ;
}
unsigned char READ_ROM(void)
{ unsigned char WORD_EVEN;
TBLPTR=0x010000;
_asm
TBLRD
movf TABLAT, 0, 0
movwf WORD_EVEN,0
_endasm
return (WORD_EVEN);
}
我出現了幾個問題

1.我固定在0x10000這個位址做存取的動作,怎麼查看我有沒有存進去flashrom裡 有地方可以看嗎?(單單檢查寫入有沒有錯誤)

2.我程式寫了1個字元 讀出來卻沒有東西,我發現我使用wprog=1 一次是寫入2個字元 跟讀出有關系嗎?

3.這種c & asm穿插的程式有夠難看得

BSF EECON1, WR <===顯示undefined label 'WR' in 'READ_ROM'

也不能#define WR 0x02

bsf EECON1 ,0x02 ,0<==卻可以 能給我一點提示嗎?

謝謝

發表於: 2009/9/15 17:26
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------