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


Browsing this Thread:   1 Anonymous Users






Re: PIC18F 內部EEPROM讀寫函式
#10
高級會員
高級會員


查看用戶資訊
nicecookie大大
我也不知道咧~~~我之前測試是這樣~~我也知道那三行C等於那五行ASM,還是我再用的時候有去給它定到一些奇怪的東西,當時的我也很納悶,但是因為時間緊迫我就沒去想那些問題咧,哈哈,我道行尚淺,有很多不明白的東西,多多指教啊,等我這個CASE結束在改回來試試看。
當初設不過去用DEBUGER模式看,就設不過去,然後我就在想為什麼板主要用那五行ASM一改過去就可以了,接著看DATA SHEET 它寫EECON2 (not a physical register)
到底什麼原因咧~~

發表於: 2005/6/21 12:00
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F 內部EEPROM讀寫函式
#9
資深會員
資深會員


查看用戶資訊
參照:

bbc0803 寫道:
我ㄧ開始設好像也不行

你的這邊這樣好像不能直接改變EECON2
EECON2 = 0x55;
EECON2 = 0xaa;

要這樣
_asm
MOVLW 0X55
MOVWF EECON2,0
MOVLW 0XAA
MOVWF EECON2,0
BSF EECON1,1,0
_endasm

ㄧ開始我也是那樣設~~但是涉不過去~~用DEBUGER模式看EECON2好像不會改變,用那5行組語後就寫的過去了
;


還是看不懂為什麼那3行C source code 需要改用asm 來寫

我用的是pic16f87x
我都是直接用C寫的, compilier 的結果如下
應該可以看得出來, c compliier後的結果和asm的寫法是一樣的
=================================
; EECON2=0x55; C 的source code
MOVLW .85
MOVWF EECON2

; EECON2=0xAA; C 的source code
MOVLW .170
MOVWF EECON2

; WR=1; C 的source code
BSF 0x18C,WR
=================================

程式確定可以正常寫入讀出..
還是pic16 和18的程序是否有所差別??

發表於: 2005/6/21 10:54
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F 內部EEPROM讀寫函式
#8
高級會員
高級會員


查看用戶資訊
我ㄧ開始設好像也不行

你的這邊這樣好像不能直接改變EECON2
EECON2 = 0x55;
EECON2 = 0xaa;

要這樣
_asm
MOVLW 0X55
MOVWF EECON2,0
MOVLW 0XAA
MOVWF EECON2,0
BSF EECON1,1,0
_endasm

ㄧ開始我也是那樣設~~但是涉不過去~~用DEBUGER模式看EECON2好像不會改變,用那5行組語後就寫的過去了
void wrEEPROM(void)
{
EECON1bits.EEPGD = 0;
EECON1bits.CFGS = 0;
EECON1bits.WREN = 1;
INTCONbits.GIE = 0;
_asm
MOVLW 0X55
MOVWF EECON2,0
MOVLW 0XAA
MOVWF EECON2,0
BSF EECON1,1,0
_endasm
INTCONbits.GIE = 1;
while (!PIR2bits.EEIF);
PIR2bits.EEIF = 0;
EECON1bits.WREN = 0;
}
我是先把要存的值放到EEDATA
位址放在EEADDR
然後就呼叫這個副程式就可以了你試試看吧
呼叫前的程式
PIR2bits.EEIF = 0;
EEADR = i;
EEDATA = j;
wrEEPROM();

發表於: 2005/6/21 10:18
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F 內部EEPROM讀寫函式
#7
高級會員
高級會員


查看用戶資訊
依照範例然後將
INTCONbits.GIE = 0;
INTCONbits.GIE = 1;
拿掉就可以了,試試看吧

發表於: 2005/6/18 23:34
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F 內部EEPROM讀寫函式
#6
高級會員
高級會員


查看用戶資訊
>>可參考左邊的檔案下載區中就有範例程式

// * Define byte data into the Internal EEPROM
#pragma romdata EEDATA
rom unsigned char EE_Data[] = {'H','i','-','T','e','c','h',0x00,};
#pragma romdata

請問一下根據範例程式,是不是這樣就可以設定初值...
但我的好像不行,在hex檔檔尾並沒有加入'值'

