飞思卡尔HCS12系列 Flash的加密解密
我要做一个功能,对Flash进行加锁,解锁。我用的单片机是MC9S12G128.
加锁部分的代码已经实现了,如下:
const unsigned char flash_array[] @0xFF00 = //设置密钥(四个字:0XAAAA,0XAAAA,0XAAAA,0XAAAA)
{
0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA
};
const char Set_key @0xFF0F = 0X80; //加锁
// FSTAT_CCIF = 1; //launch command
// while(FSTAT_CCIF == 0); //wait for done
// }
static unsigned char Send_Command[]=
{
0x1C, 0x01, 0x06, 0x80, 0x1F, 0x01, 0x06, 0x80, 0xFB, 0x3D
};
while(FSTAT_CCIF == 0); // wait if command in progress
FSTAT = 0x30; // clear ACCERR and PVIOL
FCCOBIX = 0x00; // Verify Backdoor Access Key
FCCOB = 0x0C00;
FCCOBIX = 0x01; // Backdoor key was defined in the variable
FCCOB = 0xAAAA; // "flash_array" above as
FCCOBIX = 0x02; // 0xAAAA,0xAAAA,0xAAAA,0xAAAA
FCCOB = 0xAAAA;
FCCOBIX = 0x03;
FCCOB = 0xAAAA;
FCCOBIX = 0x04;
FCCOB = 0xAAAA;
asm JSR Send_Command;