基于LCM1602液晶、DS1302時鐘芯片、E2PROM的電子時鐘設計 作者: 時間:2016-11-29 來源:網(wǎng)絡 加入技術交流群 掃碼加入和技術大咖面對面交流海量資料庫查詢 收藏 void lcm1602_init(){LCD_RW=0;LCD_RS=0;LCD_EN=0;lcm1602_xie_cmd_hs(0x38);lcm1602_xie_cmd_hs(0x0c);lcm1602_xie_cmd_hs(0x06);}/*************************ds1302*******************************************************/void DS1302_xie_1byte(uchar dat){uchar i;for(i=0;i<8;i++){DS1302_DS=(bit)(dat&0x01);DS1302_SCK=1;DS1302_SCK=0;dat>>=1;}}uchar DS1302_du_1buyte(){uchar i,num;for(i=0;i<8;i++){num>>=1;if(DS1302_DS)num|=0x80;DS1302_SCK=1;DS1302_SCK=0;}return(num);}void DS1302_xie_hs(uchar cmd,uchar dat){DS1302_RST=0;DS1302_SCK=0;DS1302_RST=1;DS1302_xie_1byte(cmd);DS1302_xie_1byte(dat);DS1302_SCK=1;DS1302_RST=0;} uchar DS1302_du_hs(uchar cmd){uchar tmp;DS1302_RST=0;DS1302_SCK=0;DS1302_RST=1;DS1302_xie_1byte(cmd);tmp=DS1302_du_1buyte();DS1302_SCK=1;DS1302_RST=0;return(tmp);}void DS1302_inti(){DS1302_RST=0;DS1302_SCK=0;DS1302_xie_hs(0x8e,0x00);DS1302_xie_hs(0x80,xdw[0]);DS1302_xie_hs(0x82,xdw[1]);DS1302_xie_hs(0x84,xdw[2]);DS1302_xie_hs(0x86,xdw[3]);DS1302_xie_hs(0x88,xdw[4]);DS1302_xie_hs(0x8a,xdw[5]);DS1302_xie_hs(0x8c,xdw[6]);DS1302_xie_hs(0x8e,0x80);}/*************************24c02*******************************************************/void start_24c02_hs(){E2R_SCK=1;delaysp(1);E2R_SDA=1;delaysp(1);E2R_SDA=0;delaysp(1);}void stop_24c02_hs(){E2R_SDA=0;delaysp(1);E2R_SCK=1;delaysp(1);E2R_SDA=1;delaysp(1);}void yingda_24c02_hs(){uchar i;E2R_SCK=1;E2R_SDA=1;delaysp(1);while((E2R_SDA==1)||(i<220)){i++;} E2R_SCK=0;delaysp(1);}void E2R_inti(){E2R_SCK=1;E2R_SDA=1;}uchar du_1byte_24c02_hs(){uchar i,num;E2R_SCK=0;delaysp(1);for(i=0;i<8;i++){num<<=1;E2R_SCK=1;delaysp(1);if(E2R_SDA)num|=0x01;E2R_SCK=0;delaysp(1);}return(num);}void xie_1byte_24c02_hs(uchar dat){uchar i;E2R_SCK=0;delaysp(1);for(i=0;i<8;i++){E2R_SDA=(bit)(dat&0x80);E2R_SCK=1;delaysp(1);E2R_SCK=0;delaysp(1);dat<<=1;}E2R_SDA=1;delaysp(1);}void xie_24c02_hs(uchar add,uchar cmd,uchar dat){start_24c02_hs();xie_1byte_24c02_hs(add);yingda_24c02_hs();xie_1byte_24c02_hs(cmd);yingda_24c02_hs();xie_1byte_24c02_hs(dat);yingda_24c02_hs();stop_24c02_hs();}uchar du_24c02_hs(uchar add,uchar cmd){uchar tmp;start_24c02_hs();xie_1byte_24c02_hs(add);yingda_24c02_hs();xie_1byte_24c02_hs(cmd);yingda_24c02_hs();start_24c02_hs();xie_1byte_24c02_hs(add|0x01);yingda_24c02_hs();tmp=du_1byte_24c02_hs();stop_24c02_hs();return(tmp);}/*************************************************************************************/void main(){uchar i,j;E2R_inti();lcm1602_init();display_inti();init_du_24c02();DS1302_inti();while(1){cang();for(i=0;i<7;i++){xie_24c02_hs(0xa0,i,xdw[i]);while(j<30){ j++;display();}j=0;} }}void init_du_24c02(){uchar seg;seg=du_24c02_hs(0xa0,0);xdw[0]=seg;seg=du_24c02_hs(0xa0,1);xdw[1]=seg;seg=du_24c02_hs(0xa0,2);xdw[2]=seg;seg=du_24c02_hs(0xa0,3);xdw[3]=seg;seg=du_24c02_hs(0xa0,4);xdw[4]=seg;seg=du_24c02_hs(0xa0,5);xdw[5]=seg;seg=du_24c02_hs(0xa0,6);xdw[6]=seg;} 上一頁 1 2 下一頁
評論