12864液晶顯示實(shí)時(shí)時(shí)鐘
下面是一段12864液晶顯示實(shí)時(shí)時(shí)鐘的程序:
本文引用地址:http://m.butianyuan.cn/article/201611/323551.htm/***************************************************************************************時(shí)間:2012.11.30晶振:11.0592MHz芯片:STC89C52RC功能描述:在12864上顯示年、月、日、星期、時(shí)、分和秒等時(shí)間信息***************************************************************************************/ #include#define uchar unsigned charsbit CLK=P1^4; //DS1302引腳定義sbit IO=P1^5;sbit CE=P1^6;sbit ACC0=ACC^0;sbit ACC7=ACC^7;sbit RS=P2^4; //12864引腳定義 數(shù)據(jù)口為P0sbit RW=P2^5;sbit EN=P2^6;sbit PSB=P2^1;sbit RET=P2^3;void Input_1byte(uchar TD) //DS1302輸入一字節(jié)數(shù)據(jù){uchar i;ACC=TD;for(i=8;i>0;i--){IO=ACC0;CLK=1;CLK=0;ACC=ACC>>1;}}uchar Output_1byte(void) //DS1302輸出一字節(jié)數(shù)據(jù){uchar i;for(i=8;i>0;i--){ACC=ACC>>1;ACC7=IO;CLK=1;CLK=0;}return(ACC);}void Write_DS1302(uchar add,uchar dat)//向DS1302寫{CE=0;CLK=0;CE=1;Input_1byte(add);Input_1byte(dat);CE=0;}uchar Read_DS1302(uchar add) //從DS1302讀{uchar inf; //信息臨時(shí)存儲(chǔ)變量CE=0;CLK=0;CE=1;Input_1byte(add);inf=Output_1byte();CE=0;return(inf);}/**********************DS1302初始化*****************************/void init_1302(){if(Read_DS1302(0xd1)==0x55) //判斷內(nèi)存單元的內(nèi)容,是否進(jìn)行初始化{ return; } else {Write_DS1302(0x8e,0x00); //關(guān)閉寫保護(hù)Write_DS1302(0x90,0x00); //電池充電設(shè)置Write_DS1302(0x80,0x00); //秒Write_DS1302(0x82,0x54); //分Write_DS1302(0x84,0x20); //時(shí)Write_DS1302(0x86,0x30); //日Write_DS1302(0x88,0x11); //月Write_DS1302(0x8a,0x05); //星期Write_DS1302(0x8c,0x12); //年Write_DS1302(0xd0,0x55); //寫RAMWrite_DS1302(0x8e,0x80); //打開寫保護(hù) }}/**********************延時(shí)函數(shù)*****************************/void DelayUs2x(unsigned char t){ while(--t);}void DelayMs(unsigned char t){while(t--){//大致延時(shí)1mSDelayUs2x(245);DelayUs2x(245);}}/**********************12864判忙*****************************/void check_busy(){RS=0;RW=1;EN=1;while((P0&0x80)==0x80);EN=0;}
評(píng)論