📄 updater_f02x.lst
字号:
C51 COMPILER V7.50 UPDATER_F02X 06/05/2007 11:01:38 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE UPDATER_F02X
OBJECT MODULE PLACED IN updater_F02x.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE updater_F02x.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 可用于用户程序的空间共为122个扇区共62464个字节(0x0000-0xF3FF)
3 引导程序占用四个扇区(0xF400-0xFBFF) 2048字节
4 */
5 #include <c8051f020.h> // SFR declarations
6 #include "crc.h"
7
8 //-----------------------------------------------------------------------------
9 // Global CONSTANTS
10 //-----------------------------------------------------------------------------
11 #define TRUE 1
12 #define FALSE 0
13
14 #define SYSCLK 22118400 // SYSCLK frequency in Hz
15 #define BAUDRATE 115200 // Baud rate of UART in bps
16
17 #define BINCELL_LEN 518 //数据段大小
18
19 sbit Run = P3^7; // LED='1' means ON
20
21 unsigned char xdata Rec_Buf[600];
22 unsigned char xdata Send_Buf[512];
23 unsigned int P_RecBuf=0;
24 //-----------------------------------------------------------------------------
25 // Function PROTOTYPES
26 //-----------------------------------------------------------------------------
27
28 void main (void);
29
30 // Initialization Subroutines
31 void SYSCLK_Init (void);
32 void PORT_Init (void);
33 void UART0_Init (void);
34
35
36 //-----------------------------------------------------------------------------
37 // Global VARIABLES
38 //-----------------------------------------------------------------------------
39
40 void (*f)(); // function pointer declaration
41
42 bit code_erased = FALSE; // flag used to indicate that the FLASH
43 // erase operation is complete
44 bit f_valid = FALSE; // flag to indicate that the FLASH
45 // programming operation is complete
46 bit Need_Update=0;
47
48 unsigned char Update_Step=0;
49 //-----------------------------------------------------------------------------
50 // MAIN Routine
51 //-----------------------------------------------------------------------------
52
53 void DealRec();
54 void SendData(unsigned char *SendBuf,unsigned char SendLen);
55 void Erase_Flash(unsigned char Erase_Page);
C51 COMPILER V7.50 UPDATER_F02X 06/05/2007 11:01:38 PAGE 2
56 void Write_Flash(unsigned char *Write_Buf,unsigned char Write_Page);
57 unsigned char Read_Flash(unsigned int Read_Address );
58
59 //延时1ms
60 void DelayMs(unsigned int TimeNum)
61 {
62 1 unsigned int i,j;
63 1 for(i=0;i<TimeNum;i++)
64 1 {
65 2 for(j=0;j<185;j++);
66 2 }
67 1 }
68
69 void JumpToRun()
70 {
71 1 IE=0;
72 1 CKCON=0;
73 1 PCON=0;
74 1 TMOD=0;
75 1 SCON0=0;
76 1 TH1=0;
77 1 TL1=0;
78 1 TR1=0;
79 1 ((void(code *)(void))0xF400)();
80 1
81 1 }
82
83 void main (void)
84 {
85 1 unsigned int Update_OverTime=0;
86 1
87 1 WDTCN = 0xde; // disable watchdog timer
88 1 WDTCN = 0xad;
89 1
90 1 EA = 0; // disable interrupts (this statement
91 1 // is needed because the device is not
92 1 // neccesarily in a reset state prior
93 1 // to executing this code)
94 1 OSCXCN=0;
95 1
96 1
97 1 PORT_Init (); // initialize crossbar and GPIO
98 1 SYSCLK_Init (); // initialize oscillator
99 1 UART0_Init (); // initialize UART0
100 1
101 1 Run=0;
102 1
103 1 DelayMs(100);
104 1 Update_Step=1;
105 1 Send_Buf[0]=0x55;
106 1 Send_Buf[1]=0xAA;
107 1 Send_Buf[2]=0xA1;
108 1 SendData(Send_Buf,3);
109 1
110 1 /*while(RI0==0)
111 1 {
112 1 if(Update_OverTime>60000) //如果升级超时,则进入正常程序
113 1 {
114 1 JumpToRun();
115 1
116 1 }
117 1 else
C51 COMPILER V7.50 UPDATER_F02X 06/05/2007 11:01:38 PAGE 3
118 1 {
119 1 Update_OverTime++;
120 1 }
121 1 }
122 1 Rec_Buf[P_RecBuf++]=SBUF0;
123 1 RI0=0;
124 1 Update_OverTime=0;*/
125 1
126 1
127 1 while (1)
128 1 {
129 2 while(RI0==0)
130 2 {
131 3 if(Need_Update==0)
132 3 {
133 4 if(Update_OverTime>60000) //如果升级超时,则进入正常程序
134 4 {
135 5 JumpToRun();
136 5
137 5 }
138 4 else
139 4 {
140 5 Update_OverTime++;
141 5 }
142 4 }
143 3 }
144 2
145 2 Rec_Buf[P_RecBuf++]=SBUF0;
146 2 RI0=0;
147 2 Update_OverTime=0;
148 2 DealRec();
149 2 } // end while
150 1
151 1 } // end main
152
153 void SendData(unsigned char *SendBuf,unsigned char SendLen)
154 {
155 1 unsigned char i;
156 1 for(i=0;i<SendLen;i++)
157 1 {
158 2 SBUF0=SendBuf[i];
159 2 while(TI0==0);
160 2 TI0=0;
161 2 }
162 1 }
163
164 void DealRec()
165 {
166 1 unsigned int i;
167 1 unsigned int CRC;
168 1 unsigned char CRC_H;
169 1 unsigned char CRC_L;
170 1 unsigned int Cell_No;
171 1 bit Write_Error=0;
172 1 if(P_RecBuf>=3) //至少收到三个字节。
173 1 {
174 2 if(Rec_Buf[0]==0x55&&Rec_Buf[1]==0xAA) //数据帧头有效
175 2 {
176 3 switch(Rec_Buf[2])
177 3 {
178 4 case 0xB1: //收到上位机应答升级请求的命令
179 4 if(Update_Step==1)
C51 COMPILER V7.50 UPDATER_F02X 06/05/2007 11:01:38 PAGE 4
180 4 {
181 5 Update_Step=2;
182 5 Need_Update=1;
183 5 }
184 4 P_RecBuf=0;
185 4 break;
186 4 case 0xC1: //收到上位机要求升级的指令
187 4 if(Update_Step==2)
188 4 {
189 5 Update_Step=3;
190 5 Send_Buf[0]=0x55;
191 5 Send_Buf[1]=0xAA;
192 5 Send_Buf[2]=0xD1;
193 5 SendData(Send_Buf,3); //返回可以接收数据
194 5 }
195 4 P_RecBuf=0;
196 4 break;
197 4 case 0xE1: //收到上位机发送的数据帧
198 4 if(P_RecBuf<BINCELL_LEN) return; //帧未收全则返回
199 4 if(Update_Step!=3) {P_RecBuf=0;return;}
200 4
201 4 CRC=cal_crc(Rec_Buf+4,512);
202 4 CRC_H=CRC>>8;
203 4 CRC_L=CRC;
204 4 if(Rec_Buf[516]==CRC_H&&Rec_Buf[517]==CRC_L) //通过CRC校验,则写入数据
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -