53501《设计自己的ISP程序》P70Word下载.docx

上传人:b****1 文档编号:812550 上传时间:2023-04-29 格式:DOCX 页数:39 大小:24.20KB
下载 相关 举报
53501《设计自己的ISP程序》P70Word下载.docx_第1页
第1页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第2页
第2页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第3页
第3页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第4页
第4页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第5页
第5页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第6页
第6页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第7页
第7页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第8页
第8页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第9页
第9页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第10页
第10页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第11页
第11页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第12页
第12页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第13页
第13页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第14页
第14页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第15页
第15页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第16页
第16页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第17页
第17页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第18页
第18页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第19页
第19页 / 共39页
53501《设计自己的ISP程序》P70Word下载.docx_第20页
第20页 / 共39页
亲,该文档总共39页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

53501《设计自己的ISP程序》P70Word下载.docx

《53501《设计自己的ISP程序》P70Word下载.docx》由会员分享,可在线阅读,更多相关《53501《设计自己的ISP程序》P70Word下载.docx(39页珍藏版)》请在冰点文库上搜索。

53501《设计自己的ISP程序》P70Word下载.docx

voidbyte_program(unsignedint,unsignedchar);

unsignedcharbyte_verify(unsignedint);

unsignedcharready(void);

*Block0-EraseSubroutine

voidblock0_erase(void)

{

SFCF=SFCF|0x40;

/*enableIAP*/

#ifdefSTC

SFAH=0xf0;

/*STC单片机选择block0*/

#else

SFAH=0x00;

/*SST单片机选择block0*/

#endif

SFDT=0x55;

SFCM=SFCM_BE;

/*issueblockerasecommand*/

if(!

ready())iap_error=1;

}

*Sector-EraseSubroutine

voidsector_erase(unsignedshortintdestAddr)

SFAH=destAddr>

>

8;

/*loadhighorderaddressbyte*/

SFAL=destAddr;

/*loadloworderaddressbyte*/

SFCM=SFCM_SE;

/*issuesectorerasecommand*/

*Byte-ProgramSubroutine

voidbyte_program(unsignedshortintdestAddr,unsignedchardataByte)

/*enableIAP*/

SFDT=dataByte;

/*loaddatatobeprogrammed*/

SFCM=SFCM_PB;

/*issuebyteprogramcommand*/

*Byte-VerifySubroutine

unsignedcharbyte_verify(unsignedshortintdestAddr)

