📄 ini_ok.lst
字号:
C51 COMPILER V7.05 INI_OK 10/26/2005 14:17:04 PAGE 1
C51 COMPILER V7.05, COMPILATION OF MODULE INI_OK
OBJECT MODULE PLACED IN ini_ok.OBJ
COMPILER INVOKED BY: C:\Program Files\SiLabs\MCU\IDEfiles\C51\BIN\C51.exe ini_ok.c DB OE
stmt level source
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2004 Silicon Laboratories, Inc.
3 //
4 // AUTH: JS
5 // DATE: 03 JUL 02
6 //
7 // This program flashes the green LED on the C8051F31x target board about
8 // five times a second using the interrupt handler for Timer2.
9 //
10 // Target: C8051F31x
11 //
12 // Tool chain: KEIL Eval 'c'
13 //
14
15 //-----------------------------------------------------------------------------
16 // Includes
17 //-----------------------------------------------------------------------------
18 //OSC=24.5MHz
19 /*
20 ; C8051F310
21 ; KEY5 P0.1 1|---=---|32 P0.2 XTAL1
22 ; KEY6 P0.0 2| |31 P0.3 XTAL2
23 ; GND 3| |30 P0.4 KEY1
24 ; VDD 4| |29 P0.5 KEY2
25 ; /RST/C2ACK 5| |28 P0.6 CNVSTR KEY3
26 ; KEY7 P3.0(C2D) 6| |27 P0.7 KEY4
27 ; CS2 P3.1 7| |26 P1.0 D0
28 ; CS1 P3.2 8| |25 P1.1 D1
29 ; RD P3.3 9| |24 P1.2 D2
30 ; WR P3.4 10| |23 P1.3 D3
31 ; RS P2.7 11| |22 P1.4 D4
32 ; MR_B P2.6 12| |21 P1.5 D5
33 ; MWE P2.5 13| |20 P1.6 D6
34 ; MRE P2.4 14| |19 P1.7 D7
35 ; MALE P2.3 15| |18 P2.0 LP
36 ; MCLE P2.2 16|-------|17 P2.1 MCE
37 ;
38 */
39 //=============================
40 #include <c8051f310.h>
41
42 //=============================
43
44 #define uchar unsigned char
45 #define uint unsigned int
46 //=============================
47 uchar xdata buffer[513]; //开辟页缓存数组
48 uchar *pointer; //建立数组指针
49 uchar raddrl; uchar raddrh; //页寻址的高、低位
50 uchar mydata; //数据
51 //=============================
52 sbit KEY4 =P0^7;
53 sbit RD =P3^3;
54 sbit RS =P2^7;
55 sbit WR =P3^4;
C51 COMPILER V7.05 INI_OK 10/26/2005 14:17:04 PAGE 2
56 sbit MR_B =P2^6;
57 sbit MWE =P2^5;
58 sbit MRE =P2^4;
59 sbit MALE =P2^3;
60 sbit MCLE =P2^2;
61 sbit MCE =P2^1;
62 //================
63 sbit LED =P0^1;
64 //=================
65 uchar autorun;
66 //=========delay without key==========================================
67 void DelayX1ms(uchar count)
68 {
69 1 uchar i,j,k;
70 1 for(i=0;i<count;i++)
71 1 for(j=0;j<40;j++)
72 1 for(k=0;k<120;k++)
73 1 {
74 2 ;
75 2 }
76 1 }
77 //=====================================================================
78 void DelayX10ms(uint count)
79 {
80 1 uint i,j,k;
81 1 for(i=0;i<count;i++)
82 1 for(j=0;j<10;j++)
83 1 for(k=0;k<120;k++)
84 1 {
85 2 ;
86 2 }
87 1 }
88 //====================================================================
89 void Delay50us(uchar count)
90 {
91 1 uchar i,j;
92 1 for(j=0;j<count;j++)
93 1 for(i=0;i<6;i++)
94 1 {
95 2 ;
96 2 }
97 1 }
98 //=======================================================================
99 void key_wait(uint count)
100 {
101 1 uint i,j,k;
102 1 if(autorun==0)
103 1 {
104 2 for(i=0;i<count;i++)
105 2 for(j=0;j<10;j++)
106 2 for(k=0;k<120;k++)
107 2 {
108 3 if(KEY4!=1)
109 3 {
110 4 autorun=1;
111 4 goto next;
112 4 }
113 3 ;
114 3 }
115 2 }
116 1 else
117 1 {
C51 COMPILER V7.05 INI_OK 10/26/2005 14:17:04 PAGE 3
118 2 while(1)
119 2 {
120 3 if(KEY4!=1)
121 3 {
122 4 for(i=0;i<100;i++)
123 4 for(j=0;j<100;j++)
124 4 {
125 5 ;
126 5 }
127 4 goto next;
128 4 }
129 3 }
130 2 }
131 1 next:
132 1 ;
133 1 }
134 //=============K9F5608U0A===============
135 //=============RESET====================
136 void reset(void)
137 {
138 1 MCE=0;
139 1 MR_B=1;
140 1 MRE=1;
141 1 MWE=1;
142 1 MCLE=0;
143 1 MALE=0;
144 1 P1=0xff;
145 1 MCLE=1;
146 1 MALE=0;
147 1 MWE=0;
148 1 MWE=0;
149 1 MWE=0;
150 1 MWE=1;
151 1 MWE=1;
152 1 MWE=1;
153 1 MCLE=0;
154 1 MALE=0;
155 1 while(MR_B==0)
156 1 {
157 2 ;
158 2 }
159 1 }
160 //============命令输出函数=================
161 void writecomd(unsigned char comd)
162 {
163 1 P1=comd;
164 1 MCLE=1;
165 1 MALE=0;
166 1 MWE=0;
167 1 MWE=0;
168 1 MWE=1;
169 1 MWE=1;
170 1 MCLE=0;
171 1 MALE=0;
172 1 }
173 //============地址输出函数====================
174 void writeaddr(uchar raddrl,uchar raddrh)
175 {
176 1 P1=0x00;
177 1 MCLE=0;
178 1 MALE=1;
179 1 MWE=0;
C51 COMPILER V7.05 INI_OK 10/26/2005 14:17:04 PAGE 4
180 1 MWE=0;
181 1 MWE=1;
182 1 MWE=1;
183 1 P1=raddrl;
184 1 MWE=0;
185 1 MWE=0;
186 1 MWE=1;
187 1 MWE=1;
188 1 P1=raddrh;
189 1 MWE=0;
190 1 MWE=0;
191 1 MWE=1;
192 1 MWE=1;
193 1 MCLE=0;
194 1 MALE=0;
195 1 }
196 //=============数据输出函数=============
197 void writedata(void)
198 {
199 1 P1= *pointer;
200 1 MWE=0;
201 1 MWE=0;
202 1 MWE=1;
203 1 MWE=1;
204 1 pointer++;
205 1 }
206 //=============读操作==================
207 uchar readsta(void)
208 {
209 1 unsigned char soop;
210 1 P1MDOUT=0x00;
211 1 P1=0xff;
212 1 DelayX1ms(20);
213 1 MRE=0;
214 1 MRE=0;
215 1 soop=P1;
216 1 MRE=1;
217 1 P1MDOUT=0xff;
218 1 return(soop);
219 1 }
220 //==============整块擦除1块=32pages 共2048块====
221 uchar blockerase(uint block)
222 {
223 1 unsigned char result;
224 1 writecomd(0x60);
225 1 block=block*32;
226 1 P1=block&0x00ff;
227 1 MCLE=0;
228 1 MALE=1;
229 1 MWE=0;
230 1 MWE=0;
231 1 MWE=1;
232 1 MWE=1;
233 1 P1=(block&0xff00)>>8;
234 1 MWE=0;
235 1 MWE=0;
236 1 MWE=1;
237 1 MWE=1;
238 1 MCLE=0;
239 1 MALE=0;
240 1 writecomd(0xd0);
241 1 while(MR_B==0)
C51 COMPILER V7.05 INI_OK 10/26/2005 14:17:04 PAGE 5
242 1 {
243 2 ;
244 2 }
245 1 writecomd(0x70);
246 1 result=readsta();
247 1 if((result&0x01)== 1)
248 1 {
249 2 return(1);
250 2 }//出错处理
251 1 else
252 1 return(0);
253 1 }
254 //==============整页写入的详细代码======
255 uchar pagewrite(uchar raddrl,uchar raddrh)
256 {
257 1 int i;
258 1 unsigned char result;
259 1 pointer = &buffer;
260 1 writecomd(0x00);//必须指出开始地址
261 1 writecomd(0x80);
262 1 writeaddr(raddrl,raddrh);
263 1 for(i=0;i<512;i++)
264 1 {
265 2 writedata();
266 2 }
267 1 writecomd(0x10);
268 1 while(MR_B==0)
269 1 {
270 2 ;
271 2 }
272 1 writecomd(0x70);
273 1 result=readsta();
274 1 if((result&0x01) == 1)
275 1 {
276 2 return(1);
277 2 }//出错处理
278 1 else
279 1 return(0);
280 1 }
281 //===============
282 //-----------------------------------------------------------------------------
283 // SYSCLK_Init
284 //-----------------------------------------------------------------------------
285 //
286 // This routine initializes the system clock to use the internal 24.5MHz / 8
287 // oscillator as its clock source. Also enables missing clock detector reset.
288 //
289 void SYSCLK_Init (void)
290 {
291 1 OSCICN = 0x83; // IOSCEN IFRDY 0 0 0 0 IFCN1 IFCN0 (sfr OSCICN=0xB2;内部振荡器
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -