存储数据不进ram里面 是为什么这源代码
include "STK_EEPROM.H"
//#include "MS51_16K.H"
uchar xdata memory[64];
bit BIT_TMP=0;
extern uchar Address_l,Address_h;
uchar Memory_save[20];
void Enable_IAP_Mode(void)
{
BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;CHPCON |= 0x01 ;EA=BIT_TMP;
}
//-----------------------------------------------------------------------------------------------------------
void Disable_IAP_Mode(void)
{
BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;CHPCON &= ~0x01;EA=BIT_TMP;
}
//-----------------------------------------------------------------------------------------------------------
bit Trigger_IAP(void)
{
BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;IAPTRG |= 0x01 ;EA=BIT_TMP; //trigger IAP
if((CHPCON&0x40)==0x40) //check IAPFF (CHPCON.6)
{
return 0;
}
return 1;
}
//uchar xdata IAP_AUX[64] _at_ 0x100; //外部擴展RAM 位址(限定IAP 能使用)
//-------------------------------------------------------------
void Initeeprom()
{
EEdaly();
EEdaly();
EEdaly();
EEdaly();
EERead();
if(memory[0]!=0xAA)//没有进行初始化
{
memory[0]=0xAA;//存储标志位
// //预留6个字节地址位
memory[1]=(uchar)on_off;//开关标志
memory[2]=Frozen_Flag; //暂停模式标志
memory[3]=Touch_Cut;//色环值
memory[4]= Dim_Lv; //亮度
memory[5]= Mode_Step; //模式
memory[6]= Speed_3_Jump_Lv;; //3色渐变速度
memory[7]= Speed_7_Jump_Lv; //7色渐变速度
memory[8]= Speed_3_Faded_Lv; //3色跳变速度
memory[9]= Speed_7_Faded_Lv; //7色跳变速度
memory[10]= Address_l; //低地址码
memory[11]= Address_h; //高地址码
memory[12] = Color_Num;
EEWrite();
}
else
{
on_off=(bit)memory[1]; //亮度
Frozen_Flag=memory[2];//开关标志
Touch_Cut=memory[3];//自动模式标志
Dim_Lv= memory[4];
Mode_Step= memory[5];
Speed_3_Jump_Lv= memory[6];
Speed_7_Jump_Lv= memory[7];
Speed_3_Faded_Lv= memory[8];
Speed_7_Faded_Lv= memory[9];
Address_l = memory[10]; //低地址码
Address_h = memory[11]; //高地址码
Color_Num = memory[12];
}
}
//将数据写入存储
void Write_Memory()
{
memory[1]=(uchar)on_off;//开关标志
memory[2]=Frozen_Flag; //暂停模式标志
memory[3]=Touch_Cut;//色环值
memory[4]= Dim_Lv; //亮度
memory[5]= Mode_Step; //模式
memory[6]= Speed_3_Jump_Lv;; //3色渐变速度
memory[7]= Speed_7_Jump_Lv; //7色渐变速度
memory[8]= Speed_3_Faded_Lv; //3色跳变速度
memory[9]= Speed_7_Faded_Lv; //7色跳变速度
memory[10]= Address_l; //低地址码
memory[11]= Address_h; //高地址码
memory[12] = Color_Num;
EEWrite();
}
void Erase_APROM_Page(unsigned int Page_Num)
{
Enable_IAP_Mode();
IAPFD = 0xFF;
IAPCN = 0x22;
BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;IAPUEN |= 0x01 ;EA=BIT_TMP;
IAPAL = (Page_Num*128) & 0xFF;
IAPAH = ((Page_Num*128)>>8)&0xFF;
Trigger_IAP();
BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;IAPUEN &= ~0x01;EA=BIT_TMP;
Disable_IAP_Mode();
}
/*************eeprom***********/
void EEWrite(void)
{
unsigned char u8Count;
Erase_APROM_Page(128);
Enable_IAP_Mode();
IAPAL = (128*128) & 0xFF;
IAPAH = ((128*128)>>8)&0xFF;
IAPCN = 0x21;
//set_APUEN;
BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;IAPUEN |= 0x01 ;EA=BIT_TMP;
for(u8Count=0;u8Count<64;u8Count++)
{
IAPFD = memory[u8Count];
Trigger_IAP();
IAPAL++;
}
BIT_TMP=EA;EA=0;TA=0xAA;TA=0x55;IAPUEN &= ~0x01;EA=BIT_TMP;
Disable_IAP_Mode();
}
/***************************************************************************/
//void EERead(unsigned int Page_Num, unsigned int num)
void EERead()
{
unsigned int num;
Enable_IAP_Mode();
IAPAL = (128*128) & 0xFF;
IAPAH = ((128*128)>>8)&0xFF;
for (num=0; num<64; num++)
{
IAPCN = 0x00;
Trigger_IAP();
memory[num] = IAPFD;
IAPAL++;
}
Disable_IAP_Mode();
}
void EEdaly()
{
uint i;
for(i=100;i>0;i--)
_nop_();
}
volatile unsigned char code OTHER_DATA_Flash[11] _at_ OTHER_DATA_ADDR;
// unsigned char code COLOR_DATA_Flash[COLOUR_DN] _at_ COLOR_DATA_ADDR;
//volatile unsigned char code SCENE_DATA_Flash[SCENE_DN] _at_ SCENE_DATA_ADDR;
//void delay_xus(unsigned int x)
//{
// unsigned int i,j;
// for(i=0;i<x;i++)
// for(j=0;j<1000;j++);
//}
void Write_Data_To_Flash_Continued(unsigned int u16_addr, unsigned char *pDat,unsigned char num)
{
unsigned char looptmp;
unsigned int u16_addr_page,u16_addr_upd;
//Erase APROM DATAFLASH page
u16_addr_page=(u16_addr/128)*128;
set_CHPCON_IAPEN; //enable IAP mode
set_IAPUEN_APUEN; //enable APROM update
// set_IAPTRG_IAPGO;
if(u16_addr_page==SCENE_DATA_ADDR) //使用两个扇区保存场景数据
{
IAPAL = u16_addr_page&0xff; //写入L地址
IAPAH = (u16_addr_page>>8)&0xff; //写入H地址
IAPFD = 0xFF; //写入数据
IAPCN = 0x22; //写入命令:APROM页擦除
set_IAPTRG_IAPGO;
IAPAL = (u16_addr_page+128)&0xff; //写入L地址
IAPAH = ((u16_addr_page+128)>>8)&0xff; //写入H地址
IAPFD = 0xFF; //写入数据
IAPCN = 0x22; //写入命令:APROM页擦除
}
else
{
IAPAL = u16_addr_page&0xff; //写入L地址
IAPAH = (u16_addr_page>>8)&0xff; //写入H地址
IAPFD = 0xFF; //写入数据
IAPCN = 0x22; //写入命令:APROM页擦除
}
set_IAPTRG_IAPGO;
//Write_Data_To_Flash APROM
u16_addr_upd = u16_addr;
set_CHPCON_IAPEN;
set_IAPUEN_APUEN;
IAPCN = 0x21; //写入命令:APROM字节编程
for(looptmp=0;looptmp<num;looptmp++)
{
IAPAL = (u16_addr_upd&0xff); //写入L地址
IAPAH = (u16_addr_upd>>8)&0xff; //写入H地址
IAPFD = pDat[looptmp];
set_IAPTRG_IAPGO;
u16_addr_upd++;
}
clr_IAPUEN_APUEN;
clr_CHPCON_IAPEN;
}
|