void Erase_Page(unsigned short int addr) {unsigned char ss; unsigned short int flash_error; flash_error = 0x00; FEEADR = addr & 0xFE00; // set address FEEMOD |=0x08; //enable the erase and write commands. FEECON = 0x05; // page erase command ss = FEESTA&0x01; while (!ss && (flash_error++<=2000)) ss = FEESTA&0x01; // wait data read ready }
unsigned short int read_flash_word(unsigned short int addr) {unsigned char ss; unsigned short int flash_error; flash_error = 0x00; FEEMOD =0x00; //关闭页面,禁止修改 FEEADR = addr; // set address FEECON = 0x07;//FEECON = 0x01; // single read command ss = FEESTA&0x01; while (!ss && (flash_error++<=2000)) ss = FEESTA&0x01; // wait data read ready FEEMOD =0x00; //关闭页面,禁止修改 flash_error = FEEDAT; return(flash_error); // one byte data }
void write_flash_word(unsigned short int addr, unsigned short int *word, unsigned short int count) { unsigned short int erased_page, i; unsigned short int flash_error; unsigned char ss; erased_page = 0x01; //页面起始地址的低九位应该为0,设置为1表示开始就需要页面清空 for(i=0; i<count; i++) { if (erased_page!=(addr&0xFE00)) { Erase_Page(addr); erased_page = addr&0xFE00; } FEEADR = addr++; addr++; // set address //地址必须 “+ 2” FEEDAT = *word; word++; // set data value FEECON = 0x03; //FEECON = 0x02; // write command flash_error = 0x00; ss = FEESTA&0x01; while (!ss && (flash_error++<=2000)) ss = FEESTA&0x01; // wait data read ready } FEEMOD =0x00; //关闭页面,禁止修改 }
执行上面的写操作,程序就飞了,中断也乱了!求教! |