新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 12864液晶顯示實時時鐘

12864液晶顯示實時時鐘

作者: 時間:2016-11-29 來源:網(wǎng)絡(luò) 收藏
/**********************12864寫指令*****************************/void write_com(uchar com){check_busy();RS=0;RW=0;EN=1;P0=com;DelayUs2x(250);EN=0;DelayUs2x(250);}/**********************12864寫數(shù)據(jù)*****************************/void write_data(uchar dat){check_busy();RS=1;RW=0;EN=1;P0=dat;DelayUs2x(250);EN=0;DelayUs2x(250);}/**********************12864初始化函數(shù)*****************************/void init(){ DelayMs(40); //大于40MS的延時程序PSB=1; //設(shè)置為8BIT并口工作模式DelayMs(1); //延時RET=0; //復(fù)位DelayMs(1); //延時RET=1; //復(fù)位置高DelayMs(200);write_com(0x30); //選擇基本指令集DelayUs2x(250); //延時大于100uswrite_com(0x30); //選擇8bit數(shù)據(jù)流DelayUs2x(200); //延時大于37uswrite_com(0x0c); //開顯示(無游標、不反白)DelayUs2x(250); //延時大于100uswrite_com(0x01); //清除顯示,并且設(shè)定地址指針為00HDelayMs(200); //延時大于10mswrite_com(0x06); //指定在資料的讀取及寫入時,設(shè)定游標的移動方向及指定顯示的移位,光標從右向左加1位移動DelayUs2x(250); //延時大于100us}/**********************清屏*****************************/void clrscreen(){write_com(0x01);DelayMs(15);}/*********************************************************主函數(shù)********************************************************/void main(){ uchar sec,sec1,sec2;uchar min,min1,min2;uchar hour,hour1,hour2;uchar date,date1,date2;uchar mon,mon1,mon2;uchar day;uchar year,year1,year2;uchar table1[]="年月日時分秒星期溫度攝氏"; //長度24uchar table2[]={0XD2,0XBB, 0XB6,0XFE, 0XC8,0XFD, 0XCB,0XC4, 0XCE,0XE5,0XCE,0XF9, 0XC8,0XD5}; //長度14uchar table3[]="0123456789"; //長度10init(); //液晶初始化clrscreen();DelayMs(200);init_1302(); //1302初始化 只初始化一下就可以 需要下載兩次DelayMs(50);write_com(0x80); //顯示20write_data(2);write_data(0);write_com(0x82); //顯示年write_data(table1[0]);write_data(table1[1]);write_com(0x84); //顯示月write_data(table1[2]);write_data(table1[3]);write_com(0x86); //顯示日write_data(table1[4]);write_data(table1[5]);write_com(0x91); //顯示時write_data(table1[6]);write_data(table1[7]);write_com(0x93); //顯示分write_data(table1[8]);write_data(table1[9]);write_com(0x95); //顯示秒write_data(table1[10]);write_data(table1[11]);write_com(0x88); //顯示星期write_data(table1[12]);write_data(table1[13]); write_data(table1[14]);write_data(table1[15]);while(1){ sec=Read_DS1302(0x81); ////讀秒sec1=sec&0x0f; //個位sec2=sec>>4; //十位min=Read_DS1302(0x83); ////讀分min1=min&0x0f; //個位min2=min>>4; //十位hour=Read_DS1302(0x85); ////讀時hour1=hour&0x0f; //個位hour2=hour>>4; //十位date=Read_DS1302(0x87); ////讀日date1=date&0x0f; //個位date2=date>>4; //十位mon=Read_DS1302(0x89); ////讀月mon1=mon&0x0f; //個位mon2=mon>>4; //十位year=Read_DS1302(0x8d); ////讀年year1=year&0x0f; //個位year2=year>>4; //十位day=Read_DS1302(0x8b); ////讀星期write_com(0x94); //送顯示內(nèi)容write_data(table3[sec2]); //秒 write_data(table3[sec1]); write_com(0x92);write_data(table3[min2]); //分write_data(table3[min1]);write_com(0x90);write_data(table3[hour2]); //時write_data(table3[hour1]);write_com(0x85);write_data(table3[date2]); //日write_data(table3[date1]); write_com(0x83);write_data(table3[mon2]); //月write_data(table3[mon1]);write_com(0x81);write_data(table3[year2]); //年write_data(table3[year1]);write_com(0x8a);write_data(table2[2*day-2]); //星期write_data(table2[2*day-1]);}}
上一頁 1 2 下一頁

關(guān)鍵詞: 12864液晶顯示實時時

評論


技術(shù)專區(qū)

關(guān)閉