有谁用过,我日的,怎么写不进去啊:
#include "p30f6014A.h"
// 编程EEPROM时需用到的一些控制字
#define EE_ERASE_WORD_CODE 0x4044
#define EE_WRITE_WORD_CODE 0x4004
#define EE_ERASE_ROW_CODE 0x4045
#define EE_WRITE_ROW_CODE 0x4005
int failmemory[40];
// 在EEPROM中安排16个字的数据
int _EEDATA(32) ArrayInEEData[16] = {0,1,2,3,4,5,6,7,8,9,0xA,0xB,0xC,0xD,0xE,0xF};
// 在RAM中安排16个字的数据
int ArrayInRAM0[16] = {7,7,7,7,7,7,9,8,7,6,5,4,3,2,1,0};
int ArrayInRAM1[16];
// 初始化系统
void InitializeSys()
{
SRbits.IPL = 7; // 关闭所有可屏蔽中断
}
// 通过表读指令从EEPROM中读一行数据至RAM
void ReadEEByTable(register int SourceAddr, register int OffsetAddr, int* DestArray)
{
unsigned char i;
//int DataTemp;
TBLPAG = SourceAddr;
for(i=0; i<16; i++)
{
__asm__("tblrdl [W1++],[W2++]");
}
}
// 通过使能PSV从EEPROM中读一行数据至RAM
void ReadEEByPSV(register int PageAddr, int* DestArray)
{
unsigned char i;
PSVPAG = PageAddr;
for(i=0; i<16; i++)
{
DestArray = ArrayInEEData;
}
}
//擦除EEPROM中指定的一行数据
void EraseEE(register int PageAddr, register int OffsetAddr)
{
NVMADRU = PageAddr;
NVMADR = OffsetAddr;
NVMCON = EE_ERASE_ROW_CODE; //配置NVMCON寄存器为擦除一行EEPROM
NVMKEY = 0x55; //写密钥序列
NVMKEY = 0xAA;
NVMCONbits.WR = 1; //开始擦除
while(NVMCONbits.WR == 1);
}
//向EEPROM中指定的行写入一行数据
void WriteEE(register int PageAddr, register int OffsetAddr, int* SourceArray)
{
unsigned char i;
TBLPAG = PageAddr;
for(i=0; i<16; i++)
{
__asm__("tblwtl [W2++], [W1++]");
}
NVMCON = EE_WRITE_ROW_CODE;
NVMKEY = 0x55; //写密钥序列
NVMKEY = 0xAA;
NVMCONbits.WR = 1; //开始编程
while(NVMCONbits.WR = 1);
}
int main()
{
InitializeSys();
TRISD = 0xFF00; //设定LED引脚为输出
ReadEEByTable(__builtin_tblpage(&ArrayInEEData[0]), __builtin_tbloffset(&ArrayInEEData[0]), &ArrayInRAM1[0]);
PORTD=&ArrayInRAM1[6];
//EraseEE(__builtin_tblpage(&ArrayInEEData[0]), __builtin_tbloffset(&ArrayInEEData[0]));
//WriteEE(__builtin_tblpage(&ArrayInEEData[0]), __builtin_tbloffset(&ArrayInEEData[0]), &ArrayInRAM0[0]);
while(1);
一周热门 更多>