AT24C512程序

阅读: 评论:0

标题:AT24C512程序
1楼
cnrtu 发表于:2007-10-11 17:12:04
#include "SM89516A.h"
sbit SCL = P1^0;
sbit SDA = P1^1;
void Delay( void )
{
 unsigned char i = 10;
 
 while(i--);
}
void IIC_Start( void )
{
 SDA = 1;
 SCL = 1;
 Delay( );
 SDA = 0;
 Delay( );
 SCL = 0;
}
void IIC_Stop( void ) 
{
 SDA = 0;
 SCL = 1;
 Delay( );
 SDA = 1;
 Delay( );
 SCL = 0;
}
void IIC_ACK( void ) 
{y型钢
 SDA = 0;
 SCL = 1;
 Delay( ); 
// SDA = 1;
 SCL = 0;
}
void IIC_NACK( void ) 
{
 SDA = 1;
 SCL = 1;
 Delay( ); 
// SDA = 0;
 SCL = 0;
}
bit IIC_WriteByte(unsigned char Byte)
{
 unsigned char i;
 bit ack;
 渗透印章
 for( i=0; i<8; i++ )
 {
    if( ( Byte << i ) & 0x80 ) 
  {
   IIC_NACK(  );
  }
  else
  {
   IIC_ACK(  );
  } 
 }
 
 SDA = 1; 
 SCL = 1;
 Delay( );
山地单轨运输车 ack = SDA;
 Delay( );   
 SCL =0;
 
  return( ack );
}
 
unsigned char IIC_ReadByte( void )
{
 register char i, Byte = 0;
 for( i=0; i<8; i++)
 {
  SDA = 1; 
  SCL = 1; 
  Delay( ); 
  Byte = Byte<<1;     
自动排污阀  if( SDA )
  {
   Byte |= 0x01;
  }
  else
  {
   Byte &= 0xfe;
  }
  SCL = 0; 旋压皮带轮
  Delay( );   
 }
 
 return Byte;
void IIC_WriteData( unsigned char nChip, unsigned int WAddress, unsigned char *WData, unsigned int Count )
{
 unsigned int Len;
 
 IIC_Start(  );
 if( IIC_WriteByte(0xA0+(nChip<<1)) )
 {
  return; 
 }
 if( IIC_WriteByte( (unsigned char )WAddress / 256 ) )
 {
  return;
 }
 if( IIC_WriteByte( (unsigned char )WAddress % 256 ) )
 {
  return;
 }
 for( Len=0; Len<Count; Len++ )
 {
  if( IIC_WriteByte(WData[Len]) )
  {
   return;
防屏蔽  }
 } 
 
 P0_3 = !P0_3;
 IIC_Stop(  );
}
void IIC_ReadData( unsigned char nChip, unsigned int RAddress, unsigned char *RData, unsigned int Count )
{
 unsigned int Len;
 
 IIC_Start(  );
 if( IIC_WriteByte( 0xA0+(nChip<<1) ) )
 {
  return; 
 }

本文发布于:2023-05-14 08:51:56,感谢您对本站的认可!

本文链接:https://patent.en369.cn/patent/4/99182.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:程序   渗透   运输车   自动
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 369专利查询检索平台 豫ICP备2021025688号-20 网站地图