我采用的是GCC软件,用自己写的子程序能读不能写,而用内部自带的读写函数就可以读写,下面为读写子程序,请高人指点。
/*EEPROM读取函数*//*addr:地址;number:长度;p_buff:读出数据存放指针*/ void eprom_read(unsigned int addr, unsigned char number, unsigned char *EEP_BUF) { while(EECR&(1<<EEWE)); EEARH =0x00; while(number --) { EEARL=addr++; EECR=(1<<EERE); *EEP_BUF++ = EEDR; } }
/*EEPROM写入函数*//*addr:地址;number:长度;p_buff:写入数据存放指针*/ void eprom_write(unsigned int addr, unsigned char number, unsigned char *EEP_BUF) { while(number--) { while(EECR&(1<<EEWE)); EEAR=addr++; EEDR=*EEP_BUF ++; EECR=0x04; //EECR|=(1<<EEMWE); EECR|=(1<<EEWE); 此方式也不可以写 EECR=0x06; } }
下面为部分程序: EEP_BUFF.burner1_segment1=9; EEP_BUFF.burner1_segment2=8; EEP_BUFF.burner1_segment3=7; eprom_write(0x0104,3,&EEP_BUFF); asm("nop"); asm("nop"); eprom_read(0x0104,3,&EEP_BUFF);
|