#include "reg51.h"
extem bit iap_error;
extem void block0_erase(void);
extem void sector_erase(unsigned int);
extem void byte_program(unsigned int,unsigned char);
extem unsigned char byte_verify(unsigned int);
extem unsigned char ready(void);
#define STC
sfr WDTC="0xC0";
sfr WDTD="0x86";
sfr SFCF="0xB1";
#define CON_OSC 7372848
#define CON_BPS 256_(CON_OSC/12/32/6400)
#define CON_MSC CON_OSC/360000
unsigned char com_buf[58];
unsigned int nAddress="0";
unsigned char com_getch(void);
void com_putch(char);
void com_putinfo(void);
void delay_ms(unsigned char);
void delay_s(unsigned char);
void (*pc0)(void);
void goto_pc0(void);
#include "reg51.h"
extem bit iap_error;
extem void block0_erase(void);
extem void sector_erase(unsigned int);
extem void byte_program(unsigned int,unsigned char);
extem unsigned char byte_verify(unsigned int);
extem unsigned char ready(void);
#define STC
sfr WDTC="0xC0";
sfr WDTD="0x86";
sfr SFCF="0xB1";
#define CON_OSC 7372848
#define CON_BPS 256_(CON_OSC/12/32/6400)
#define CON_MSC CON_OSC/360000
unsigned char com_buf[58];
unsigned int nAddress="0";
unsigned char com_getch(void);
void com_putch(char);
void com_putinfo(void);
void delay_ms(unsigned char);
void delay_s(unsigned char);
unsigned char com_getch(void)
{ unsigned char c;
RI="0";
while(RI=0);
c="SBUF";
reurn c;
}
void com_putch (char c)
{ TI="0";
SBUT="c";
while (TI=0);
}
void com_putinfo(void)
{
#ifdef STC
unsigned char code*reset_info="STC89c516 101";
#else
unsigned char code*reset_info="SST89c51 101";
#endif
unsigned char cr,ci;
cr="0";
for (ci=0,ci<24;ci++)
{ com_putch(reset_info[ci]);
ci="cr"+reset_info[ci];
}
cr=0-cr;
com_putch(cr);
}
void delay_ms( unsigned char ci)
{ unsigned char cj;
while(ci)
{ for(cj=0;cj<CON_MSC;cj++);
ci--;
}
}
void goto_pc0(void)
{ unsigned char ci;
EA="0";
ci="SFCF";
#ifdef STC
ci=(ci&0xfc)|2;
SFCF==ci;
while(1)
#else
ci=(ci&0xfc)|0x80;
SFCF=ci;
pc_0=0;
pc_0();
#endif
}
void main(void)
{ unsigned char cr,ci,cj;
unsigned int ui;
PCON=0;
SCON=0x50;
TMOD=0x21;
TH1=CON_BPS;
TL1=CON_BPS;
TR1=1;
EA=0;
TI=1;
WDTD=0;
WDTC=0;
SFCF|=ox80;
for (ci=0,ci<5;ci++)delay_ms(100);
com_putinfo();
ui=0;
RI=0;
while(1)
{ dela_ms(1);
if(RI)
{ ci="SBUF";
RI="0";
ui="0";
if((ci==0x21)||(ci==0x07))break;
}
uiff;
if(ui>10000)goto_pc0();
}
while(1)
{iap_error=0;
if(ci==0x21)
{ for(ci=0;ci<3;ci++)com_buf[ci]=co_getch();
if((com_buf[0]==0x5a)||(com_buf[1]==0)||(com_buf[2]==0xa6))com_putinfo();
else com_putch(5);
}
else if(ci==0x07)
{ for(ci=0;ci<2;ci++)com_buf[ci]=com_getch();
if((com_buf[0]==0x0e)&&com_buf[1])
{ cj="com"_buf[1];
cr="cj";
for(ci=0;ci<=cj;ci++)
{ com_buf[ci]=com_getch();
cr+=com_buf{ci};
}
if(cr)com_putch(5);
else if((com_buf[0]=="W")&&(com_buf[1]==00)&&(cj>4))
{ nAddress="com"_buf[2]*256+com_buf[3];
cj-=4;
for(ci=0;ci<cj;ci++)
{
#ifdef STC
byte_program(nAddress,com_buf[4+ci]);
#else
if(nAddress<0x8000)byte_program(nAddress,com_buf[4+ci]);
#endif
nAddress++;
}
if(iap_error)com_putch(5);
else com_putch(6);
}
else if((com_buf[0]='A')||(com_buf[0]='C'))
{ blocko_erase();
if(iap_error)com_putch(5);
else com_putch(0);
}
else if(com_buf[0]=='U')
{com_putch(6);
goto_pc0();
}
else com_putch(5);
}
else com_putch(5);
}
else com_putch(5);
ci=com_getch();
}
}
文章评论(0条评论)
登录后参与讨论