/******發(fā)送數(shù)據(jù)*********/void send_message(unchar date){unchar temp,i; temp=date;SCL=0;NOP();for (i=0;i<8;++i){temp=temp<<1;SDA=CY;NOP();SCL=1;NOP();SCL=0;NOP();}SDA=1;NOP(); }/***** 接收數(shù)據(jù) *****/unchar rece_message(void){unchar date,temp,i;SCL=0;CY=0;NOP();for(i=0;i<8;++i){SCL=1;NOP();temp=SDA;date=date<<1;date=date|temp;SCL=0;NOP(); }SDA=1;NOP();return date;}/***** 應(yīng)答接收 ********/unchar ack_back(void){unchar ack;SCL=0;NOP();SCL=1;NOP();ack=SDA;NOP();SCL=0;return ack;}/****完整接收數(shù)據(jù)*******/unchar get(unchar add){ unchar date;delay(50);start(); send_message(0xa0); ack_back();send_message(add); ack_back();start();send_message(0xa1); ack_back();date=rece_message(); stop();delay(50);return date ;}/******完整寫(xiě)入數(shù)據(jù)*******/void write(unchar date,unchar add){init();start();send_message(0xa0); //發(fā)送地址碼ack_back();send_message(add); //存儲(chǔ)的內(nèi)容首地址ack_back(); send_message(date);ack_back();stop(); }/*****寫(xiě)入數(shù)據(jù)串 并分配指針地址*******/void write_s (unchar date){if(date!=#)write(date,ac);if (date==#){ac=ac+0x10;write(ac,0xff);}}void main(){ init();//ac=get(0xff);while(1){while(!RI);RI=0;// write_s(SBUF);LCD_date(SBUF);}}本文引用地址:http://www.ex-cimer.com/article/201611/323236.htm不以程序長(zhǎng)短論英雄,成敗完全取決于細(xì)節(jié)的把握。一步登天難,十天學(xué)會(huì)單片機(jī)更難。扎實(shí)的基礎(chǔ),刻苦的精神是成功的必備。謹(jǐn)以此句,哀悼我三個(gè)失敗的項(xiàng)目。EPROM莫名的錯(cuò)誤已讓我發(fā)瘋。高強(qiáng)度的腦力,低質(zhì)量的四小時(shí)睡眠,我已經(jīng)精疲力竭了。我真以為我能一步登天,我太急躁了。
評(píng)論