C8051FXXX单片机FLASH程序的自动升级
MOVX @DPTR,A
INC DPTR
MOV A,DPH
CJNE A,#0E0H,RECEIVE_NEXT_DOWNLOAD_CHAR
MOV FLSCL,#01H //FLASH 写使能
MOV PSCTL,#01H
MOV DPTR,#0FDFEH
CLR A
MOVX @DPTR,A
MOV DPTR,#0FDFFH
MOVX @DPTR,A
MOV PSCTL,#00H
MOV FLSCL,#00H
CYCLE_FOREVER:SJMP CYCLE_FOREVER;死循环
RET
4)FLASH程序的准备
为了更快地得到—下载到C8051F020的FLASH程序,先在CYGNAL IDE开发环境中,将做好的控制程序编泽,链按,然后用厂家提供的串行适配器将PC与目标板连接起来,传送FLASH程序到目标系统中去。接下来用“UPLOAD MEMORY T0 PILE…”(如图示)功能将0000H~OEOOOH的FLASH代码程序上载到硬盘存储器中,再将此ASCII文件转化为16进制的HE文件,注意将其十的0DH,0AH等回车换行字节取消,最后生成的HEX文件即可被直接下载到FLASH的0000H~0DFFFH的相应地址中。此HEX文件即可发送至用户处,用于升级用户的单片机FLASH程序。
5)C程序的准备
//发送FLASH程序文件到单片机中去
BOOL SendFileToFlash()
{
unsigned char ch;
FILE *fp;
long int flen,wi=0;
int i,j;
if ((fp = fopen("flashwl","rb"))==NULL)
{
return FALSE;
}
//初使化串口,且与单片机系统握手
InitialCommuClass();
//发送数据
for (wi=0,j=0;wi<flen;wi++)
{
if (feof(fp)!=0)//到达文件结束
break;
fread(&ch,sizeof(unsigned char),1,fp);
for (;;)
if (SendAByte(ch)==TRUE)
break;
Printf("%ld bytes is transmitted!\n",wi); }
fclose(fp);
for (;;)
{
Printf("All bytes is transmitted!\n");
}
}
//转换上载文件为可下载的HEX目标文件
BOOL ConvertFileToFlash()
{
unsigned char ch,ru;
FILE *fp,*fpw;
long int flen,wi=0;
int i,j;
if ((fp = fopen("SOURCEC","rb"))==NULL)
{
return FALSE;
}
if ((fpw = fopen("HEXOBJECT","wb"))==NULL)
{
return FALSE;
}
for (wi=0,j=0;;wi++)
{
if (feof(fp)!=0)
break;
ru=0;
fread(&ch,sizeof(unsigned char),1,fp);
&n