ORG 0xf00000
DE "Test Data",0,1,2,3,4,5

ASM 的就正常,

發表於: 2005/6/17 19:10
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


訪客
Re: PIC18F 內部EEPROM讀寫函式
#5
歹勢
那個範例程式我也試過了, 就是因為不行才改成目前這個樣子.
不知是否有其他該注意的細節沒注意到...

你指的是這個嗎?
void EE_Write (unsigned int EE_Address, unsigned char EE_Data)
{
PIR2bits.EEIF = 0;
EEADRH = (EE_Address>>8) & 0xFF;
EEADR = EE_Address & 0xFF;
EEDATA = EE_Data;
EECON1bits.EEPGD = 0;
EECON1bits.WREN = 1;
INTCONbits.GIE = 0;
_asm
MOVLW 0X55
MOVWF EECON2,0
MOVLW 0XAA
MOVWF EECON2,0
BSF EECON1,1,0
_endasm
INTCONbits.GIE = 1;
while (!PIR2bits.EEIF);
PIR2bits.EEIF = 0;
EECON1bits.WREN = 0;
}

unsigned char EE_Read (unsigned int EE_Address)
{
EEADRH = (EE_Address>>8) & 0xFF;
EEADR = EE_Address & 0xFF;
EECON1bits.EEPGD = 0;
EECON1bits.RD = 1;
return EEDATA;
}

Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F 內部EEPROM讀寫函式
#4
高級會員
高級會員


查看用戶資訊
可參考左邊的檔案下載區中就有範例程式

發表於: 2005/6/17 17:40
人生最長久的擁有是珍惜 但是大都在失去後才發現
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


訪客
Re: PIC18F 內部EEPROM讀寫函式
#3
EEDATA = WREG;
本來也是沒加,一樣不行.
加了還是不行.
傷腦筋...

Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: PIC18F 內部EEPROM讀寫函式
#2
資深會員
資深會員


查看用戶資訊
參照:


unsigned char ReadEEPChar(int Addr)
{
EEADRH = Addr / 256;
EEADR = Addr % 256;
//Disable Interrupt
INTCONbits.GIE = 0;
EECON1bits.EEPGD = 0;
//EECON1bits.CFGS = 0;
EECON1bits.RD = 1;
EEDATA = WREG;
//Enable Interrupt
INTCONbits.GIE = 1;
return(EEDATA);
}



抱歉~~說聲明 我沒寫過18的EEPROM讀寫喔,

個人是覺得讀取EEDATA 應該不需要加
EEDATA = WREG;
這一行吧

發表於: 2005/6/17 16:37
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


訪客
PIC18F 內部EEPROM讀寫函式
#1
請各位先進幫我看一下PIC 18F 內部EEPROM讀寫函式是否有誤, 因為寫入及讀出資料不正確, 謝謝!

unsigned char ReadEEPChar(int Addr)
{
EEADRH = Addr / 256;
EEADR = Addr % 256;
//Disable Interrupt
INTCONbits.GIE = 0;
EECON1bits.EEPGD = 0;
//EECON1bits.CFGS = 0;
EECON1bits.RD = 1;
EEDATA = WREG;
//Enable Interrupt
INTCONbits.GIE = 1;
return(EEDATA);
}

bool WriteEEPChar(int Addr, unsigned char wrData)
{
int writetimes = 0;
unsigned long counter;

// 寫入至多5次, 以防止寫入失敗
do
{
EEADRH = Addr / 256;
EEADR = Addr % 256;
EEDATA = wrData;
EECON1bits.EEPGD = 0;
EECON1bits.WREN = 1;
//Disable Interrupt
INTCONbits.GIE = 0;
EECON2 = 0x55;
EECON2 = 0xaa;
EECON1bits.WR = 1;
//Enable Interrupt
INTCONbits.GIE = 1;
counter = 0;
while(PIR2bits.EEIF == 0)
{
counter++;
if (counter > 0xfffe)
break;
}
EECON1bits.WREN = 0;
PIR2bits.EEIF = 0;
if (counter > 0xfffe)
writetimes++;
else
return true;
}while (writetimes < 5);
return false;
}

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... ]

教育訓練中心

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