?? 帶農歷帶生肖.lst
字號:
247
248
249
250 /*****************************************************************************/
251 //清屏函數
252 void LCM_clr(void)
253 {
254 1 LCM_WriteDatOrCom (0,0x30);
255 1 LCM_WriteDatOrCom (0,0x01);
256 1 Delay (180);
257 1
258 1 }
259
260 /*****************************************************************************/
261 //向LCM發送一個字符串,長度64字符之內。
262 //應用:LCM_WriteString("您好!");
263 void LCM_WriteString(unsigned char *str)
264 {
265 1 while(*str != '\0')
266 1 {
267 2 LCM_WriteDatOrCom(1,*str++);
268 2 }
269 1 *str = 0;
270 1 }
271 /******************************************************************************/
272 void Delay(int num)//延時函數
273 {
274 1 while(num--);
275 1 }
276 /******************************************************************************/
277 void Init_DS18B20(void)//初始化ds1820
278 {
279 1 unsigned char x=0;
280 1 DQ = 1; //DQ復位
281 1 Delay(8); //稍做延時
282 1 DQ = 0; //單片機將DQ拉低
283 1 Delay(80); //精確延時 大于 480us
284 1 DQ = 1; //拉高總線
285 1 Delay(14);
286 1 x=DQ; //稍做延時后 如果x=0則初始化成功 x=1則初始化失敗
287 1 Delay(20);
288 1 }
289 /******************************************************************************/
290 unsigned char ReadOneChar(void)//讀一個字節
291 {
292 1 unsigned char i=0;
293 1 unsigned char dat = 0;
294 1 for (i=8;i>0;i--)
295 1 {
296 2 DQ = 0; // 給脈沖信號
297 2 dat>>=1;
298 2 DQ = 1; // 給脈沖信號
299 2 if(DQ)
300 2 dat|=0x80;
301 2 Delay(4);
C51 COMPILER V8.08 確農繽確蒧肖 01/25/2009 10:21:59 PAGE 6
302 2 }
303 1 return(dat);
304 1 }
305
306 /******************************************************************************/
307 void WriteOneChar(unsigned char dat)//寫一個字節
308 {
309 1 unsigned char i=0;
310 1 for (i=8; i>0; i--)
311 1 {
312 2 DQ = 0;
313 2 DQ = dat&0x01;
314 2 Delay(5);
315 2 DQ = 1;
316 2 dat>>=1;
317 2 }
318 1 }
319 /******************************************************************************/
320 unsigned int ReadTemperature(void)//讀取溫度
321 {
322 1 unsigned char a=0;
323 1 unsigned char b=0;
324 1 unsigned int t=0;
325 1 float tt=0;
326 1 Init_DS18B20();
327 1 WriteOneChar(0xCC); // 跳過讀序號列號的操作
328 1 WriteOneChar(0x44); // 啟動溫度轉換
329 1 Init_DS18B20();
330 1 WriteOneChar(0xCC); //跳過讀序號列號的操作
331 1 WriteOneChar(0xBE); //讀取溫度寄存器
332 1 a=ReadOneChar(); //讀低8位
333 1 b=ReadOneChar(); //讀高8位
334 1 t=b;
335 1 t<<=8;
336 1 t=t|a;
337 1 tt=t*0.0625;
338 1 t= tt*10+0.5; //放大10倍輸出并四舍五入
339 1 return(t);
340 1 }
341 /*****************************************************************************/
342 //聲明
343 void LCM_w_ss(void);
344 void LCM_w_mm(void);
345 void LCM_w_hh(void);
346 void LCM_w_dd(void);
347 void LCM_w_mo(void);
348 void LCM_w_yy(void);
349 void LCM_w_xq(void);
350 void DS1302InputByte(unsigned char d) ;
351 unsigned char DS1302OutputByte(void) ;
352 void Init_1302(void);
353 unsigned char Read1302(unsigned char);
354
355 void Set_time(unsigned char sel);
356 void Write1302(unsigned char , unsigned char );
357 void updata (void);
358 /*****************************************************************************/
359
360 /*****************************************************************************/
361 //調時用加1程序
362 void Set_time(unsigned char sel) //根據選擇調整的相應項目加1并寫入DS1302
363 {
C51 COMPILER V8.08 確農繽確蒧肖 01/25/2009 10:21:59 PAGE 7
364 1 signed char address,item;
365 1 signed char max,mini;
366 1 LCM_WriteDatOrCom(0,0x9a);
367 1 LCM_WriteString("調整");
368 1 //if(sel==6) {LCM_WriteString("秒鐘");address=0x80; max=0;mini=0;} //秒7
369 1 if(sel==5) {LCM_WriteString("分鐘");address=0x82; max=59;mini=0;} //分鐘6
370 1 if(sel==4) {LCM_WriteString("小時");address=0x84; max=23;mini=0;} //小時5
371 1 if(sel==3) {LCM_WriteString("星期");address=0x8a; max=7;mini=1;} //星期4
372 1 if(sel==2) {LCM_WriteString("日期");address=0x86; max=31;mini=1;} //日3
373 1 if(sel==1) {LCM_WriteString("月份");address=0x88; max=12;mini=1;} //月2
374 1 if(sel==0) {LCM_WriteString("年份");address=0x8c; max=99; mini=0;} //年1
375 1
376 1 //讀取1302某地址上的數值轉換成10進制賦給item
377 1 item=((Read1302(address+1))/16)*10 + (Read1302(address+1))%16;
378 1 if(KEY_2 == 0)
379 1 {
380 2 item++;//數加 1
381 2 }
382 1 if(KEY_4 == 0){
383 2 item--;//數減 1
384 2 }
385 1 if(item>max) item=mini;//查看數值有效范圍
386 1 if(item<mini) item=max;
387 1 Write1302(0x8e,0x00);//允許寫操作
388 1 Write1302(address,(item/10)*16+item%10);//轉換成16進制寫入1302
389 1 Write1302(0x8e,0x80);//寫保護,禁止寫操作
390 1 updata (); //刷新數據
391 1 LCM_w_mm();//刷新 分
392 1 nl();
393 1 }
394 /*****************************************************************************/
395 //設置1302的初始時間
396 void Init_1302(void) //(2007年1月1日00時00分00秒星期一)
397 { uchar cctt;
398 1 cctt=Read1302(0x80);
399 1 if(cctt&0x80)
400 1 {
401 2 Write1302(0x8e,0x00);//允許寫操作
402 2 Write1302(0x8c,0x08);//年
403 2 Write1302(0x8a,0x02);//星期
404 2 Write1302(0x88,0x01);//月
405 2 Write1302(0x86,0x01);//日
406 2 Write1302(0x84,0x00);//小時
407 2 Write1302(0x82,0x00);//分鐘
408 2 Write1302(0x80,0x00);//秒
409 2 // Write1302(0x90,0x55);//充電
410 2 Write1302(0x8e,0x80);//禁止寫操作
411 2 }
412 1 }
413 void DS1302InputByte(unsigned char d) //實時時鐘寫入一字節(內部函數)
414 {
415 1 unsigned char i;
416 1 ACC = d;
417 1 for(i=8; i>0; i--)
418 1 {
419 2 DS1302_IO = ACC0; //相當于匯編中的 RRC
420 2 DS1302_CLK = 1;
421 2 DS1302_CLK = 0;
422 2 ACC = ACC >> 1;
423 2 }
424 1 }
425
C51 COMPILER V8.08 確農繽確蒧肖 01/25/2009 10:21:59 PAGE 8
426 unsigned char DS1302OutputByte(void) //實時時鐘讀取一字節(內部函數)
427 {
428 1 unsigned char i;
429 1 for(i=8; i>0; i--)
430 1 {
431 2 ACC = ACC >>1; //相當于匯編中的 RRC
432 2 ACC7 = DS1302_IO;
433 2 DS1302_CLK = 1;
434 2 DS1302_CLK = 0;
435 2 }
436 1 return(ACC);
437 1 }
438
439 void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302地址, ucData: 要寫的數據
440 {
441 1 DS1302_RST = 0;
442 1 DS1302_CLK = 0;
443 1 DS1302_RST = 1;
444 1 DS1302InputByte(ucAddr); // 地址,命令
445 1 DS1302InputByte(ucDa); // 寫1Byte數據
446 1 DS1302_CLK = 1;
447 1 DS1302_RST = 0;
448 1 }
449
450 unsigned char Read1302(unsigned char ucAddr) //讀取DS1302某地址的數據
451 {
452 1 unsigned char ucData;
453 1 DS1302_RST = 0;
454 1 DS1302_CLK = 0;
455 1 DS1302_RST = 1;
456 1 DS1302InputByte(ucAddr|0x01); // 地址,命令
457 1 ucData = DS1302OutputByte(); // 讀1Byte數據
458 1 DS1302_CLK = 1;
459 1 DS1302_RST = 0;
460 1 return(ucData);
461 1 }
462 /*****************************************************************************/
463 //向LCM中填寫 年 數據
464 void LCM_w_yy(void){
465 1 //if(Read1302(0x8d) != yy){
466 1 yy = Read1302(0x8d);
467 1 LCM_WriteDatOrCom(0,0x80);
468 1 LCM_WriteString("20");
469 1 LCM_WriteDatOrCom(0,0x81);
470 1 LCM_WriteDatOrCom(1,(yy/16)+0x30);
471 1 LCM_WriteDatOrCom(1,yy%16+0x30);
472 1 LCM_WriteDatOrCom(0,0x82);
473 1 LCM_WriteString("年");
474 1 nl();
475 1 } //}
476 /*****************************************************************************/
477 //向LCM中填寫 月 數據
478 void LCM_w_mo(void){
479 1 //if(Read1302(0x89) != mo){
480 1 mo = Read1302(0x89);
481 1 LCM_WriteDatOrCom(0,0x83);
482 1 if(mo/16 != 0){LCM_WriteDatOrCom(1,(mo/16)+0x30);} //十位消隱
483 1 else{LCM_WriteDatOrCom(1,0x20);}//同上
484 1 LCM_WriteDatOrCom(1,mo%16+0x30);
485 1 LCM_WriteDatOrCom(0,0x84);
486 1 LCM_WriteString("月");
487 1 nl();
C51 COMPILER V8.08 確農繽確蒧肖 01/25/2009 10:21:59 PAGE 9
488 1 } //}
489 /*****************************************************************************/
490 //星期處理并送入LCM的指定區域
491 void LCM_w_xq(void){
492 1 unsigned char sel;
493 1
494 1 //if(Read1302(0x8b) != xq){
495 1 xq = Read1302(0x8b);
496 1 sel = (Read1302(0x8b))%16; //字節低4位的BCD碼放入sel
497 1 LCM_WriteDatOrCom(0,0x97);//寫入指定區域(97H 第二行第8個字)
498 1 if(sel==7) {LCM_WriteString("日");} //
499 1 if(sel==6) {LCM_WriteString("六");} //
500 1 if(sel==5) {LCM_WriteString("五");} //
501 1 if(sel==4) {LCM_WriteString("四");} //
502 1 if(sel==3) {LCM_WriteDatOrCom(1,0xc8);LCM_WriteDatOrCom(1,0xfd);} //此指令等于LCM_WriteString("三");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -