📄 test.c
字号:
IOCLR|=BEEPCON;
CommInit();
Time0Init();
//RTC_init(400000);
//判断是否进入BOOTLOAD部分
boottime_overflow=FALSE;
while(1)
{
if( (T0IR&0x01) != 0 ) // 等待定时时间到
{
T0IR = 0x01;
closetc0;
boottime_overflow=TRUE;
break;
}
if((GetComm()==TRUE)&&(recivebuf[1]==relink_comm))//接收到连接命令
{
closetc0;
T0IR = 0x01;
replayack(TRUE);
break;
}
}
if(boottime_overflow==TRUE)//进入引导应用程序部分
{
CopyCode();
runapp();//进入外部RAM的应用程序的开头
}
else//进入bootload部分
{
LCDInit();
LCDShowChar(0,3,tong_hc);
LCDShowChar(0,2,SHUZI_zimo+0x0b*16);
LCDShowChar(0,3,O_zimo);
LCDShowChar(0,4,O_zimo);
LCDShowChar(0,5,T_zimo);
LCDShowHc(0,6,tong_hc);
LCDShowHc(0,8,xun_hc);
LCDShowHc(0,10,cheng_hc);
LCDShowHc(0,12,gong_hc);
//----------------------------------------
//----------------------------------------
while(1)//对串口命令进行解析
{ tmpchar=GetComm();
if(tmpchar==TRUE)//有接收到命令
{
switch(recivebuf[1])
{
case bootver_comm://上传版本号
sendbytebuf[0]=heard_comm;
sendbytebuf[1]=bootver_comm;
sendbytebuf[2]=0x00;
sendbytebuf[3]=0x02;
tmpint=codever;
tmpchar2=(tmpint>>8)&0xff;
sendbytebuf[4]=tmpchar2;
tmpchar2=tmpint&0xff;
sendbytebuf[5]=tmpchar2;
replycomm(sendbytebuf,7);
LCDShowChar(1,0,SHUZI_zimo+0x0b*16);
LCDShowChar(1,1,O_zimo);
LCDShowChar(1,2,O_zimo);
LCDShowChar(1,3,T_zimo);
LCDShowChar(1,4,null_zimo);
LCDShowChar(1,5,V_zimo);
LCDShowChar(1,6,SHUZI_zimo+((codever>>12)&0x0f)*16);
LCDShowChar(1,7,SHUZI_zimo+((codever>>8)&0x0f)*16);
LCDShowChar(1,8,dian_zimo);
LCDShowChar(1,9,SHUZI_zimo+((codever>>4)&0x0f)*16);
LCDShowChar(1,10,SHUZI_zimo+(codever&0x0f)*16);
LCDShowHc(1,11,ban_hc);
LCDShowHc(1,13,ben_hc);
break;
case flashid_comm://上传FLASH的ID号
tmplong=readflashid();//读失败则返回0
if(tmplong==0)
{
replayack(FALSE);
}
else
{
sendbytebuf[0]=heard_comm;
sendbytebuf[1]=flashid_comm;
sendbytebuf[2]=0x00;
sendbytebuf[3]=0x04;
sendbytebuf[4]=(tmplong>>24)&0xff;
sendbytebuf[5]=(tmplong>>16)&0xff;
sendbytebuf[6]=(tmplong>>8)&0xff;
sendbytebuf[7]=tmplong&0xff;
replycomm(sendbytebuf,9);
LCDShowChar(2,0,SHUZI_zimo+0x0f*16);
LCDShowChar(2,1,l_zimo);
LCDShowChar(2,2,a_zimo);
LCDShowChar(2,3,s_zimo);
LCDShowChar(2,4,h_zimo);
LCDShowChar(2,5,I_zimo);
LCDShowChar(2,6,SHUZI_zimo+0x0d*16);
LCDShowChar(2,7,mao_zimo);
LCDShowChar(2,8,SHUZI_zimo+((tmplong>>28)&0x0f)*16);
LCDShowChar(2,9,SHUZI_zimo+((tmplong>>24)&0x0f)*16);
LCDShowChar(2,10,SHUZI_zimo+((tmplong>>20)&0x0f)*16);
LCDShowChar(2,11,SHUZI_zimo+((tmplong>>16)&0x0f)*16);
LCDShowChar(2,12,SHUZI_zimo+((tmplong>>12)&0x0f)*16);
LCDShowChar(2,13,SHUZI_zimo+((tmplong>>8)&0x0f)*16);
LCDShowChar(2,14,SHUZI_zimo+((tmplong>>4)&0x0f)*16);
LCDShowChar(2,15,SHUZI_zimo+((tmplong)&0x0f)*16);
}
break;
case write_comm:
//烧写BOOT程序,预留28KB
//烧写LOGO,预留4KB
//烧写8*16英文字库,预留4KB
//烧写16*16字库,预留216KB
//烧写应用程序,预留256KB
flash_down();
if(savemenu==0)
{
//烧录FLASH。。。
clearlcd_lin(3);
LCDShowHc(3,0,xia_hc);
LCDShowHc(3,2,zai_hc);
LCDShowChar(3,4,SHUZI_zimo+0x0f*16);
LCDShowChar(3,5,l_zimo);
LCDShowChar(3,6,a_zimo);
LCDShowChar(3,7,s_zimo);
LCDShowChar(3,8,h_zimo);
LCDShowChar(3,9,dian_zimo);
LCDShowChar(3,10,dian_zimo);
LCDShowChar(3,11,dian_zimo);
savemenu=1;
}
break;
case runapp_comm:
tmplong=recivebuf[4];
tmplong=((tmplong<<8)&0xff00)+recivebuf[5];
replayack(TRUE);
if(tmplong==0x0000)
{
runboot();
}
else
{
CopyCode();
runapp();//进入外部RAM的应用程序的开头
}
savemenu=0;
break;
case clear_comm://清除数据区
tmpint=recivebuf[6];
tmpint=((tmpint<<8)&0xff00)+recivebuf[7];
i=recivebuf[4];
i=((i<<8)&0xff00)+recivebuf[5];
for(tmplong=i;tmplong<=tmpint;tmplong++)
{
if(SectorErase(tmplong)!=TRUE)//搽除失败
{
replayack(FALSE);
break;
}
DelayNS(20);
}
clearlcd_lin(3);
LCDShowHc(3,0,cha_hc);
LCDShowHc(3,2,chu_hc);
LCDShowChar(3,4,SHUZI_zimo+0x0f*16);
LCDShowChar(3,5,l_zimo);
LCDShowChar(3,6,a_zimo);
LCDShowChar(3,7,s_zimo);
LCDShowChar(3,8,h_zimo);
if(tmplong>tmpint)
{
replayack(TRUE);
LCDShowHc(3,9,cheng_hc);
LCDShowHc(3,11,gong_hc);
}
else
{
replayack(FALSE);
LCDShowHc(3,9,shi_hc);
LCDShowHc(3,11,bai_hc);
}
savemenu=0;
break;
case read_comm:
tmplong=recivebuf[4];
tmplong=((tmplong<<8)&0xff00)+recivebuf[5];
tmplong=tmplong*1024;
for(i=0;i<512;i++)
{
tmpint=readflash(tmplong+i*2);
SendChar(tmpint>>8);
SendChar(tmpint);
}
clearlcd_lin(3);
LCDShowHc(3,0,du_hc);
LCDShowHc(3,2,qu_hc);
LCDShowChar(3,4,SHUZI_zimo+0x0f*16);
LCDShowChar(3,5,l_zimo);
LCDShowChar(3,6,a_zimo);
LCDShowChar(3,7,s_zimo);
LCDShowChar(3,8,h_zimo);
savemenu=0;
break;
case rtc_comm:
time_rec.fields.second=recivebuf[4];
time_rec.fields.minute=recivebuf[5];
time_rec.fields.hour=recivebuf[6];
date_rec.fields.day=recivebuf[7];
date_rec.fields.week=recivebuf[8];
date_rec.fields.month=recivebuf[9];
tmplong=recivebuf[10];
date_rec.fields.year=((tmplong<<8)&0xff00)+recivebuf[11];
if(RTC_set_time(time_rec.l_word)==-1)
{
replayack(FALSE);
break;
}
if(RTC_set_date(date_rec.l_word)==-1)
{
replayack(FALSE);
break;
}
replayack(TRUE);
break;
case rtc_up_comm:
time_rec.l_word=RTC_read_time();
date_rec.l_word=RTC_read_date();
sendbytebuf[0]=heard_comm;
sendbytebuf[1]=rtc_comm;
sendbytebuf[2]=0x00;
sendbytebuf[3]=0x08;
sendbytebuf[4]=time_rec.fields.second;
sendbytebuf[5]=time_rec.fields.minute;
sendbytebuf[6]=time_rec.fields.hour;
sendbytebuf[7]=date_rec.fields.day;
sendbytebuf[8]=date_rec.fields.week;
sendbytebuf[9]=date_rec.fields.month;
sendbytebuf[10]=date_rec.fields.year/0x100;
sendbytebuf[11]=date_rec.fields.year%0x100;
replycomm(sendbytebuf,13);
break;
default:
break;
}
}
}
}
return 0;
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -