有哪位大侠用过AD7416?

zys0001 2003-09-17 11:14:45
有哪位大侠用过AD7416?麻烦提供一下读取温度值的代码(汇编的),100分相送,不够的话再加,谢谢。
...全文
40 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
coffeefish 2003-09-18
  • 打赏
  • 举报
回复
我用过c51得,你看懂了,移植到汇编很简单
sbit Second_Led=P2^4;
sbit Power_OnOff=P2^5;
sbit Led1=P2^0;
sbit Led2=P2^1;
sbit Led3=P2^2;
sbit Led4=P2^3;

sbit ks=P1^0;
sbit ku=P1^1;
sbit kd=P1^2;
sbit LE=P0^6;

sbit SDA = P3^5;
sbit SCL = P3^4;

sbit DS_CLK = P1^3;
sbit DS_IO = P1^4;
sbit DS_RST = P1^5;


char cp=0,cp1=0,di=0,cps=0,cpt,cps1;
char buf[4],d=0,c,dt[7];
char disp_mode;

typedef struct
{
unsigned char h,m,t;
}SEG_CT;
SEG_CT seg_ct[10];


/**************** IIC Access Function *******************/
/* Author: Dai LiZHou */
/* Date: 1999.8.24 */
/* Last Date: 1999.8.24 */
/********************************************************/

/********** Function Declare Begin **********************/

char Start(); /* Start IIC bus for reading or writing*/
void Stop(); /* Stop IIC bus */
char Shin(); /* Shift a byte from EEPROM, */
/* most significant first */
void Shout(char Byte); /* Shift a byte to EEPROM */
char TestAck(); /* check if Acknowledge bit is valid */


/********** Function Declare End *************************/

char Start()
{
SCL=1; /* release SCL */
SDA=1; /* release SDA */
_nop_();
_nop_();
_nop_();
_nop_();
if( SCL==0 || SDA==0 ) return 0; /* IIC bus not available, Start false */
else
{
SCL=1; /* Send start operation */
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=0; /* SDA high-to-low when SCL high */
_nop_();
_nop_();
_nop_(); /*one cycle delay function */
_nop_(); /*declare in <intrins.h> */
_nop_();
SCL=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1; /*release SDA */
}
} /*return with SDA high, SCL low */

void Stop()
{
SDA=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1; /* SDA low-to-high when SCL high, return with SCL SDA high */
}

char Shin()
{
char i,RetByte;
for(i=0;i<8;i++)
{
SCL=0;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
RetByte=RetByte<<1;
if( SDA==1 ) RetByte=RetByte|0x01;
}
SCL=0;
_nop_();
_nop_(); /* return with SCL low, SDA high */
SDA=1;
return RetByte;
}

void Shout( char Byte )
{ /* Send one byte to EEPROM */
/* most significant */
char i;
for(i=0;i<8;i++)
{
SCL=0;
_nop_();
_nop_();
if( Byte&0x80 ) SDA=1;
else SDA=0;
_nop_();
_nop_();
Byte=Byte<<1;
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
SCL=0;
_nop_();
_nop_();
_nop_();
_nop_();
SDA=1; /* return with SCL low , SDA high */
}

char TestAck()
{
char rf=0; /* return flag */
SCL=0;
_nop_();
_nop_();
_nop_();
SDA=1; /* release SDA */
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
_nop_();
_nop_();
if( SDA==1 ) rf=1; /* Acknowledge bit is invalid*/
else rf=0;
SCL=0;
_nop_();
_nop_();
_nop_();
return rf;
}

unsigned int LM74_Read(void)
{
unsigned char rc_h=0, rc_l=0,i;
unsigned int bbData,sum;

Start();
Shout( 0x90 ); /* send device address & write command */
if( !TestAck() )
{
Shout(0);
TestAck();
}
Stop;

sum=0;
for(i=0;i<10;i++)
{
Start();
Shout( 0x91 ); /* send device address & write command */
if( !TestAck() )
{
rc_h=Shin();
if( !TestAck() )
rc_l=Shin();
TestAck();
}
Stop();

bbData=rc_h;
bbData=_irol_(bbData,8);
bbData=bbData|rc_l;
bbData=_iror_(bbData,6);
bbData=bbData&0x0FFF;

sum+=bbData;
}
bbData=sum/10;
return (bbData);
}

void LM74_Set(void)
{
unsigned char rc_h, rc_l;
unsigned int bbData;

Start();
Shout( 0x90 ); /* send device address & write command */
if( !TestAck() )
{
Shout( 1 ); /* send byte address to read */
if( !TestAck() )
{
Shout(0x0);
TestAck();
}
}
Stop();

Start();
Shout( 0x91 ); /* send device address & write command */
if( !TestAck() )
{
rc_l=Shin();
TestAck();
}
Stop();

}
wangluyan 2003-09-18
  • 打赏
  • 举报
回复
也可以去这个网站看看!
http://www.atsemi.com/index.htm
wangluyan 2003-09-18
  • 打赏
  • 举报
回复
去这个网站!
http://www.rdeast.com/bbs/dispbbs.asp?boardID=5&ID=326
不懂可以在这个网站留言!~

27,382

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 单片机/工控
社区管理员
  • 单片机/工控社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