51单片机仿真例程-串行EEPROM扩展

代码:

通过IIC总线写入24C04模块

#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define AddWr24c04 0xa0
#define AddRd24c04 0xa1
#define delay4us(){_nop_();_nop_();_nop_();_nop_();_nop_();};

sbit SDA=P1^1;
sbit SCL=P1^0;
bit ack;
uchar tab[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void STARTI2C()
{
  SDA=1;
  _nop_();
  SCL=1;
  delay4us();
  SDA=0;
  delay4us();
  SCL=0;
  _nop_();
  _nop_();
}
void STOPI2C()
{
  SDA=0;
  _nop_();
  SCL=1;
  delay4us();
  SDA=1;
  delay4us();
}
uchar rcvbyte()
{
  uchar retc,BitCnt;
  retc=0;
  SDA=1;
  for(BitCnt=0;BitCnt<8;BitCnt++)
  {
    _nop_();
	SCL=0;
	delay4us();
	SCL=1;
	_nop_();
	_nop_();
	retc=retc<<1;
	if(SDA==1)
	  retc=retc+1;
	_nop_();
	_nop_();

  
  
  }
  SCL=0;
  _nop_();
  _nop_();
  return(retc);



}
void sendbyte(uchar c)
{
 unsigned ch
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值