:::


Browsing this Thread:   1 Anonymous Users






Re: PIC16F18345 EEPROM 存取問題
#2
管理員
管理員


查看用戶資訊
dginlon你好,在PIC16F18345使用DATAEE_ReadByte()或DATAEE_WriteByte()讀寫EEPROM,需要將記憶體位址設定為EEPROM的實際記憶體位址,可以參考Datasheet中的以下圖表:
縮圖



依您的範例,可以嘗試修改如下:
ReadEeprom.c
uiChannelA = DATAEE_ReadByte(0x7000+1) * 0x100 + DATAEE_ReadByte(0x7000+0);
WriteEeprom.c
DATAEE_WriteByte(0x7000+0,uiChannelA & 0xFF);
DATAEE_WriteByte(0x7000+1,uiChannelA / 0x100);

Attach file:



jpg  PIC16F18345.jpg (90.87 KB)
123092_6246c8d16323e.jpg 634X455 px

發表於: 4/1 17:40
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


PIC16F18345 EEPROM 存取問題
#1
資深會員
資深會員


查看用戶資訊
Dear All:

初始化 OK
讀出 皆為 0xFF
寫入 失敗


This file provides implementations of driver APIs for MEMORY.
Generation Information :
Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.7
Device : PIC16F18345 Rev.0
Driver Version : 2.0.2
The generated drivers are tested against the following:
Compiler : XC8 2.31 and above
MPLAB : MPLAB X 5.45

InitEeprom.c
eeprom struct PowerSwCountTag SwitchCount = {DEFAULT_SWITCH_COUNT_A,DEFAULT_SWITCH_COUNT_B};


Memory.c
/**
  Section: Data EEPROM Module APIs
*/

void DATAEE_WriteByte(uint16_t bAdduint8_t bData)
{
    
uint8_t GIEBitValue INTCONbits.GIE;

    
NVMADRH = ((bAdd >> 8) & 0xFF);
    
NVMADRL = (bAdd 0xFF);
    
NVMDATL bData;    
    
NVMCON1bits.NVMREGS 1;
    
NVMCON1bits.WREN 1;
    
INTCONbits.GIE 0;     // Disable interrupts
    
NVMCON2 0x55;
    
NVMCON2 0xAA;
    
NVMCON1bits.WR 1;
    
// Wait for write to complete
    
while (NVMCON1bits.WR)
    {
    }

    
NVMCON1bits.WREN 0;
    
INTCONbits.GIE GIEBitValue;   // restore interrupt enable
}

uint8_t DATAEE_ReadByte(uint16_t bAdd)
{
    
NVMADRH = ((bAdd >> 8) & 0xFF);
    
NVMADRL = (bAdd 0xFF);
    
NVMCON1bits.NVMREGS 1;    
    
NVMCON1bits.RD 1;
    
NOP();  // NOPs may be required for latency at high frequencies
    
NOP();
    return (
NVMDATL);
}

ReadEeprom.c
uiChannelA DATAEE_ReadByte(1) * 0x100 DATAEE_ReadByte(0);
uiChannelB DATAEE_ReadByte(3) * 0x100 DATAEE_ReadByte(2);

WriteEeprom.c
DATAEE_WriteByte(0,uiChannelA 0xFF);
DATAEE_WriteByte(1,uiChannelA 0x100);
DATAEE_WriteByte(2,uiChannelB 0xFF);
DATAEE_WriteByte(3,.uiChannelB 0x100);

發表於: 3/31 18:05
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.

[進階搜尋]


:::

搜尋

會員登入

知識列車系列 IV – 2022 MU選粹網路研討會

http://www.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
[ more... ]
:::

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://www.microchip.com.tw/modules/tadnews/page.php?ncsn=2&nsn=41
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... ]

教育訓練中心

課程 - 台北教育訓練中心
課程 - 新竹教育訓練中心
課程 - 高雄教育訓練中心
教育訓練中心介紹
購買 - 實驗工具
臺灣實驗板介紹與資源