protect.lst
来自「为aduc7026应用开发例程」· LST 代码 · 共 750 行 · 第 1/3 页
LST
750 行
ARM COMPILER V2.42, protect 19/06/07 11:55:41 PAGE 1
ARM COMPILER V2.42, COMPILATION OF MODULE protect
OBJECT MODULE PLACED IN .\Output\Keil\protect.obj
COMPILER INVOKED BY: C:\Keil\ARM\BIN\CA.exe protect.c THUMB INCDIR(C:\Keil\ARM\INC\ADI) DEBUG PRINT(.\OUTPUT\KEIL\PROTEC
-T.LST) TABS(4) OBJECT(.\Output\Keil\protect.obj)
stmt level source
1 /*********************************************************************
2
3 Author : ADI - Apps www.analog.com/MicroConverter
4
5 Date : Sept. 2005
6
7 File : protect.c
8
9 Hardware : Applicable to ADuC702x rev H or I silicon
10 Currently targetting ADuC7028.
11
12 Description : In this example page 120 to 123 (@ 8F000h) are erased, and
13 10 integers are written beginning at 8F000h.
14 Write protection on pages 120 to 123 is set and data
15 is read back and send through the UART at 9600 bps
16
17 1) Protect = 0. see on Hyperterminal the Flash/EE memory content: 00A to 001
18 2) Protect = 1. see on Hyperterminal the Flash/EE memory content: 001 to 00A
19 3) Protect = 0. see on Hyperterminal error message
20 4) use ARMWSD to unprotect the Flash: mass erase command in the configure panel
21
22
23 *********************************************************************/
24 #include <ADuC7028.h>
25 #define PROTECT 1
26
27 extern int write (int file, char * ptr, int len); // Function used to write string
28 void delay (int length);
29 void erase_page(unsigned short int addr);
30 void save(unsigned short int addr, unsigned char data);
31 void protect_page(unsigned int addr);
32 unsigned short load(unsigned short int addr);
33 void senddata(short);
34 char hex2ascii(char);
35 unsigned char ERROR;
36 unsigned char status;
37
38 int main(void)
39 {
40 1 unsigned char count = 0;
41 1 unsigned int i = 0;
42 1 char output[7] = "Error\n";
43 1 ERROR = 0;
44 1
45 1 POWKEY1 = 0x01;
46 1 POWCON = 0x00; // 41.78MHz
47 1 POWKEY2 = 0xF4;
48 1
49 1 GP1CON = 0x011; // Setup tx & rx pins on P1.0 and P1.1
50 1
51 1 // Start setting up UART at 9600bps
52 1 COMCON0 = 0x80; // Setting DLAB
53 1 COMDIV0 = 0x88; // updated for rev H
54 1 COMDIV1 = 0x00;
55 1 COMCON0 = 0x07; // Clearing DLAB
56 1
57 1 GP4DAT = 0x04000000; // configure P4.2 as output
58 1 FEEMOD = 0x8; // bit 3 should be set to allow erase/write command
ARM COMPILER V2.42, protect 19/06/07 11:55:41 PAGE 2
59 1
60 1 if (PROTECT){ // if it is not protected yet
61 2
62 2 erase_page(0xF000); // erase page 120-123
63 2
64 2 for (i=0;i<10;i++) {
65 3 count ++; // save numbers
66 3 save(0xF000+2*i, count);
67 3 }
68 2
69 2 for (i=0;i<10;i++){ // Output Data
70 3 senddata (load(0xF000+2*i));
71 3 }
72 2
73 2 protect_page(0xBFFFFFFF); // protect pages 120-123
74 2 RSTSTA = 0x02; // software reset
75 2 }
76 1 else{
77 2
78 2 erase_page(0xF000); // erase page 120-123
79 2
80 2 count = 0xA;
81 2
82 2 if (ERROR){
83 3 write(0,output,7); // Output Error message
84 3 }
85 2 else{
86 3 for (i=0;i<10;i++){ // Save data
87 4 save(0xF000+2*i, count);
88 4 count --;
89 4 }
90 3
91 3 for (i=0;i<10;i++){ // Output Data
92 4 senddata (load(0xF000+2*i));
93 4 }
94 3 }
95 2
96 2 while (1){
97 3 GP4DAT ^= 0x00040000; // complement P4.2
98 3 delay(100000);
99 3 }
100 2
101 2 }
102 1
103 1 return 0;
104 1 }
105
106 void delay (int length) { // delay
107 1 while (length >= 0)
108 1 length--;
109 1 }
110
111 void protect_page(unsigned int addr){
112 1 FEEADR = 0x1234; // Key
113 1 FEEDAT = 0xA5A5; // Key
114 1 FEEPRO = addr;
115 1 FEEMOD = 0x48;
116 1 FEECON = 0x0C;
117 1 status = FEESTA&0x03;
118 1 while (!(status)) status = FEESTA&0x03;
119 1 if ((status&0x02)==0x02) ERROR = 1;
120 1 return; // return
121 1 }
122
123
124 unsigned short load(unsigned short int addr){
ARM COMPILER V2.42, protect 19/06/07 11:55:41 PAGE 3
125 1 FEEADR = addr;
126 1 FEECON = 0x01; // single read command
127 1 status = FEESTA&0x03;
128 1 while (!(status)) status = FEESTA&0x03;
129 1 if ((status&0x02)==0x02) ERROR = 1;
130 1 return (FEEDAT);
131 1 }
132
133
134 void save(unsigned short int addr, unsigned char data){
135 1 FEEADR = addr; // set data address
136 1 FEEDAT = data; // set data value
137 1 FEECON = 0x02; // single Write command
138 1 status = FEESTA&0x03;
139 1 while (!(status)) status = FEESTA&0x03;
140 1 if ((status&0x02)==0x02) ERROR = 1;
141 1 return;
142 1 }
143
144 void erase_page(unsigned short int addr){
145 1 FEEADR = addr; // set data address
146 1 FEECON = 0x05; // erase page command
147 1 status = FEESTA&0x03;
148 1 while (!(status)) status = FEESTA&0x03;
149 1 if ((status&0x02)==0x02) ERROR = 1;
150 1 return;
151 1 }
152
153 void senddata(short to_send){
154 1 while(!(0x020==(COMSTA0 & 0x020))){}
155 1 COMTX = 0x0A; // output LF
156 1 while(!(0x020==(COMSTA0 & 0x020))){}
157 1 COMTX = 0x0D; // output CR
158 1 while(!(0x020==(COMSTA0 & 0x020))){}
159 1 COMTX = hex2ascii ((to_send >> 8) & 0x0F);
160 1 while(!(0x020==(COMSTA0 & 0x020))){}
161 1 COMTX = hex2ascii ((to_send >> 4) & 0x0F);
162 1 while(!(0x020==(COMSTA0 & 0x020))){}
163 1 COMTX = hex2ascii (to_send & 0x0F);
164 1 }
165
166
167 char hex2ascii(char toconv){
168 1 if (toconv<0x0A) toconv += 0x30;
169 1 else toconv += 0x37;
170 1 return (toconv);
171 1 }
172
173
ARM COMPILER V2.42, protect 19/06/07 11:55:41 PAGE 4
ASSEMBLY LISTING OF GENERATED OBJECT CODE
*** EXTERNALS:
EXTERN CODE16 (write?T)
EXTERN NUMBER (__startup)
*** PUBLICS:
PUBLIC delay?T
PUBLIC erase_page?T
PUBLIC save?T
PUBLIC protect_page?T
PUBLIC load?T
PUBLIC senddata?T
PUBLIC hex2ascii?T
PUBLIC main
PUBLIC ERROR
PUBLIC status
*** DATA SEGMENT '?DT0?protect':
00000000 ERROR:
00000000 DS 1
00000001 status:
00000001 DS 1
*** DATA SEGMENT '?CON?protect':
00000000 ?tpl?0001:
00000000 BEGIN_INIT
00000000 DB 'Error',0x0A,0x00
00000007 END_INIT
*** CODE SEGMENT '?PR?main?protect':
38: int main(void)
00000000 B500 PUSH {LR}
00000002 B082 SUB R13,#0x8
39: {
00000004 ; SCOPE-START
40: unsigned char count = 0;
00000004 2500 MOV R5,#0x0
00000006 ---- Variable 'count' assigned to Register 'R5' ----
41: unsigned int i = 0;
00000006 2400 MOV R4,#0x0
00000008 ---- Variable 'i' assigned to Register 'R4' ----
42: char output[7] = "Error\n";
00000008 4800 LDR R1,=?tpl?0001 ; ?tpl?0001
0000000A A800 ADD R0,R13,#0x0
0000000C 2207 MOV R2,#0x7
0000000E L_82:
0000000E 780B LDRB R3,[R1,#0x0]
00000010 7003 STRB R3,[R0,#0x0]
00000012 1C49 ADD R1,R1,#0x1
00000014 1C40 ADD R0,R0,#0x1
00000016 1E52 SUB R2,R2,#0x1
00000018 D1F9 BNE L_82 ; T=0x0000000E
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?