|
基于51單片機 led 12864的顯示器 顯示當前時間 和 距離高考小白第一個項目 望大神指點 多多指教
- #include <reg51.h>
- #include "lcd12864.h"
- #include "string.h"
- #include "stdio.h"
- #include "uart.h"
- #include "main.h"
- #include "ds1302.h"
- unsigned int i = 0;
- //當前時間
- extern uint now_year,now_month,now_date,now_hour,now_min,now_sec;
- //倒計時時間
- extern int days;
- extern int hours;
- extern int mins;
- extern int secs;
- uchar temp[10] = {0};
- //獲取個位數并轉換為字符類型
- uchar get_ge(uint c){
- uchar ge = c%10;
- ge = ge+48;
- return ge;
- }
- //獲取百位數并轉換為字符類型
- uchar get_shi(uint c){
- uchar ge = c%100/10;
- ge = ge+48;
- return ge;
- }
- //獲取十位數并轉換為字符類型
- uchar get_bai(uint c){
- uchar ge = c%1000/100;
- ge = ge+48;
- return ge;
- }
- void to_str(uint c,uchar* content,uint length){
-
- if(length == 1){
- *content = ' ';
- *(content+1) = get_ge(c);
- *(content+2) = '\0';
- }
- else if(length == 2){
- *(content) = get_shi(c);
- *(content+1) = get_ge(c);
- *(content+2) = '\0';
- }
- else if(length == 3){
- *content = ' ';
- *(content+1) = get_bai(c);
- *(content+2) = get_shi(c);
- *(content+3) = get_ge(c);
- *(content+4) = '\0';
- }
- }
- void add_str(char* p){
- while(*p !='\0')
- {
- LCD12864_WriteData(*p);
- p++;
- }
- }
- //刷新顯示界面
- void refresh(){
- //LCD12864_ClearScreen();//清屏有BUG
- LCD12864_SetWindow(0, 0);
- add_str("當前時間");
- to_str(now_hour,temp,2);
- add_str(temp);
- add_str("時");
- to_str(now_min,temp,2);
- add_str(temp);
- add_str("分");
- LCD12864_SetWindow(1,0);
- add_str(" 距離高考還有 ");
- LCD12864_SetWindow(2,0);
- if(days < 10){
- to_str(days,temp,1);
- }else if(days >= 10 && days < 100){
- to_str(days,temp,2);
- }else{
- to_str(days,temp,3);
- }
- to_str(days,temp,3);
- add_str(temp);
- add_str("天");
- LCD12864_SetWindow(2,3);
- to_str(hours,temp,2);
- add_str(temp);
- add_str("時");
- to_str(mins,temp,2);
- add_str(temp);
- add_str("分");
- to_str(secs,temp,2);
- add_str(temp);
- LCD12864_SetWindow(3,0);
- add_str("你還年輕你怕什么");
- // if (days==127&& now_hour ==8&& now_min <=5){
- // TR0=0;
- // LCD12864_SetWindow(0, 0);
- // add_str("擼起袖子加油干 ");
- // LCD12864_SetWindow(1, 0);
- // add_str(" ");
- // LCD12864_SetWindow(2, 0);
- // add_str(" ");
- // LCD12864_SetWindow(3, 0);
- // add_str(" 謝顯山");
- // }
- //// if ( days ==138&&now_hour ==15 && now_min <=5){
- // TR0=0;
- // LCD12864_SetWindow(0, 0);
- // add_str("人生最大的痛苦是");
- // LCD12864_SetWindow(1, 0);
- // add_str("夢醒了無路可走 ");
- // LCD12864_SetWindow(2, 0);
- // add_str(" 不怕萬人阻擋 ");
- // LCD12864_SetWindow(3, 0);
- // add_str(" 只怕自己投降 ");
- // }
- //
復制代碼
時間 和勵志標語 可在基礎上進行更改
|
|