{unsignedcharreadByte;

/*enableIAP*/

/*loadhighorderaddressbyte*/

/*loadloworderaddressbyte*/

SFCM=SFCM_VB;

/*issuebyteverifycommand*/

readByte=SFDT;

SFCF=SFCF&

0xBF;

/*turnoffIAP*/

SFDT=0;

returnreadByte;

*ReadySubroutine

*Purpose:

TocheckiftheIAPoperationiscompleted.

*Whenitisdone,turnoffIAPconfiguration.

unsignedcharready()

{unsignedlongTimeOut;

for(TimeOut=0;

TimeOut<

100000;

TimeOut++)

{if((SFST&

4)==0)/*CheckifIAPisdone*/

{/*IAPisdone*/

SFCF=SFCF&

/*turnoffIAP*/

SFDT=0;

/*anyvalueotherthan0x55*/

return1;

/*IAPoperationiscompleted*/

}

}

/*turnoffIAP*/

/*anyvalueotherthan0x55*/

return0;

/*IAPoperationisNOTcompletedbeforetimeout*/

附件二:

ISP.C

SST或STC单片机ISP程序

魏东(tonywei@)2004.7.25

SST89C54或STC89C516RD,频率:

7.372848MHz

#include"

reg51.h"

/*对IAP.C调用的定义*/

externbitiap_error;

externvoidblock0_erase(void);

externvoidsector_erase(unsignedint);

externvoidbyte_program(unsignedint,unsignedchar);

externunsignedcharbyte_verify(unsignedint);

externunsignedcharready(void);

//#defineSTC/*定义为STC单片机*/

sfrWDTC=0xC0;

sfrWDTD=0x86;

#defineCON_OSC7372848/*振荡频率*/

#defineCON_BPS256-(CON_OSC/12/32/6400)/*6400BPS时间常数*/

#defineCON_MSCCON_OSC/360000/*延时*/

/*变量定义*/

unsignedcharcom_buf[58];

unsignedintnAddress=0;

/*编程器编程地址*/

/*函数定义*/

unsignedcharcom_getch(void);

/*串口接收1字符*/

voidcom_putch(char);

/*串口发送1字符*/

voidcom_putinfo(void);

/*串口发送复位信息*/

voiddelay_ms(unsignedchar);

/*延时(单位:

0.1毫秒)*/

voiddelay_s(unsignedchar);

0.01秒)*/

void(*pc_0)(void);

/*程序地址0000*/

voidgoto_pc0(void);

/*跳转到程序地址0000运行*/

/*************************************************************************/

/*串口接收1字符*/

unsignedcharcom_getch(void)

{unsignedcharc;

RI=0;

while(RI==0);

c=SBUF;

returnc;

/*串口发送1字符*/

voidcom_putch(charc)

TI=0;

SBUF=c;

while(TI==0);

/*串口发送复位信息*/

voidcom_putinfo(void)

unsignedcharcode*reset_info="

STC89C516101"

;

SST89C54101"

unsignedcharcr,ci;

cr=0;

for(ci=0;

ci<

24;

ci++)

{com_putch(reset_info[ci]);

cr=cr+reset_info[ci];

cr=0-cr;

com_putch(cr);

/*发送效验和*/

/*延时(单位:

voiddelay_ms(unsignedcharci)

{unsignedcharcj;

while(ci)

{for(cj=0;

cj<

CON_MSC;

cj++);

/*延时(12/CON_OSC)*3*/

/*编译为汇编如下:

delay_ub:

INCR6;

1

CJNER6,delay_ub;

2

*/

ci--;

/*跳转到程序地址0000运行*/

voidgoto_pc0(void)

{unsignedcharci;

EA=0;

/*禁止中断*/

ci=SFCF;

ci=(ci&

0xfc)|2;

SFCF=ci;

//SFCF[1]从0到1产生软复位,程序从0开始执行,并且SC0按照其设置(从block0运行)

while

(1);

0xfc)|0x80;

pc_0=0;

pc_0();

voidmain(void)

unsignedcharcr,ci,cj;

unsignedintui;

PCON=0;

SCON=0x50;

/*置串口工作方式1(T1用作串口波特率发生)*/

TMOD=0x21;

/*置定时器1工作方式2,定时器0工作方式1*/

TH1=CON_BPS;

/*波特率时间常数*/

TL1=CON_BPS;

TR1=1;

/*启动定时器1*/

TI=1;

/*setTItosendfirstcharofUART*/

WDTD=0;

WDTC=0;

/*关看门狗*/

SFCF|=0x80;

5;

ci++)delay_ms(100);

/*等待50mS稳定时间*/

com_putinfo();

/*发送复位信息*/

ui=0;

while

(1)

{delay_ms

(1);

if(RI)

{ci=SBUF;

RI=0;

ui=0;

if((ci==0x21)||(ci==0x07))break;

/*接收到命令就进入通讯*/

ui++;

if(ui>

=10000)goto_pc0();

/*等待1秒,跳转到用户程序运行*/

{iap_error=0;

if(ci==0x21)

{for(ci=0;

3;

ci++)com_buf[ci]=com_getch();

if((com_buf[0]==0x5a)||(com_buf[1]==0)||(com_buf[2]==0xa6))

com_putinfo();

/*发送复位信息*/

elsecom_putch(5);

/*返回错误标志*/

elseif(ci==0x07)/*数据包:

07H,0EH,包长度,'

W'

00H,地址高字节,地址低字节,程序数据,效验和*/

2;

if((com_buf[0]==0x0e)&

&

com_buf[1])

{cj=com_buf[1];

cr=cj;

for(ci=0;

=cj;

{com_buf[ci]=com_getch();

cr+=com_buf[ci];

}

if(cr)com_putch(5);

elseif((com_buf[0]=='

)&

(com_buf[1]==00)&

(cj>

4))

{nAddress=com_buf[2]*256+com_buf[3];

cj-=4;

for(ci=0;

cj;

{

byte_program(nAddress,com_buf[4+ci]);

/*写*/

if(nAddress<

0x8000)byte_program(nAddress,com_buf[4+ci]);

/*SST限制写地址*/

nAddress++;

}

if(iap_error)com_putch(5);

/*返回错误标志*/

elsecom_putch(6);

/*返回正确标志*/

A'

)||(com_buf[0]=='

C'

))

{block0_erase();

/*擦除器件*/

elseif(com_buf[0]=='

U'

{com_putch(6);

goto_pc0();

/*跳转到用户程序运行*/

elsecom_putch(5);

elsecom_putch(5);

ci=com_getch();

附件三:

DOWNLOAD.C

/********************************************************************

ISP下载程序

ProgramfilesmustbeofINTELstandardHEXformat.

ThiscodewascompiledusingBorlandC++version5.0forDOS.

Theclock()functionisusedtodeterminecommunicationtimeouts.

[thetickresolutionisassumedtobe1/18thofasecond.Itmaybe

differentonothercompilersorinmemorymodelsotherthanLARGE]

********************************************************************/

#include<

stdio.h>

/*forreadinghexfile*/

string.h>

/*forcopyingparameterstrings*/

stdlib.h>

/*forexit()function*/

time.h>

/*forclock()andclock_t(timeouts)*/

conio.h>

/*forreading/writingtheUARThardwareports*/

ctype.h>

/*fortoupper()function*/

/*******************************************************************/

#defineDEFAULTTIMEOUT5/*aboutaquarterofasecond*/

#defineERASETIMEOUT80/*about4seconds*/

#defineVER"

1.01"

#defineDATE"

25July,2004"

 

/*functionprototypes*/

intreset(int*major,int*minor);

intdownload(intrev,char*program);

intrun();

voidshowTitle(void);

voidshowInstructions(void);

intdecodeCommandLine(intargc,char*argv[],

int*comport,double*crystal,

char*filename,

int*dontEraseData,

int*autoRun);

intvalidateParameters(intcomport,double*cryst

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2