OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 4912|回复: 2

stc单片机在线升级程序的问题

[复制链接]

19

主题

64

帖子

0

精华

初级会员

Rank: 2

积分
160
金钱
160
注册时间
2014-5-23
在线时间
0 小时
发表于 2014-8-12 09:23:29 | 显示全部楼层 |阅读模式
5金钱
[mw_shl_code=c,true]/*------------------------------------------------------------------*/ /* --- STC MCU International Limited -------------------------------*/ /* --- STC IAP ?????????ú???????§ISP ???????ò ----------------------*/ /* --- Mobile: (86)13922805190 -------------------------------------*/ /* --- Fax: 86-755-82944243 ----------------------------------------*/ /* --- Tel: 86-755-82948412 ----------------------------------------*/ /* --- Web: www.STCMCU.com -----------------------------------------*/ /* ???????????ò???????ò???????????????????ò,???????ò???ò??????×??÷ */ /* ???????ê?§??????×????ò???ò */ /*------------------------------------------------------------------*/ #include<STC12C5A.h> #include "absacc.h" sbit en=P3^2; //MAX485????????IO sbit led1=P4^1; sbit seg5=P2^4; sbit seg6=P2^5; sbit seg7=P2^6; #define seg_duan P0 char code seg_yang[]={0x40, 0xf9, 0x24, 0xa0, 0x91, 0x82, 0x02, 0xf8, 0x00, 0x80};//???? /*?¨??????*/ #define FOSC 11059200L //?????±???? #define BAUD (256 - FOSC/32/19200) //?¨???®???¨???? #define MAX_SIZE 118 //???§???ò×??ó???????????? #define ENABLE_IAP 0x82 //?????¤×÷????<20MHz typedef unsigned char BYTE; typedef unsigned int WORD; typedef struct { BYTE cmd; WORD addr; WORD len; BYTE chk; } CBW; void Isp_Check(BYTE *p); BYTE Isp_RecvUart(); void Isp_RecvBlock(BYTE *p, BYTE n); void Isp_SendUart(BYTE dat); void Isp_SoftReset(); BYTE cnt7f; //Isp_Check??????????±???,????7F???????÷,?±??????????16??7F?ó????ISP???????? CBW cbw; //?®???ü???é BYTE sum; //???é??±??? BYTE buf[64]; //?????????? /*------------------------------------------------ ?®??????·??????ò ------------------------------------------------*/ void uart() interrupt 4 { if (TI) TI = 0; //·????ê?????? if (RI) //?????ê?????? { Isp_Check(&cnt7f); //ISP?ì?? RI = 0; //???????ê??±ê?? } } void delayms(int xms)//???±???? { for(;xms>0;xms--); } void main() { SCON = 0x50; //?¨???®????????8bit??±?,?????é?? AUXR = 0x15; //?¨????·??ú?÷12±???,???????¨????·??ú?÷?¨?±?÷ BRT = BAUD; //???????¨????·??ú?÷?¨?±?÷???¨?±???? ES = 1; //?????®?????? EA = 1; //?ò?????????????? en=0; while (1) { led1=~led1; delayms(5000); } } /*------------------------------------------------ ?®??ISP?ü???ò???ì?????é ------------------------------------------------*/ void Isp_Check(BYTE *p) { BYTE i; WORD j; if (SBUF != 0x7f) //?ì???®????????·???7F { *p = 0; //??????7F,?ò??7F?????? // Isp_SoftReset(); //??????·?·¨?ü???±,???????? } else { (*p)++; //????7F,?ò7F??????+1 if (*p>=16) //????7F??·?????????????16?? { //??>=16??,?ò????ISP???????? IE = 0; //??±??ù?????? PSW = 0; //ISP???é??????0×é?????÷ SP = 0x5f; //????ISP???é?????????? RI = 0; //?????®??????±ê?? TI = 0; //???®??·???±ê?? Isp_SendUart(0x5a); //·???5A 69??PC,±í??ISP???é??×?±????÷ Isp_SendUart(0x69); //·???5A 69??PC,±í??ISP???é??×?±????÷ while (1) //ISP????????,?÷???· { sum = 0; //?????é?? //???ü?????í,?ò???ò???? if((Isp_RecvUart()==0x5a)&&(Isp_RecvUart()==0x69)) { Isp_RecvBlock((BYTE *)&cbw, 6); //????6×??????ü???ò?? if (sum != 0) //?????ü???ò????·????· { Isp_SoftReset(); //???ü?????í,?ò???ò???? } switch (cbw.cmd) { case 0: //0???ü?????????ü?? IAP_ADDRL = 0; //????0???????????? IAP_ADDRH = 0; IAP_CONTR = ENABLE_IAP; //????IAP???? IAP_CMD = 3; //?????ü?? if (cbw.len > MAX_SIZE) //????????????????·?????·??§ { cbw.len = MAX_SIZE; } while (cbw.len--) //??????·??????ê?? { WDT_CONTR = 0x17; //???????· IAP_TRIG = 0x5a; //??·?ISP?ü?? IAP_TRIG = 0xa5; IAP_ADDRH += 2; //??±ê???·+512 } Isp_SendUart(0); //???··??? break; case 1: //1???ü????±à???ü?? sum = 0; //???????é???? Isp_RecvBlock(buf, 64); //????64×?????±à?????? Isp_RecvUart(); //???????é?? if (sum != 0) //??????????·????· { Isp_SoftReset(); //?????????í,?ò???ò???? } IAP_CONTR = ENABLE_IAP; //????IAP???? IAP_CMD = 2; //±à???ü?? j = cbw.addr; //±à????±ê???· for (i=0; i<64; i++) //±à??64×??????? { WDT_CONTR = 0x17; //???????· IAP_DATA = buf; //???±?°??????IAP?????????÷ IAP_ADDRL = j; //??±ê???·??IAP???·?????÷ IAP_ADDRH = j >> 8; IAP_TRIG = 0x5a; //??·?ISP?ü?? IAP_TRIG = 0xa5; j++; //??±ê???·+1 } j = cbw.addr; //???é??±ê???· for (i=0; i<64; i++) //???é64×??????? { WDT_CONTR = 0x17; //???????· if (buf != CBYTE[j]) //??????????±ê????????±??? break; //???à??,?ò±à?????í j++; //???é??????×??? } Isp_SendUart(!(i == 64)); //???é????·???0; ·??ò·???1 break; default: Isp_SoftReset(); //??????·?·¨?ü???±,???????? break; } } } } } } /*------------------------------------------------ ???????é?®?????? ????????: R0 (?????????????·) R7 (???????¤??) ------------------------------------------------*/ void Isp_RecvBlock(BYTE *p, BYTE n) { while (n--) //?ì???¤?? { *p = Isp_RecvUart(); //????1×???,??±??????????? p++; //?????????·+1 } } /*------------------------------------------------ ????1×????®?????? ????????: ACC (????????????) ------------------------------------------------*/ BYTE Isp_RecvUart() { BYTE dat; RI = 0; //?????®??????±ê?? en=0; while (!RI) //?????????ê?? { WDT_CONTR = 0x17; //???????· } dat = SBUF; //?????®?????? RI = 0; //????±ê?? sum += dat; //???????é?? return dat; //·????????????®?????? } /*------------------------------------------------ ·???1×????®?????? ????????: ACC (??·?????????) ------------------------------------------------*/ void Isp_SendUart(BYTE dat) { en=1; TI = 0; //????±ê?? SBUF = dat; //·????±?°???? while (!TI) //?????°????????·????ê?? { WDT_CONTR = 0x17; //???????· } en=0; } /*------------------------------------------------ ?í?????? ------------------------------------------------*/ void Isp_SoftReset() { IAP_CONTR = 0x20; //???§???ò?????? } [/mw_shl_code]
请问大神们,这个ISP在线升级程序的通讯协议怎么看?没有经验,求指教啊。。。

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165309
金钱
165309
注册时间
2010-12-1
在线时间
2108 小时
发表于 2014-8-12 23:00:46 | 显示全部楼层
这还真不好看...
直接问作者要文档比较靠谱点.
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复

使用道具 举报

19

主题

64

帖子

0

精华

初级会员

Rank: 2

积分
160
金钱
160
注册时间
2014-5-23
在线时间
0 小时
 楼主| 发表于 2014-8-13 15:09:39 | 显示全部楼层
回复【2楼】正点原子:
---------------------------------
发过来的就变这样了。。。蛋疼。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-11-23 04:10

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表