国产肉体XXXX裸体137大胆,国产成人久久精品流白浆,国产乱子伦视频在线观看,无码中文字幕免费一区二区三区 国产成人手机在线-午夜国产精品无套-swag国产精品-国产毛片久久国产

新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 實用的單片機模擬I2C總線控制EEPROM讀寫程序

實用的單片機模擬I2C總線控制EEPROM讀寫程序

作者: 時間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
之前寫的EEPROM程序雖然能夠軟仿成功,但燒到單片機里的時候卻不能用,無疑是時序的問題,今天修正了時序,總算硬仿成功了。對照上次的程序可以發(fā)現(xiàn)就是添加了頭函數(shù):,這樣就可以通過“_nop_()”指令較為準確的控制時序。

上次那個問題依然沒有解決:就是接收緩沖區(qū)的數(shù)據(jù)是從readbuf[6]開始的,以這個程序為例:

本文引用地址:http://m.ptau.cn/article/201611/315769.htm

readbuf[6]中存放0x96

readbuf[7]中存放0x84

readbuf[8]中存放0xd5

readbuf[9]中存放0x63

readbuf[10]中存放0x7c

readbuf[11]中存放0x8c

其實我是想把收到的數(shù)據(jù)存放在readbuf[0]~[5]中的,我也不知道為什么結(jié)果會這樣,有知道的麻煩指教下。

不多說了,上程序:

#include
#include
#define unit unsigned int
#define uchar unsigned char

uchar num=6;
uchar idata sendbuf[6]={0x96,0x84,0xd5,0x63,0x7c,0x8c};
uchar idata readbuf[6];

sbit scl=P2^0;
sbit sda=P2^1;

start(void) //start
{
sda=1;
_nop_();
_nop_();
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
sda=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
}

stop(void) //stop
{
sda=0;
_nop_();
_nop_();
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
sda=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
}

answer(void) //answer
{
sda=0;
_nop_();
_nop_();
_nop_();
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
}

noanswer(void)//no answer
{
sda=1;
_nop_();
_nop_();
_nop_();
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
}

checkanswer(void) //check answer
{
F0=0;
sda=1;
_nop_();
_nop_();
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
if(sda==1) F0=1;
scl=0;
}

sendabyte(uchar idata *saddress) //send a byte
{
uchar n=8,temp=*saddress;
while(n--)
{
if((temp&0x80)==0x80) sda=1;
else sda=0;
_nop_();
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
temp=temp<<1;
}
checkanswer();
if(F0==1) return;
}

sendnbyte(uchar n) //send n byte
{
uchar idata *ps;
ps=&sendbuf[0];

while(n--)
{
sendabyte(ps);
ps++;
}
stop();
}

readabyte(uchar idata *raddress) //read a byte
{
uchar n=8,temp=0;
while(n--)
{
_nop_();
_nop_();
scl=1;
_nop_();
_nop_();
temp=temp<<1;
if(sda==1)
temp=temp|0x01;
else
temp=temp&0xfe;
_nop_();
_nop_();
_nop_();
scl=0;
_nop_();
_nop_();
_nop_();
}
*raddress=temp;
}

readnbyte(uchar n) //read n byte
{
uchar idata *pr;
pr=&readbuf[0];
while(n--)
{
readabyte(pr);
answer();
pr++;
}
noanswer();
stop();
}

main(void) //MAIN
{
start();

sendabyte(0xa0);

sendabyte(0x00);

sendnbyte(num);

/*-----------------------*/
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();

start();

sendabyte(0xa0);

sendabyte(0x00);

sendabyte(0xa1);

readnbyte(num);

P1=readbuf[11];

while(1);
}



評論


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

關(guān)閉