题内话,公司要开始忙了,会很少有时间来网上了,在此之前抽空发个文章吧,关于HCS08内核的飞思卡尔单片机的内部Flash的擦写和读取测试!很简单,没啥技术含量~飞思卡尔提供了很多Flash命令~写入相关寄存器即可。
废话不说了,要不被CZZ鄙视了,直接贴代码吧~就一个main.c,所以工程文件就不发了。这里用的MC13211测试的,因为公司有这个片子的板子,嘿嘿~
#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */
#include "uart.h"
#define Page_Erase PGM[21]=0x40; temp = ((unsigned char(*)(unsigned int))(PGM))
#define Program_Byte PGM[21]=0x20; temp =((unsigned char(*)(unsigned int, unsigned char))(PGM))
//Array of opcode instructions of the Erase/Program function in the HCS08 family
volatile unsigned char PGM[59] = {
0x87,0xC6,0x18,0x25,0xA5,0x10,0x27,0x08,0xC6,0x18,0x25,0xAA,0x10,0xC7,0x18,0x25,
0x9E,0xE6,0x01,0xF7,0xA6,0x20,0xC7,0x18,0x26,0x45,0x18,0x25,0xF6,0xAA,0x80,0xF7,
0x9D,0x9D,0x9D,0x9D,0x45,0x18,0x25,0xF6,0xF7,0xF6,0xA5,0x30,0x27,0x04,0xA6,0xFF,
0x20,0x07,0xC6,0x18,0x25,0xA5,0x40,0x27,0xF9,0x8A,0x81};
/* Main
//Flash擦写校验主函数
//BY:Richard.Mo
//2011-10-21
*/
void main(void)
{
/* include your code here */
unsigned char temp = 0;
unsigned int i = 0;
DisableInterrupts; //Disable all interrupt
SOPT = 0X73; //Close Watch Dog
FCDIV = 19; //直接使用内部8MHz CLK, 4MHz Bus, 200KHz
PTADD_PTADD1 = 1; //LED RED
PTADD_PTADD2 = 1; //LED GREEN
PTAD_PTAD1 = 1; //Turn off led red
PTAD_PTAD2 = 1; //Turn off led green
for(;;)
{
temp = Page_Erase(0xf000); //execute Erase one page routine, page start Addr @0xf000
if(temp == 0xFF)
{ //an error occurred erase routine
PTAD_PTAD1 = 0;
while(1);
}
for(i = 0; i < 512; i++) //Programe one page(512bytes)
{
temp = Program_Byte(0xf000+i,(unsigned char)i ); //execute Program routine
if(temp == 0xFF)
{ //an error occurred programe routine
PTAD_PTAD1 = 0;
while(1);
}
}
for(i = 0; i < 512; i++) //Check one page flash
{
temp = *(volatile unsigned char*)(0xf000+i);
if(temp != (unsigned char)i )
{
PTAD_PTAD2 = 0; //校验出错,停机
while(1);
}
}
PTAD_PTAD2 ^= 1; //成功,进行下一次读写测试
} /* loop forever */
/* please make sure that you never leave main */
}