📄 nixie.lst
字号:
185 2 }
186 1 temp|=((add&0x1f)<<1);
187 1 SCLK_1302 = 0;
188 1 NOP();
189 1 RST_1302 = 1;
190 1 NOP();
191 1 write_byte(temp);
192 1 write_byte(dat);
193 1 RST_1302 = 0;
194 1 NOP();
195 1 }
196
197 /**************************************
198 *从DS1302的指定地址读一个字节
199 **************************************/
200 uchar read_data(uchar add,bit type)
201 {
202 1 uchar temp;
203 1 RST_1302 = 0;
204 1 NOP();
205 1 SCLK_1302 = 0;
206 1 NOP();
207 1 RST_1302 = 1;
208 1 NOP();
209 1 if(type == RAM_1302)
210 1 {
211 2 temp = 0xC1;
212 2 }
213 1 else
214 1 {
215 2 temp = 0x81;
216 2 }
217 1 temp|=((add&0x1f)<<1);
218 1 SCLK_1302 = 0;
219 1 NOP();
220 1 RST_1302 = 1;
221 1 NOP();
222 1 write_byte(temp);
223 1 temp = read_byte();
224 1 RST_1302 = 0;
225 1 NOP();
226 1 return(temp);
227 1 }
228
229 /**************************************
230 *获得按键状态
231 **************************************/
232 void get_key()
233 {
234 1 if((P1&0x07) != 0x07)
235 1 {
236 2 if(key_down == 1)
237 2 {
238 3 return;
239 3 }
240 2 else
241 2 {
C51 COMPILER V8.09 NIXIE 10/22/2008 23:02:09 PAGE 5
242 3 delay_ms(10);
243 3 if((P1&0x07) != 0x07)
244 3 {
245 4 if(key1 == 0)
246 4 {
247 5 sec_inc = 1;
248 5 }
249 4 else if(key2 == 0)
250 4 {
251 5 min_inc = 1;
252 5 }
253 4 else if(key3 == 0)
254 4 {
255 5 hour_inc = 1;
256 5 }
257 4 }
258 3 }
259 2 }
260 1 else
261 1 {
262 2 key_down = 0;
263 2 }
264 1
265 1 }
266
267 /**************************************
268 *定时器中断
269 **************************************/
270 void timer0_task() interrupt 1
271 {
272 1 TH0 = 0x3C;
273 1 TL0 = 0xB0;
274 1 get_key();
275 1 }
276
277 /**************************************
278 *主函数
279 **************************************/
280 void main()
281 {
282 1 init_io();
283 1 init_timer();
284 1 if(read_data(0x05,RAM_1302)!=0xA5)//是否断电?
285 1 {
286 2 write_data(0x07,0x00,CLOCK_1302);//开写保护
287 2 write_data(0x05,0xA5,RAM_1302); //写断电标志
288 2 write_data(0x02,0x12,CLOCK_1302);//初始化时间
289 2 write_data(0x01,0x00,CLOCK_1302);
290 2 write_data(0x00,0x00,CLOCK_1302);
291 2 }
292 1 write_data(0x07,0x80,CLOCK_1302);//写保护
293 1 while(1)
294 1 {
295 2 if(sec_inc == 1)
296 2 {
297 3 sec = read_data(0x00,CLOCK_1302);
298 3 sec++;
299 3 if((sec&0x0f)>9)
300 3 {
301 4 sec &= 0xf0;
302 4 sec += 0x10;
303 4 }
C51 COMPILER V8.09 NIXIE 10/22/2008 23:02:09 PAGE 6
304 3 if(sec > 59)
305 3 {
306 4 sec = 0;
307 4 }
308 3 write_data(0x07,0x00,CLOCK_1302);
309 3 write_data(0x00,sec,CLOCK_1302);
310 3 write_data(0x07,0x80,CLOCK_1302);
311 3 sec_inc = 0;
312 3 disp_req = 1;
313 3 }
314 2 if(min_inc == 1)
315 2 {
316 3 min = read_data(0x01,CLOCK_1302);
317 3 min++;
318 3 if((min&0x0f)>9)
319 3 {
320 4 min &= 0xf0;
321 4 min += 0x10;
322 4 }
323 3 if(min > 59)
324 3 {
325 4 min = 0;
326 4 }
327 3 write_data(0x07,0x00,CLOCK_1302);
328 3 write_data(0x01,min,CLOCK_1302);
329 3 write_data(0x07,0x80,CLOCK_1302);
330 3 min_inc = 0;
331 3 disp_req = 1;
332 3 }
333 2 if(hour_inc == 1)
334 2 {
335 3 hour = read_data(0x02,CLOCK_1302);
336 3 hour++;
337 3 if((hour&0x0f)>9)
338 3 {
339 4 hour &= 0xf0;
340 4 hour += 0x10;
341 4 }
342 3 if(hour > 23)
343 3 {
344 4 hour = 0;
345 4 }
346 3 write_data(0x07,0x00,CLOCK_1302);
347 3 write_data(0x02,hour,CLOCK_1302);
348 3 write_data(0x07,0x80,CLOCK_1302);
349 3 hour_inc = 0;
350 3 disp_req = 1;
351 3 }
352 2 if((sec != read_data(0x00,CLOCK_1302))|(disp_req == 1))
353 2 {
354 3 sec = read_data(0x00,CLOCK_1302);
355 3 min = read_data(0x01,CLOCK_1302);
356 3 hour = read_data(0x02,CLOCK_1302);
357 3 disp_time();
358 3 disp_req = 0;
359 3 }
360 2 }
361 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 760 ----
C51 COMPILER V8.09 NIXIE 10/22/2008 23:02:09 PAGE 7
CONSTANT SIZE = 20 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 3 ----
IDATA SIZE = ---- ----
BIT SIZE = 5 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -