|
基于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(" 只怕自己投降 ");
- // }
- //
复制代码
时间 和励志标语 可在基础上进行更改
|
|