我写了一个 void E2prom_Write_Byte(unsigned inteeaddress, unsigned char eedata) { unsignedint b=0; FCLKDIV=0x03;//FDIVfield is open for writing AND FDIV[5:0]=3; if(FSTAT_CCIF == 1) { FSTAT = 0x30;//cleare ACCERR AND FPVIOL FCCOBIX = 0x00; FCCOBHI = 0x11; FCCOBLO = 0x00;//Program EEPROM Command FCCOBIX ++; FCCOB = eeaddress; FCCOBIX ++; FCCOBHI = eedata; FCCOBLO = 0xff;//WRITE_BYTE FSTAT_CCIF = 1; while(!FSTAT_CCIF&&b<3000)//wait for write byte complete { b++; } } } 此函数内部没有调用其它函数,全是操作寄存器,作用是操作了E2PROM。 上面的函数我测试了没问题,函数作用也实现了。 然后在编译器中编译,查看.map文件: E2prom_Write_Byte 88013 4E 78 2 .text 得知是在地址088013地址为函数起始地址,其后的78个字节,是该函数的编译出来的机器码,我把这78字节的机器码提前在.S19文件中提取出来,得到存到了一个数组中 如下: unsigned char e2prom_driver_code[78] = { 0x1D,0x02,0xFA,0x80,0xCC,0x04,0x13,0x5B,0x34,0x5A,0x36,0x4F,0x37,0x08,0xFC,0x4C,0x39,0x80,0x0A,0x6B,0xAD,0xC7,0x87,0x6C,0x81,0xC6,0x03,0x7B,0x01,0x00,0x1F,0x01, 0x06,0x80,0x3B,0xC6,0x30,0x7B,0x01,0x06,0x7A,0x01,0x02,0xC6,0x11,0x7B,0x01,0x0A,0x7A,0x01,0x0B,0x72,0x01,0x02,0xEE,0x86,0x7E,0x01,0x0A,0x72,0x01,0x02,0xE6,0x80, 0x7B,0x01,0x0A,0x43,0x7A,0x01,0x0B,0x1C,0x01,0x06,0x80,0x20,0x05,0xEE }; 然后按照函数原型定义了一个函数指针类:E2PROM_WRITE_FUN_POINTER typedef void(*E2PROM_WRITE_FUN_POINTER)(unsigned int,unsigned char);//定义该类型的函数指针类型 E2PROM_WRITE_FUN_POINTER fun;//然后定义了该类型的一个指针, 然后通过((E2PROM_WRITE_FUN_POINTER)e2prom_driver_code)(0x400,0x28);来调用机器码, 但是好像编译警告如下: 非标准转换 跑起来跑到这个函数调用处,也非法复位了,/(ㄒoㄒ)/~~。。。求指教啊!
|