📄 otp.lst
字号:
C51 COMPILER V8.02 OTP 12/19/2007 17:51:25 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE OTP
OBJECT MODULE PLACED IN otp.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE otp.c BROWSE DEBUG OBJECTEXTEND
line level source
1
2 #include "define.h"
3 #include "otp.h"
4 #include "mainloop.h"
5 #include "isr.h"
6
7 bdata k_flag=0x0;
8 bdata s_flag=0x0;
9 sbit _50ms = s_flag^0;
10 //k_flag(_kdown, _lkey1, _lkey0, _key1, _key0), lkey_num, key_buf
11 uchar key_buf=0;
12 uchar lkey_num=0;
13 sbit _kdown=k_flag^7;
14 sbit _lkey1=k_flag^6;
15 sbit _lkey0=k_flag^5;
16 sbit _key1=k_flag^4;
17 sbit _key0=k_flag^3;
18 unsigned char otp_type=0x00;
19 unsigned char code mcu_size[]={0x04,0x04,0x04,0x08,0x02}; //get muc_size from type
20 unsigned int code blank_config[]={0x2fff, 0x3fff, 0x3fff, 0x3fff, 0x27ff};
21
22
23 void timer0_50ms(void) interrupt 1 using 1
24 {
25 1 TH0=(65536-50000)/256; /*每隔50MS扫描一次*/
26 1 TL0=(65536-50000)%256;
27 1 _50ms=1;
28 1 }
29
30
31 void init_sub(void)
32 {
33 1 P0=0XFF; P1=0XFF;
34 1 P2=0XFF; P3=0XFF;
35 1
36 1 LED=0; //LED ON
37 1 CE_FLS=1; //SELECT USB
38 1 CE_DET=1;
39 1 VPP_CTRL=1;
40 1 VCC_CTRL=1;
41 1 NRST=1;
42 1 SCLK=1;
43 1 SDAT=1;
44 1 BZ_IO=1;
45 1 INH=1;
46 1
47 1 CE_FLS=0; //SELECT FLASH
48 1 // 如果FLASH内没有CONFIG值,或者没有A标志,就默认型号为0X00
49 1 //0X8000-0X8001:CONFIG, 0X8002:A5, 0X8003:otp_type
50 1 if( (XWORD[0X4000]>0X3FFF)||(XBYTE[0X8002]!=0XA5) )
51 1 otp_type=0x00;
52 1 else
53 1 otp_type=XBYTE[0X8003];
54 1
55 1 }
C51 COMPILER V8.02 OTP 12/19/2007 17:51:25 PAGE 2
56
57
58 void DelayNms(uchar count) //Nms
59 {
60 1 uchar i,j;
61 1
62 1 for(i=0; i<count; i++)
63 1 {
64 2 for(j=0; j<250; j++)
65 2 {
66 3 nop; nop; nop; nop;
67 3 }
68 2 }
69 1 }
70
71 void DelayXus(void) //5.4us
72 {
73 1 /* nop;
74 1 nop;
75 1 nop;
76 1 nop;
77 1 nop; */
78 1 }
79
80 /*******************************************************/
81 void I2cReset(void)
82 {
83 1
84 1 VCC_CTRL=1;
85 1 VPP_CTRL=1;
86 1 SDAT=0;
87 1 SCLK=1;
88 1 DelayXus();
89 1 }
90
91 void pulse_read(void) //???
92 {
93 1 VCC_CTRL=0; //可以改善挑片的毛病
94 1 DelayNms(1);
95 1 VCC_CTRL=1;
96 1 DelayNms(10); //???
97 1 }
98 void start(void)
99 {
100 1
101 1 VCC_CTRL=0; //vcc high
102 1 NRST=0; //pe40 and pa80 reset
103 1 DelayXus();
104 1 NRST=1;
105 1 SDAT=1;
106 1 DelayXus();
107 1 SCLK=0;
108 1 DelayXus();
109 1 SDAT=0;
110 1 DelayXus();
111 1 SCLK=1;
112 1 }
113
114 void send_1bit(bit si)
115 {
116 1 SCLK=1;
117 1 SDAT=si; //SDAT在时钟间断中不跳零
C51 COMPILER V8.02 OTP 12/19/2007 17:51:25 PAGE 3
118 1 DelayXus();
119 1 SCLK=0;
120 1 DelayXus();
121 1 SCLK=1;
122 1 }
123
124 //10,AAAAA,rw,1,AAAAAAAA,0,if x=0, showing read, else showing write
125 void main_command(bit rw, uchar command_adrh, uchar command_adrl)
126 {
127 1 uchar count;
128 1 send_1bit(1); //show main mode
129 1 send_1bit(0);
130 1
131 1 for(count=0;count<5;count++) /*要传送的数据长度为5位*/
132 1 {
133 2 if((command_adrh<<count)&0x10)
134 2 send_1bit(1);
135 2 else
136 2 send_1bit(0);
137 2 }
138 1
139 1 if(rw==0) //根据RW选择读写模式
140 1 send_1bit(0);
141 1 else
142 1 send_1bit(1);
143 1
144 1 send_1bit(1); //high dummy clock
145 1 for(count=0; count<8; count++)
146 1 {
147 2 if((command_adrl<<count)&0x80) /*要传送的数据长度为8位*/
148 2 send_1bit(1);
149 2 else
150 2 send_1bit(0);
151 2 }
152 1 send_1bit(0); //low dummy clock
153 1 }
154
155
156
157 bit rev_1bit(void) //接收一个位
158 {
159 1 bit i;
160 1 SCLK=1; //???
161 1 DelayXus();
162 1 //set SDAT as input mode
163 1 SCLK=0;
164 1 SDAT=1;
165 1 i=SDAT; //READ???
166 1 nop;
167 1 if(SDAT)
168 1 i=1;
169 1 else
170 1 i=0;
171 1 DelayXus();
172 1 SCLK=1;
173 1 return i;
174 1 }
175
176 void whole_write(void)
177 {
178 1 uint adr;
179 1 uchar i, iw;
C51 COMPILER V8.02 OTP 12/19/2007 17:51:25 PAGE 4
180 1 if(!PIN_TEST())
181 1 return;
182 1 CE_FLS =0;
183 1 for(iw=0; iw<mcu_size[otp_type]*16; iw++)
184 1 {
185 2 adr=128*iw; //start address
186 2 for(i=0; i<128; i++)
187 2 {
188 3 EpBuf[i]=XBYTE[adr];
189 3 adr++;
190 3 }
191 2 otp_write(iw);
192 2 P1=P1^0x01;
193 2 }
194 1 CE_FLS =0;
195 1 EpBuf[0]=XBYTE[0x8000];
196 1 EpBuf[1]=XBYTE[0x8001];
197 1 nop; nop;
198 1 write_configue();
199 1 //=========================
200 1
201 1
202 1 }
203
204 void read_data(uchar *p) //读出两个字节放在p指定的地址
205 {
206 1 uchar temp=0x00;
207 1 uchar count;
208 1 for(count=0;count<8;count++)
209 1 {
210 2 temp=temp<<1;
211 2 if(rev_1bit()) //???
212 2 temp=temp|0x01;
213 2 }
214 1 *p=temp;
215 1
216 1 send_1bit(1); //write high dummy clock
217 1 temp=0x00;
218 1 for(count=0;count<8;count++)
219 1 {
220 2 temp=temp<<1;
221 2 if(rev_1bit())
222 2 temp=temp|0x01;
223 2 }
224 1 p++;
225 1 *p=temp;
226 1 send_1bit(0); //write low dummy clock
227 1
228 1 }
229
230 void stop(void)
231 {
232 1 SDAT=0;
233 1 SCLK=1;
234 1 DelayXus();
235 1 SCLK=0;
236 1 DelayXus();
237 1 SDAT=1;
238 1 DelayXus();
239 1 NRST=1;
240 1 DelayXus();
241 1 VCC_CTRL=1;
C51 COMPILER V8.02 OTP 12/19/2007 17:51:25 PAGE 5
242 1 DelayXus();
243 1 SDAT=0;
244 1 SCLK=1;
245 1
246 1 }
247
248 void write_data(uchar *p_read, uchar wt_num)
249 {
250 1 uchar idata iw;
251 1 uchar idata tempw;
252 1 VPP_CTRL=0; //send 12.5v to vpp
253 1 DelayXus();
254 1 DelayXus();
255 1 while(wt_num)
256 1 {
257 2 wt_num--;
258 2 tempw=*p_read;
259 2 for(iw=0; iw<8; iw++)
260 2 {
261 3 if(tempw&0x80)
262 3 send_1bit(1);
263 3 else
264 3 send_1bit(0);
265 3 tempw=tempw<<1;
266 3 }
267 2 send_1bit(1); //send high dummy clock
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -