基于LCM1602液晶、DS1302時(shí)鐘芯片、E2PROM的電子時(shí)鐘設(shè)計(jì)
歷時(shí)一個(gè)下午的功夫!很多地方可以用循環(huán)優(yōu)化的,但基于簡(jiǎn)潔,可讀性好!故使用傳統(tǒng)方法!
By DAVID QQ:1205946980
程序代碼下載:http://www.51hei.com/f/1302eep.rar
#include#define uchar unsigned char#define uint unsigned intuchar code tab1[]="*DAVID*";uchar code tab2[]="Week-";uchar code tab3[]="0123456789";uchar wwe[13];uchar xdw[7]={0x00,0x27,0x22,0x01,0x02,0x03,0x12};sbit LCD_RS=P2^0;sbit LCD_RW=P2^1;sbit LCD_EN=P2^2;sbit E2R_SCK=P2^3;sbit E2R_SDA=P2^4;sbit DS1302_RST=P2^5;sbit DS1302_SCK=P2^6;sbit DS1302_DS=P2^7;sbit HC164_SCK=P1^0;sbit HC164_AB=P1^1;void start_24c02_hs();void stop_24c02_hs();void yingda_24c02_hs();void E2R_inti();uchar du_1byte_24c02_hs();void xie_1byte_24c02_hs(uchar dat);void xie_24c02_hs(uchar add,uchar cmd,uchar dat);uchar du_24c02_hs(uchar add,uchar cmd);void init_du_24c02();void DS1302_xie_1byte(uchar dat);void DS1302_xie_hs(uchar cmd,uchar dat);void DS1302_inti();uchar DS1302_du_hs(uchar cmd);uchar DS1302_du_1buyte();void lcm1602_xie_cmd_hs(uchar cmd);void lcm1602_xie_dat_hs(uchar dat);void lcm1602_init();void delay(uint z);void delaysp(uchar t);void cang();void display();void display_inti();/******************************************************************/void delay(uint z){ uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void delaysp(uchar t){while(t--) ;}void cang(){ uchar seg;seg=DS1302_du_hs(0x81);xdw[0]=seg;wwe[10]=(seg>>4);wwe[11]=(seg&0x0f);seg=DS1302_du_hs(0x83);xdw[1]=seg;wwe[8]=(seg>>4);wwe[9]=(seg&0x0f);seg=DS1302_du_hs(0x85);xdw[2]=seg;wwe[6]=(seg>>4);wwe[7]=(seg&0x0f);seg=DS1302_du_hs(0x87);xdw[3]=seg;wwe[4]=(seg>>4);wwe[5]=(seg&0x0f);seg=DS1302_du_hs(0x89);xdw[4]=seg;wwe[2]=seg>>4;wwe[3]=seg&0x0f;seg=DS1302_du_hs(0x8b);xdw[5]=seg;wwe[12]=seg&0x0f;seg=DS1302_du_hs(0x8d);xdw[6]=seg;wwe[0]=seg>>4;wwe[1]=seg&0x0f;}void display_inti(){uchar i;lcm1602_xie_cmd_hs(0x80+0x00);for(i=0;i<7;i++){lcm1602_xie_dat_hs(tab1[i]);delay(2);}lcm1602_xie_cmd_hs(0x80+0x40);for(i=0;i<5;i++){lcm1602_xie_dat_hs(tab2[i]);delay(2);}}void display(){uchar i,k;lcm1602_xie_cmd_hs(0x80+0x08);for(i=0;i<3;i++){for(k=0;k<2;k++){lcm1602_xie_dat_hs(tab3[wwe[i*2+k]]);}if(i!=2){lcm1602_xie_dat_hs(/);}}lcm1602_xie_cmd_hs(0x80+0x48);for(i=0;i<3;i++){for(k=0;k<2;k++){lcm1602_xie_dat_hs(tab3[wwe[i*2+k+6]]);}if(i!=2){lcm1602_xie_dat_hs(:);}}lcm1602_xie_cmd_hs(0x80+0x45);lcm1602_xie_dat_hs(tab3[wwe[12]]);delay(2);}void lcm1602_xie_cmd_hs(uchar cmd){uchar i,tmp;LCD_RW=0;LCD_RS=0;LCD_EN=1;tmp=cmd;HC164_SCK=0;for(i=0;i<8;i++){HC164_AB=(bit)(tmp&0x01);HC164_SCK=1;HC164_SCK=0;tmp>>=1;}LCD_EN=0;}void lcm1602_xie_dat_hs(uchar dat){uchar i;LCD_RW=0;LCD_RS=1;LCD_EN=1;HC164_SCK=0;for(i=0;i<8;i++){HC164_AB=(bit)(dat&0x01);HC164_SCK=1;HC164_SCK=0;dat>>=1;}LCD_EN=0;}
評(píng)論