資源簡(jiǎn)介
實(shí)現(xiàn)EEPROM芯片的讀取和寫(xiě)入數(shù)據(jù) 模擬IIC實(shí)現(xiàn) MSP430F149單片機(jī) 可以移植到STM32 STC51等其他系列單片機(jī)

代碼片段和文件信息
#include?“IIC.h“
typedef?unsigned?char?uchar;
typedef?unsigned?int??uint;
#define?deviceaddress?0xa0??//AT24C02的設(shè)備地址
/*******************************************
函數(shù)名稱(chēng):delay_10ms
功????能:延時(shí)約6ms,等待EEPROM完成內(nèi)部寫(xiě)入
參????數(shù):無(wú)
返回值??:無(wú)
********************************************/
void?delay_10ms(void)
{
uint?i?=?1000;
while(i--);
}
/*******************************************
函數(shù)名稱(chēng):Write_1Byte
功????能:向EEPROM中寫(xiě)入1個(gè)字節(jié)的數(shù)據(jù)
參????數(shù):Wdata--寫(xiě)入的數(shù)據(jù)
??????????dataaddress--數(shù)據(jù)的寫(xiě)入地址
返回值??:寫(xiě)入結(jié)果:1--成功,0--失敗
********************************************/
uchar?Write_1Byte(uchar?wdatauchar?dataaddress)
{
start();
write1byte(deviceaddress);
if(check())?
????????write1byte(dataaddress);
else?
????????return?0;
if(check())?
????????write1byte(wdata);
else?
????????return?0;
if(check()) ????stop();
else????????????return?0;
????
????delay_10ms();???????//等待EEPROM完成內(nèi)部寫(xiě)入
return?1;?
}
/*******************************************
函數(shù)名稱(chēng):Write_NByte
功????能:向EEPROM中寫(xiě)入N個(gè)字節(jié)的數(shù)據(jù)
參????數(shù):outbuf--指向?qū)懭霐?shù)據(jù)存放首地址的指針
??????????n--數(shù)據(jù)個(gè)數(shù),最大不能超過(guò)8,由頁(yè)地址
?????????????決定其最大長(zhǎng)度
??????????dataaddress--數(shù)據(jù)寫(xiě)入的首地址
返回值??:寫(xiě)入結(jié)果:1--成功,0--失敗
********************************************/
uchar?Write_NByte(uchar?*?outbufuchar?nuchar?dataaddress)
{
uchar??flag;?
????
start();
write1byte(deviceaddress);??????????????????//寫(xiě)入器件地址
if(check()?==?1)?
????????write1byte(dataaddress);????????????????//寫(xiě)入數(shù)據(jù)字地址
else?
????????return?0;
if(check())?
????????flag=writeNbyte(outbufn);
else?
????????return?0;
????delay_10ms();???????//等待EEPROM完成內(nèi)部寫(xiě)入
if(flag)????return?1;
else????????return?0;
}
/*******************************************
函數(shù)名稱(chēng):Read_1Byte_currentaddress
功????能:從EEPROM的當(dāng)前地址讀取1個(gè)字節(jié)的數(shù)據(jù)
參????數(shù):無(wú)
返回值??:讀取的數(shù)據(jù)
********************************************/
uchar?Read_1Byte_currentaddress(void)
{
uchar?temp;
????
start();
write1byte((deviceaddress|0x01));
if(check())
????????temp?=?read1byte();
else?
????????return?0;
mnack();
stop();
return?temp;
}
/*******************************************
函數(shù)名稱(chēng):Read_NByte_currentaddress
功????能:從EEPROM的當(dāng)前地址讀取N個(gè)字節(jié)的數(shù)據(jù)
參????數(shù):readbuf--指向保存數(shù)據(jù)地址的指針
??????????n--讀取數(shù)據(jù)的個(gè)數(shù)
返回值??:讀取結(jié)果:1--成功,0--失敗
********************************************/
uchar?Read_NByte_currentaddress(uchar?*?readbufuchar?n)
{???
????start();
write1byte((deviceaddress|0x01));
if(check())?
????????readNbyte(readbufn);
else?
????????return?0;
????
return??1;
}
/*******************************************
函數(shù)名稱(chēng):Read_1Byte_Randomaddress
功????能:從EEPROM的指定地址讀取1個(gè)字節(jié)的數(shù)據(jù)
參????數(shù):dataaddress--數(shù)據(jù)讀取的地址
返回值??:讀取的數(shù)據(jù)
********************************************/
uchar?Read_1Byte_Randomaddress(uchar?dataaddress)
{
uchar?temp;
????
start();
write1byte(deviceaddress);
if(check())
????????write1byte(dataaddress);
else?
????????return?0;
if(check())?
{
start();
write1byte((deviceaddress|0x01));
}
else????
????????return?0;
if(check())
????????temp?=?read1byte();
else
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????目錄???????????0??2013-11-17?12:00??AT24C1024存儲(chǔ)程序\
?????目錄???????????0??2013-11-17?12:00??AT24C1024存儲(chǔ)程序\E1\
?????文件???????12490??2010-04-30?22:52??AT24C1024存儲(chǔ)程序\E1\Backup?of?E1.ewd
?????文件???????43820??2010-04-30?22:53??AT24C1024存儲(chǔ)程序\E1\Backup?of?E1.ewp
?????目錄???????????0??2013-11-17?12:00??AT24C1024存儲(chǔ)程序\E1\Debug\
?????目錄???????????0??2013-11-17?12:00??AT24C1024存儲(chǔ)程序\E1\Debug\Exe\
?????文件???????16063??2011-06-17?00:13??AT24C1024存儲(chǔ)程序\E1\Debug\Exe\E1.d43
?????文件????????3040??2011-06-28?18:47??AT24C1024存儲(chǔ)程序\E1\Debug\Exe\E1.txt
?????目錄???????????0??2013-11-17?12:00??AT24C1024存儲(chǔ)程序\E1\Debug\List\
?????目錄???????????0??2013-11-17?12:00??AT24C1024存儲(chǔ)程序\E1\Debug\Obj\
?????文件?????????280??2011-07-12?00:41??AT24C1024存儲(chǔ)程序\E1\Debug\Obj\E1.pbd
?????文件???????20377??2011-06-17?00:13??AT24C1024存儲(chǔ)程序\E1\Debug\Obj\EEPROM.r43
?????文件???????17681??2011-06-17?00:13??AT24C1024存儲(chǔ)程序\E1\Debug\Obj\IIC.r43
?????文件????????7697??2011-06-17?00:13??AT24C1024存儲(chǔ)程序\E1\Debug\Obj\main.r43
?????文件????????3667??2011-07-12?00:41??AT24C1024存儲(chǔ)程序\E1\E1.dep
?????文件???????17846??2011-06-17?00:13??AT24C1024存儲(chǔ)程序\E1\E1.ewd
?????文件???????47199??2011-06-28?18:47??AT24C1024存儲(chǔ)程序\E1\E1.ewp
?????文件?????????156??2008-03-22?22:55??AT24C1024存儲(chǔ)程序\E1\E1.eww
?????文件????????4096??2008-03-05?10:57??AT24C1024存儲(chǔ)程序\E1\EEPROM.c
?????文件?????????476??2008-01-01?09:45??AT24C1024存儲(chǔ)程序\E1\EEPROM.h
?????文件????????4695??2008-01-24?23:02??AT24C1024存儲(chǔ)程序\E1\IIC.c
?????文件?????????361??2008-01-01?08:55??AT24C1024存儲(chǔ)程序\E1\IIC.h
?????文件????????1472??2010-04-21?13:09??AT24C1024存儲(chǔ)程序\E1\main.c
?????目錄???????????0??2013-11-17?12:00??AT24C1024存儲(chǔ)程序\E1\settings\
?????文件????????2785??2011-07-12?00:41??AT24C1024存儲(chǔ)程序\E1\settings\E1.cspy.bat
?????文件????????4677??2011-07-12?00:41??AT24C1024存儲(chǔ)程序\E1\settings\E1.dbgdt
?????文件????????1108??2011-07-12?00:41??AT24C1024存儲(chǔ)程序\E1\settings\E1.dni
?????文件????????2893??2011-07-12?00:41??AT24C1024存儲(chǔ)程序\E1\settings\E1.wsdt
?????目錄???????????0??2013-11-17?12:00??AT24C1024存儲(chǔ)程序\E2\
?????文件???????12489??2010-05-09?00:16??AT24C1024存儲(chǔ)程序\E2\Backup?of?E2.ewd
?????文件???????44198??2006-12-06?10:16??AT24C1024存儲(chǔ)程序\E2\Backup?of?E2.ewp
............此處省略24個(gè)文件信息
評(píng)論
共有 條評(píng)論