📄 main.lst
字号:
C51 COMPILER V7.50 MAIN 10/20/2006 13:56:21 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: D:\Keil51\keil\C51\BIN\C51.EXE main.c OPTIMIZE(1,SPEED) BROWSE ORDER DEBUG OBJECTEXTEND CODE
line level source
1 //**********************************************************************************
2 //**********************************************************************************
3 #define uchar unsigned char
4 #define uint unsigned int
5 #define ulong unsigned long
6 #include "w77e516.h"
7 extern char getbyte(void);//从串口取一个字节
8 extern putbyte(char c);//发送一个字节
9 extern putstring(uchar *puts);//发送一个字符串到串口
10 extern puthex(uchar c);//发送一个字节的hex码,分成两个字节发。
11 extern reputstring(uchar *puts);//发送一个字符串到串口
12 #define CR putstring("\r\n")//发送一个回车换行
13 extern void serial_init (void);
14 uchar code help[]="\r\n==============================================="
15 "\r\nISP of 77e516 by yuyuan"
16 "\r\n-----------------------------------------------"
17 "\r\n'r'-Read apflash"
18 "\r\n'e'-Chip erase"
19 "\r\n'w'-Write data to apflash"
20 "\r\n'v'-verify code with hexfile"
21 "\r\n'g'-Run w77e516\r\n"
22 "\r\n===============================================\r\n";
23 //**************************************
24 uchar timer0l,timer0h;
25 uchar xdata temp[1024];
26
27 void timer0_isr (void) interrupt 1
28 {
29 1 TR0=0;
30 1 // putstring("enter time interrupt1!\r\n");
31 1 TL0=timer0l;
32 1 TH0=timer0h;
33 1 }
34
35 closewatchdog()
36 {
37 1 TA=0xAA;
38 1 TA=0x55;
39 1 WDCON=0x00;
40 1 }
41 //片擦
42 void chiperase(void)
43 {
44 1 //UPDATE_64K:
45 1 P34=~P34;
46 1 timer0l=0x9f;//0xD0;
47 1 timer0h=0x0c;//0x8A;
48 1 TL0=timer0l; // 设置擦除操作的唤醒时间,时间一般取决于用户系统时钟,大约是15MS
49 1 TH0=timer0h;
50 1 //ERASE_P_4K:
51 1 SFRCN=0x22; //SFRCN = 22H, 擦除64K APFlash0
52 1
53 1 TCON=0x10; //TCON = 10H, TR0 = 1,GO
54 1 PCON =PCON | 0x01; //进入空闲模式(进行擦除操作
55 1 putstring("Erased__");
C51 COMPILER V7.50 MAIN 10/20/2006 13:56:21 PAGE 2
56 1 TMOD |= 0x21;
57 1 TR1 = 1;
58 1 TR0=0;
59 1 // serial_init();
60 1 putstring("Erased__");
61 1 }
62 //*********************************
63 //读77e516flash中的内容并输出到串口
64 uint readflash()
65 {
66 1 uchar i;
67 1 uint m,n,n_all;
68 1 timer0l= 0xA0;//0xE9; ////为读效验设置定时器, 约1.5uS.
69 1 timer0h=0xFF;
70 1 TL0=timer0l;
71 1 TH0=timer0h;
72 1
73 1 SFRAH=0x00; //目标地址低字节
74 1 SFRCN=0x00; //SFRCN = 00H, 读APFlash0
75 1 SFRAL=0x00;
76 1 n_all=0;
77 1 for(i=0;i<1;i++)
78 1 {
79 2 //get the flashdata;
80 2 for(m=0;m<256;m++)
81 2 {
82 3 SFRAH=m;
83 3 for(n=0;n<256;n++)
84 3 {
85 4 SFRAL=n;
86 4 TCON=0x10; //TCON = 10H, TR0 = 1,GO
87 4 PCON=0x01; //
88 4 serial_init();
89 4 if(n%16==0){CR;puthex(n_all/256);puthex(n_all%256);putbyte(':');}
90 4 puthex(SFRFD);
91 4 n_all++;
92 4 if(RI){getbyte();return 1;} //putstring(help);
93 4 }
94 3 }
95 2 }
96 1 // putstring(help);
97 1 putstring("\r\nRead flash over!\r\n");
98 1 return 0;
99 1 }
100 //***********************************
101 //将两个HEX字节转换成一个字节 (2 hexbytes = 1 byte)
102
103 uchar hextochar(uchar c0,c1)
104 {
105 1 uchar code hex_c[]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,10,11,12,13,14,15};
106 1 return((hex_c[c0-0x30]<<4)+hex_c[c1-0x30]);
107 1 }
108 //****************************************************
109 //从串口接收HEX文件并写入单片机
110 downfile()
111 {
112 1 uchar c1,c0,i,n_of_line,gch;
113 1 uint counter,countertemp;
114 1 uchar cc,statusbit;
115 1 uchar receiveflag;
116 1 uchar failedcounter;
117 1 union {uint addrhl;struct {uchar h,l;}addr;} idata address; //定义现在写入的地址
C51 COMPILER V7.50 MAIN 10/20/2006 13:56:21 PAGE 3
118 1 union {uint addrhl;struct {uchar h,l;}addr;} idata addressall; //定义已经写入的总数
119 1 unsigned char free[8]; //定义行首处理空间
120 1
121 1 chiperase();
122 1 counter=0;
123 1 failedcounter=0;
124 1 cc=0;
125 1 statusbit=0;
126 1 PMR=0x01;
127 1
128 1 // putstring("\r\nsend the file you will download!");
129 1
130 1 SFRAH=0x00;
131 1 SFRAL=0x00;
132 1 SFRCN=0x21;
133 1 timer0l=0xcd; //50us
134 1 timer0h=0xFF;
135 1 TL0=timer0l;
136 1 TH0=timer0h;
137 1 addressall.addrhl=0; //已经写入的总数清0
138 1
139 1 do{
140 2
141 2 resend:
142 2 counter=0x00;
143 2 receiveflag=0;
144 2 while (!(':'==(gch=getbyte())));
145 2 temp[counter]=gch;
146 2 counter++;
147 2 cc=0;
148 2 for(i=0;i!=8;i++) //读取第一行的行首,8字节
149 2 {
150 3 free[i]=temp[counter]=getbyte();
151 3 counter++;
152 3 }
153 2 n_of_line=hextochar(free[0],free[1]); //分析行首,解出行字节总数及行首址
154 2 address.addr.h=hextochar(free[2],free[3]); //高位地址
155 2 address.addr.l=hextochar(free[4],free[5]); //底位地址
156 2 statusbit=hextochar(free[6],free[7]);
157 2 cc=n_of_line+address.addr.h+address.addr.l+statusbit;
158 2 do //大循环,行总数为0时停止,此时文件结束
159 2 {
160 3 do //小循环,每行一个循环
161 3 {
162 4 c1=temp[counter]=getbyte();
163 4 counter++;
164 4 c0=temp[counter]=getbyte();
165 4 counter++; //取两个HEX数据
166 4 c0=hextochar(c1,c0);
167 4 cc+=c0;
168 4 n_of_line--; //该行剩下的字节减一
169 4 }while(n_of_line>0); //写完一行退出该循
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -