📄 带农历带生肖.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 + -