TFT1.44液晶显示万年
可按键调时,调节时被选中的项显示蓝色底色,星期是自动计算的,不用调节;DS1302加备用电池,掉电继续走时
MCU=STC12C5A60S2
接线说明:
sbit LCD_SCL =P1^7;//接模块CLK引脚,接裸屏Pin9_SCL
sbit LCD_SDA =P1^5;//接模块DIN/MOSI引脚,接裸屏Pin8_SDA
sbit LCD_DC =P3^6;//接模块D/C引脚,接裸屏Pin7_A0 RS
sbit LCD_CS =P3^7;//接模块CE引脚,接裸屏Pin12_CS
sbit LCD_RST =P3^4;//接模块RST引脚,接裸屏Pin6_RES
//---------------------------End of液晶屏接线---------------------------------//
sbit TSCLK = P1^0;//时钟线 接到P10上用杜邦线
sbit TIO = P1^1;//数据线,接到P11上
sbit TRST = P1^2;//使能端,接到P12上
sbit DS18B20_IO = P2^2; //DS18B20通信引脚
sbit key1=P3^3;//调时选项键
sbit key2=P3^1;//加键
sbit key3=P3^2;//减键
制作出来的实物图如下:
单片机源程序如下:
- #include "config.h"
- #include "DS1302.H"
- #include "TFT144_ST7735.h"
- #include "ds18b20.h"
- #include "nongli.h"
- //bit debug_flag = 0; //debug mode = 1, uart printf enable
- bit timer_flag_250ms = 0; //250ms定时触发标志位
- bit timer_flag_1s = 0; //1s定时触发标志位
- bit timer_flag_2s = 0; //2s定时触发标志位
- bit timer_flag_5s = 0; //5s定时触发标志位
- sbit key1=P3^3;
- sbit key2=P3^1;
- sbit key3=P3^2;
- bit lock1,lock2,lock3;
- uint8 cont1,cont2,cont3,set_num;
- uint8 T0RH = 0; //T0重载值的高字节
- uint8 T0RL = 0; //T0重载值的低字节
- void Timer0Init(void); //10毫秒@11.0592MHz
- void ReadAndShowRtc();
- void ReadAndShowTemperature(int8 comp);
- /////////////////////////////////////
- void LCD_Show_Format() //固定显示内容
- {
- Display_Pure_Color(COLOR_BLACK);//背景色
- // Display_Pure_Color(COLOR_LIGHT_BLUE); //背景色
- // YYYY-MM-DD
- Display_Digit_12x16(4+0, 4, COLOR_SILVER, COLOR_BLACK, 2); //2
- Display_Digit_12x16(4+12, 4, COLOR_SILVER, COLOR_BLACK, 0); //0
- // Display_Digit_12x16(4+24, 4, COLOR_SILVER, COLOR_BLACK, 2); //2
- // Display_Digit_12x16(4+36, 4, COLOR_SILVER, COLOR_BLACK, 2); //2
- Display_Digit_12x16(4+48, 4, COLOR_SILVER, COLOR_BLACK, 10); //-
- // Display_Digit_12x16(4+60, 4, COLOR_SILVER, COLOR_BLACK, 0); //0
- // Display_Digit_12x16(4+72, 4, COLOR_SILVER, COLOR_BLACK, 6); //6
- Display_Digit_12x16(4+84, 4, COLOR_SILVER, COLOR_BLACK, 10); //-
- // Display_Digit_12x16(4+96, 4, COLOR_SILVER, COLOR_BLACK, 0); //0
- // Display_Digit_12x16(4+108, 4, COLOR_SILVER, COLOR_BLACK, 8); //8
- // 星期三
- Display_HZ_16x16(0,24, COLOR_SILVER, COLOR_BLACK, 0); //星
- Display_HZ_16x16(16,24, COLOR_SILVER, COLOR_BLACK, 1); //期
- // Display_HZ_16x16(32,24, COLOR_SILVER, COLOR_BLACK, 4); //三
- // HH:MI:SS
- // Display_Digit_24x48(0, 44, COLOR_YELLOW_GREEN, COLOR_BLACK, 1);
- // Display_Digit_24x48(24, 44, COLOR_YELLOW_GREEN, COLOR_BLACK, 2);
- Display_Digit_24x48(48, 44, COLOR_YELLOW_GREEN, COLOR_BLACK, 10);//冒号
- // Display_Digit_24x48(72, 44, COLOR_YELLOW_GREEN, COLOR_BLACK, 2);
- // Display_Digit_24x48(96, 44, COLOR_YELLOW_GREEN, COLOR_BLACK, 1);
- // 25.0℃
- // Display_Digit_12x24(0, 100, COLOR_LIGHT_BLUE, COLOR_BLACK, 2); //2
- // Display_Digit_12x24(12, 100, COLOR_LIGHT_BLUE, COLOR_BLACK, 5); //5
- Display_Digit_12x24(24, 100, COLOR_LIGHT_BLUE, COLOR_BLACK, 12); //.
- // Display_Digit_12x24(36, 100, COLOR_LIGHT_BLUE, COLOR_BLACK, 0); //0
- Display_Digit_16x24(48, 100, COLOR_LIGHT_BLUE, COLOR_BLACK, 13); //℃
- }
- ///////////////////////////
- void keyscan() //按键扫描
- {
- uchar minute,hour,day,month,year;
- year=BCD_Chg_Dat(read_1302(read_nian));
- month=BCD_Chg_Dat(read_1302(read_yue));
- day=BCD_Chg_Dat(read_1302(read_ri));
- hour=BCD_Chg_Dat(read_1302(read_shi));
- minute=BCD_Chg_Dat(read_1302(read_fen));
- if(key1)
- {
- lock1=0;
- cont1=0;
- }
- else if(lock1==0)
- {
- cont1++;
- if(cont1>10)
- {
- cont1=0;
- lock1=1;
- set_num++;
- if(set_num==1)
- {
- write_1302(0x8e, 0x00); //撤销写保护以允许写入数据
- write_1302(write_miao,0x80); //写秒80,时钟停止走时;
- }
- if(set_num==6) //调时完毕,时钟启动
- {
- set_num=0;
- write_1302(write_miao,0x00); //写秒0,时钟启动走时
- write_1302(0x8e,0x80); //保护启动
- }
- }
- }
- if(key2)
- {
- lock2=0;
- cont2=0;
- }
- else if(lock2==0) //短按 加
- {
- cont2++;
- if(cont2>10)
- {
- cont2=0;
- lock2=1;
- switch(set_num)
- {
-
- case 1: year++;
- if(year==99)
- year=21;
- write_1302(write_nian,Dat_Chg_BCD(year)); //写年
- break;
- case 2: month++;
- if(month==13)
- month=1;
- if(month==2 && day>28){day=28;write_1302(write_ri,Dat_Chg_BCD(day));}
- write_1302(write_yue,Dat_Chg_BCD(month)); //写月
- break;
- //公历闰年遵循的规律为: 四年一闰,百年不闰,四百年再闰
- case 3: day++; //if((year % 400 == 0)||(year % 4 == 0)&&(year % 100 != 0))闰年的计算方法
- if((month==2&&year%4!=0)&&day>28) day=1;//平年2月28天
- if((month==2&&year%4==0)&&day>29) day=1;//闰年2月29天
- if((month==1 || month==3 ||month==5 ||month==7 ||month==8 ||month==10 || month==12)&&day>31)day=1;//31天的月份
- if((month==4 || month==6 ||month==9 ||month==11)&&day>30 )day=1;//30天的月份
- write_1302(write_ri,Dat_Chg_BCD(day)); //写日
- break;
- case 4: hour++;
- if(hour==24)
- hour=0;
- write_1302(write_shi,Dat_Chg_BCD(hour)); //写小时
- break;
- case 5: minute++;
- if(minute==59)
- minute=0;
- write_1302(write_fen,Dat_Chg_BCD(minute)); //写分钟
- break;
-
- }
- }
- }
- else if(cont2<100) //长按 连加
- {
- cont2++;
- if(cont2==100)
- {
- cont2=70;
- switch(set_num)
- {
- case 1: year++;
- if(year==99)
- year=21;
- write_1302(write_nian,Dat_Chg_BCD(year)); //写年
- break;
- case 2: month++;
- if(month==13)
- month=1;
- if(month==2 && day>28){day=28;write_1302(write_ri,Dat_Chg_BCD(day));}
- write_1302(write_yue,Dat_Chg_BCD(month)); //写月
- break;
- case 3: day++;
- if((month==2&&year%4!=0)&&day>28) day=1;//平年2月28天
- if((month==2&&year%4==0)&&day>29) day=1;//闰年2月29天
- if((month==1 || month==3 ||month==5 ||month==7 ||month==8 ||month==10 || month==12)&&day>31)day=1;
- if((month==4 || month==6 ||month==9 ||month==11)&&day>30 )day=1;
- write_1302(write_ri,Dat_Chg_BCD(day)); //写日
- break;
- case 4: hour++;
- if(hour==24)
- hour=0;
- write_1302(write_shi,Dat_Chg_BCD(hour)); //写小时
- break;
- case 5: minute++;
- if(minute==59)
- minute=0;
- write_1302(write_fen,Dat_Chg_BCD(minute)); //写分钟
- break;
- }
-
- }
-
- }
- ///////////////////////////////
- if(key3)
- {
- lock3=0;
- cont3=0;
- }
- else if(lock3==0)//短按 减
- {
- cont3++;
- if(cont3>10)
- {
- cont3=0;
- lock3=1;
- switch(set_num)
- {
- case 1: year--;
- if(year==21)
- year=99;
- write_1302(write_nian,Dat_Chg_BCD(year)); //写年
- break;
- case 2: month--;
- if(month==0)
- month=12;
- if(month==2 && day>28){day=28;write_1302(write_ri,Dat_Chg_BCD(day));}
- write_1302(write_yue,Dat_Chg_BCD(month)); //写月
- break;
- case 3: day--;
- if((month==2&&year%4!=0)&&day==0) day=28;//平年2月28天
- if((month==2&&year%4==0)&&day==0) day=29;//闰年2月29天
- if((month==1 || month==3 ||month==5 ||month==7 ||month==8 ||month==10 || month==12)&&day==0)day=31;
- if((month==4 || month==6 ||month==9 ||month==11)&&day==0 )day=30;
- write_1302(write_ri,Dat_Chg_BCD(day)); //写日
- break;
- case 4: hour--;
- if(hour==255)
- hour=23;
- write_1302(write_shi,Dat_Chg_BCD(hour)); //写小时
- break;
- case 5: minute--;
- if(minute==255)
- minute=59;
- write_1302(write_fen,Dat_Chg_BCD(minute)); //写分钟
- break;
- }
- }
- }
- else if(cont3<100) //长按 连减
- {
- cont3++;
- if(cont3==100)
- {
- cont3=70;
- switch(set_num)
- {
- case 1: year--;
- if(year==21)
- year=99;
- write_1302(write_nian,Dat_Chg_BCD(year)); //写年
- break;
- case 2: month--;
- if(month==0)
- month=12;
- if(month==2 && day>28){day=28;write_1302(write_ri,Dat_Chg_BCD(day));}
- write_1302(write_yue,Dat_Chg_BCD(month)); //写月
- break;
- case 3: day--;
- if((month==2&&year%4!=0)&&day==0) day=28;//平年2月28天
- if((month==2&&year%4==0)&&day==0) day=29;//闰年2月29天
- if((month==1 || month==3 ||month==5 ||month==7 ||month==8 ||month==10 || month==12)&&day==0)day=31;
- if((month==4 || month==6 ||month==9 ||month==11)&&day==0 )day=30;
- write_1302(write_ri,Dat_Chg_BCD(day)); //写日
- break;
- case 4: hour--;
- if(hour==255)
- hour=23;
- write_1302(write_shi,Dat_Chg_BCD(hour)); //写小时
- break;
- case 5: minute--;
- if(minute==255)
- minute=59;
- write_1302(write_fen,Dat_Chg_BCD(minute)); //写分钟
- break;
- }
- }
- }
- }
- /////////////////////////
- /*显示农历日期---------------------------------------------------------------*/
- void displaynl(void)
- {
- nian=read_1302(read_nian);
- yue=read_1302(read_yue);
- ri=read_1302(read_ri);
- Conversion(0,nian,yue,ri); //公历转农历
- if (month_moon==1) {Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 15);}//正
- if (month_moon==2) {Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 3);} //二
- if (month_moon==3) {Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 4);} //三
- if (month_moon==4) {Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 5);} //四
- if (month_moon==5) {Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 6);} //五
- if (month_moon==6) {Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 7);} //六
- if (month_moon==7) {Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 9);} //七
- if (month_moon==8) {Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 10);}//八
- if (month_moon==9) {Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 11);}//九
- if (month_moon==10){Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 12);}//十
- if (month_moon==11){Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 13);}//冬
- if (month_moon==12){Display_HZ_16x16(64,24, COLOR_SILVER, COLOR_BLACK, 14);}//腊
- Display_HZ_16x16(80,24, COLOR_SILVER, COLOR_BLACK, 16); //显示“月”字
- if (day_moon==1)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 2);//一
- }
- if (day_moon==2)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 3);//二
- }
- if (day_moon==3)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 4);//三
- }
- if (day_moon==4)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 5);//四
- }
- if (day_moon==5)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 6);//五
- }
- if (day_moon==6)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 7);//六
- }
- if (day_moon==7)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 9);//七
- }
- if (day_moon==8)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 10);//八
- }
- if (day_moon==9)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 11);//九
- }
- if (day_moon==10)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 17);//初
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- }
- if (day_moon==11)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 2);//一
- }
- if (day_moon==12)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 3);//二
- }
- if (day_moon==13)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 4);//三
- }
- if (day_moon==14)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 5);//四
- }
- if (day_moon==15)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 6);//五
- }
- if (day_moon==16)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 7);//六
- }
- if (day_moon==17)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 9);//七
- }
- if (day_moon==18)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 10);//八
- }
- if (day_moon==19)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 11);//九
- }
- if (day_moon==20)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 3);//二
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- }
- if (day_moon==21)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 18);//廿
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 2);//一
- }
- if (day_moon==22)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 18);//廿
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 3);//二
- }
- if (day_moon==23)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 18);//廿
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 4);//三
- }
- if (day_moon==24)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 18);//廿
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 5);//四
- }
- if (day_moon==25)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 18);//廿
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 6);//五
- }
- if (day_moon==26)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 18);//廿
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 7);//六
- }
- if (day_moon==27)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 18);//廿
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 9);//七
- }
- if (day_moon==28)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 18);//廿
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 10);//八
- }
- if (day_moon==29)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 18);//廿
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 11);//九
- }
- if (day_moon==30)
- {
- Display_HZ_16x16(96,24, COLOR_SILVER, COLOR_BLACK, 4);//三
- Display_HZ_16x16(112,24, COLOR_SILVER, COLOR_BLACK, 12);//十
- }
- }
- ////////////////////////////
-
- void displayxq(void) //显示星期
- {
- unsigned char sel,dd,mo,yy;
- dd = read_1302(read_ri);//日
- mo = read_1302(read_yue);//月
- yy = read_1302(read_nian);//年
- Conver_week(0,yy,mo,dd);//调用公历换算星期子函数
- sel=week;//week是公历转换星期子函数的运行结果,结果为0-6,0是星期日
- if(sel==0) {Display_HZ_16x16(32,24, COLOR_SILVER, COLOR_BLACK, 8);} //0=星期日
- if(sel==6) {Display_HZ_16x16(32,24, COLOR_SILVER, COLOR_BLACK, 7);} //
- if(sel==5) {Display_HZ_16x16(32,24, COLOR_SILVER, COLOR_BLACK, 6);} //
- if(sel==4) {Display_HZ_16x16(32,24, COLOR_SILVER, COLOR_BLACK, 5);} //
- if(sel==3) {Display_HZ_16x16(32,24, COLOR_SILVER, COLOR_BLACK, 4);} //
- if(sel==2) {Display_HZ_16x16(32,24, COLOR_SILVER, COLOR_BLACK, 3);} //
- if(sel==1) {Display_HZ_16x16(32,24, COLOR_SILVER, COLOR_BLACK, 2);} //星期一
- }
-
- /////////////////////////
- void main()
- {
- int8 slen = 0;
- uint8 pdata uart_cmd_buf[64] = {0};
- DS18B20_Start();
- Timer0Init(); //T0定时10ms
- DS1302_Init(); //初始化RTC时钟
- /*
- #ifdef MCU_STC12
- //P3.2 set as push-pull output mode, for LCD backlight
- P3M1 &= ~(1<<2);
- P3M0 |= (1<<2);
- #endif */
- SPI_Init();
- LCD_Init();
- delay_ms(500);
- LCD_Show_Format();
- while(1)
- {
- if (timer_flag_250ms) //每250ms读取一次时间
- {
- ReadAndShowRtc();
- displaynl();
- displayxq();
- timer_flag_250ms = 0;
- }
- if (timer_flag_5s) //每隔5s执行以下分支
- {
- ReadAndShowTemperature(-5);
-
- timer_flag_5s = 0;
- }
- }
- }
- void ReadAndShowRtc() //读rtc并显示
- {
- read_rtc();
- if(set_num==1)
- {
- Display_Digit_12x16(4+24, 4, COLOR_SILVER, COLOR_BLUE, nian/10);
- Display_Digit_12x16(4+36, 4, COLOR_SILVER, COLOR_BLUE, nian%10);
- }
- else
- {
- Display_Digit_12x16(4+24, 4, COLOR_SILVER, COLOR_BLACK, nian/10);
- Display_Digit_12x16(4+36, 4, COLOR_SILVER, COLOR_BLACK, nian%10);
- }
- if(set_num==2)
- {
- Display_Digit_12x16(4+60, 4, COLOR_SILVER, COLOR_BLUE, yue/10);
- Display_Digit_12x16(4+72, 4, COLOR_SILVER, COLOR_BLUE, yue%10);
- }
- else
- {
- Display_Digit_12x16(4+60, 4, COLOR_SILVER, COLOR_BLACK, yue/10);
- Display_Digit_12x16(4+72, 4, COLOR_SILVER, COLOR_BLACK, yue%10);
- }
- if(set_num==3)
- {
- Display_Digit_12x16(4+96, 4, COLOR_SILVER, COLOR_BLUE, ri/10);
- Display_Digit_12x16(4+108, 4, COLOR_SILVER, COLOR_BLUE, ri%10);
- }
- else
- {
- Display_Digit_12x16(4+96, 4, COLOR_SILVER, COLOR_BLACK, ri/10);
- Display_Digit_12x16(4+108, 4, COLOR_SILVER, COLOR_BLACK, ri%10);
-
- }
- if(set_num==4)
- {
- Display_Digit_24x48(0, 44, COLOR_YELLOW_GREEN, COLOR_BLUE, shi /10);
- Display_Digit_24x48(24, 44, COLOR_YELLOW_GREEN, COLOR_BLUE, shi %10);
- }
- else
- {
- Display_Digit_24x48(0, 44, COLOR_YELLOW_GREEN, COLOR_BLACK, shi /10);
- Display_Digit_24x48(24, 44, COLOR_YELLOW_GREEN, COLOR_BLACK, shi %10);
-
- }
-
- if(set_num==5)
- {
- Display_Digit_24x48(72, 44, COLOR_YELLOW_GREEN, COLOR_BLUE, fen /10);
- Display_Digit_24x48(96, 44, COLOR_YELLOW_GREEN, COLOR_BLUE, fen %10);
- }
- else
- {
- Display_Digit_24x48(72, 44, COLOR_YELLOW_GREEN, COLOR_BLACK, fen /10);
- Display_Digit_24x48(96, 44, COLOR_YELLOW_GREEN, COLOR_BLACK, fen %10);
- }
- Display_Digit_12x24(100,100, COLOR_RED, COLOR_BLACK, miao /10); // 秒
- Display_Digit_12x24(100+12,100, COLOR_RED, COLOR_BLACK, miao %10); //秒
- // 字颜色 底色
- }
-
- void ReadAndShowTemperature(int8 comp)
- {
- int8 slen = 0, n = 0;
- static uint8 pdata sbuf[5+1] = {' ', ' ', ' ', '.', ' ', 0};
- uint16 tmp_n = 0;
- // DS18B20的小数位四舍五入显示结果速查表,4bit=索引取值范围 0 - 15
- uint8 code dect_lookup_tab[] = {0, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 9};
- if(DS18B20_Get_Temperature(&ds18b20_temp_r, &ds18b20_temp_sign_r))
- {
- //ds18b20_temp_r = ds18b20_temp_r * 10 * 0.0625 + 0.5;
-
- if(ds18b20_temp_r != ds18b20_temp_s || ds18b20_temp_sign_r != ds18b20_temp_sign_s)
- {
- int8 intT = ds18b20_temp_r >> 4; //分离出温度值整数部分
- int8 decT = ds18b20_temp_r & 0x0F; //分离出温度值小数部分,DS18B20的小数位一共4bit,乘以0.625(也就是10/16)后对0.5作四舍五入可以得到比较精确的数值
-
- // if(1 == debug_flag) printf(">raw:intT.decT = (%c)%bd.%bd\r\n", ds18b20_temp_sign_r > 0 ? '+' : '-', intT, dect_lookup_tab[decT]);
- //针对个体DS18B20模块,进行温度补偿处理,减少显示温度与实际温度误差
- tmp_n = 10 * intT + dect_lookup_tab[decT];
- tmp_n += (ds18b20_temp_sign_r > 0 ? comp : -comp);
- intT = tmp_n / 10;
- decT = tmp_n % 10;
-
- // 在液晶屏上显示温度
- if(ds18b20_temp_sign_r >= 0 && ' ' != sbuf[0])
- {
- sbuf[0] = ' ';
- Display_Digit_12x24(22+0, 100, COLOR_BLACK, COLOR_BLACK, 10);
- }
- else if(ds18b20_temp_sign_r < 0 && '-' != sbuf[0])
- {
- sbuf[0] = '-';
- Display_Digit_12x24(22+0, 100, COLOR_LIGHT_BLUE, COLOR_BLACK, 10);
- }
-
- n = intT / 10;
- if('0' + n != sbuf[1])
- {
- sbuf[1] = '0' + n;
- Display_Digit_12x24(0, 100, COLOR_LIGHT_BLUE, COLOR_BLACK, n);
- }
- n = intT % 10;
- if('0' + n != sbuf[2])
- {
- sbuf[2] = '0' + n;
- Display_Digit_12x24(12, 100, COLOR_LIGHT_BLUE, COLOR_BLACK, n);
- }
- n = decT;
- if('0' + n != sbuf[4])
- {
- sbuf[4] = '0' + n;
- Display_Digit_12x24(36, 100, COLOR_LIGHT_BLUE, COLOR_BLACK, n);
- }
-
- ds18b20_temp_s = ds18b20_temp_r;
- ds18b20_temp_sign_s = ds18b20_temp_sign_r;
- }
- }
- DS18B20_Start(); // 重新启动下一次转换
- }
- void Timer0Init(void) //10毫秒@11.0592MHz
- {
- AUXR &= 0x7F; //定时器时钟12T模式
- TMOD &= 0xF0; //设置定时器模式
- TMOD |= 0x01; //配置T0为模式1
- T0RH = 0xDC; //T0重载值的高字节
- T0RL = 0x00; //T0重载值的低字节
- TH0 = T0RH; //设置定时初值
- TL0 = T0RL; //设置定时初值
- ET0 = 1; //使能T0中断
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- EA = 1;
- }
- /* T0中断服务函数,实现系统定时处理 */
- void Timer0_Interrupt_Service() interrupt 1
- {
- static uint8 pdata tmr1s = 0;
- static uint8 pdata tmr2s = 0;
- static uint8 pdata tmr5s = 0;
- static uint8 pdata tmr250ms = 0;
-
- TH0 = T0RH; //重新加载重载值
- TL0 = T0RL;
- tmr250ms++; //定时250ms
- if (tmr250ms >= 250/TIMER0_SLICE_MS)
- {
- tmr250ms = 0;
- timer_flag_250ms = 1;
- tmr1s++; //定时1s
- if (tmr1s >= 4)
- {
- tmr1s = 0;
- timer_flag_1s = 1;
- tmr2s++; //定时2s
- tmr5s++; //定时5s
- }
- if (tmr2s >= 2)
- {
- tmr2s = 0;
- timer_flag_2s = 1;
- }
- if (tmr5s >= 5)
- {
- tmr5s = 0;
- timer_flag_5s = 1;
- }
- }
- keyscan();
- }
复制代码
Keil代码下载:
DS1302时钟tft液晶显示.zip
(290.25 KB, 下载次数: 88)
|