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;//減鍵
制作出來的實物圖如下:
51hei圖片_20220615141732.jpg (152.16 KB, 下載次數: 42)
下載附件
2022-6-15 14:32 上傳
單片機源程序如下:
- #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();
- }
復制代碼
51hei.png (11.43 KB, 下載次數: 34)
下載附件
2022-6-15 15:37 上傳
Keil代碼下載:
DS1302時鐘tft液晶顯示.zip
(290.25 KB, 下載次數: 88)
2022-6-15 14:33 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|