24c16讀寫驅動程序,
//=-----------------------------------------------------------------------------
--
/*模塊調用:
讀數據:read(unsigned int address)
寫數據:write(unsigned int address,unsigned char dd) dd為要寫的 數據字節*/
//------------------------------------------------------------------------------
sbit sda=P3^0;
sbit scl=P3^1;
sbit a0=ACC^0; //定義ACC的位,利用ACC操作
速度最快
sbit a1=ACC^1;
sbit a2=ACC^2;
sbit a3=ACC^3;
sbit a4=ACC^4;
sbit a5=ACC^5;
sbit a6=ACC^6;
sbit a7=ACC^7;
//------------------------------------------------------------------------------
#pragma disable
void s24(void) //起始函數
{
_nop_();
scl=0;
sda=1;
scl=1;
_nop_();
sda=0;
_nop_();
_nop_();
scl=0;
_nop_();
_nop_();
sda=1;
}
//------------------------------------------------------------------------------
#pragma disable
void p24(void) //停止函數
{
sda=0;
scl=1;
_nop_();
_nop_();
sda=1;
}
//-----------------------------------------------------------------------------
#pragma disable
unsigned char rd24(void) /////////////////從24c16讀一字節數據
{ ACC=0x00;
sda=1;
scl=1;a7=sda;_nop_();_nop_();_nop_();_nop_();scl=0;
scl=1;a6=sda;_nop_();_nop_();_nop_();_nop_();scl=0;
scl=1;a5=sda;_nop_();_nop_();_nop_();_nop_();scl=0;
scl=1;a4=sda;_nop_();_nop_();_nop_();_nop_();scl=0;
scl=1;a3=sda;_nop_();_nop_();_nop_();_nop_();scl=0;
scl=1;a2=sda;_nop_();_nop_();_nop_();_nop_();scl=0;
scl=1;a1=sda;_nop_();_nop_();_nop_();_nop_();scl=0;
scl=1;a0=sda;_nop_();_nop_();_nop_();_nop_();scl=0;
sda=1;scl=1;_nop_();_nop_();_nop_();_nop_
();scl=0; /// ///////////////24c16的一位回答位。
return(ACC);
}
//------------------------------------------------------------------------------
#pragma disable
void wd24(unsigned char dd) ////////////////向24c16寫一字節數據
{ sda=1;
ACC=dd;
sda=a7;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;
sda=a6;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;
sda=a5;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;
sda=a4;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;
sda=a3;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;
sda=a2;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;
sda=a1;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;
sda=a0;scl=1;_nop_();_nop_();_nop_();_nop_();scl=0;
sda=0;scl=1;//scl=0;(在下面程序中)
}
//---------------------------------------------------------------------------
#pragma disable
unsigned char read(unsigned int address)
{
unsigned char dd;
s24(); ////////////////////////開始條件
wd24(0xa0); /////////////////////////寫器件地址(寫命令)
_nop_();_nop_();_nop_();_nop_();
scl=0; ///////////////////////////////////接收器件地
址確認信號
wd24(address); //////////////////////////// 寫數據地址
_nop_();_nop_();_nop_();_nop_();
scl=0;
s24
(); ///////////////////////////////////開始條件
wd24(0xa1); /////////////////////////////寫器件地址(讀命
令)
scl=0;
dd=rd24(); //////////////////////////////////讀 一字節
p24(); ////////////////////////////////////停止條件
return(dd);
}
//------------------------------------------------------------------------------
#pragma disable
void write(unsigned int address,unsigned char dd)
{
s24(); /////////////////開始條件
wd24(0xa0); ////////////////////////寫器件地址;
scl=0;
wd24(address); /////////////////////寫數據地址
scl=0;
wd24(dd); //////////////////////////寫dd數據
scl=0;
p24(); /////////////////////////停止條件;
}
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶:
資源簡介:
上傳時間:
上傳用戶: