大家新年好!
今天我在网上找到了一个24c64的程序(不确定能用),看到内存地址相关的是先发送地址高8位,在发送地址低8位,我的24c256也是这样写的,但是不可以读和写(用外部烧录器读取没变化,写入单片机读不出来),11.0592晶振,stc89c516RD+单片机,WP接地,a0,a1,a2接地,SCL接P01,SDA接P02,因GND不够用,将WP接P24并置低电平
下面是我的单片机程序,求大佬指点一下!谢谢啦!
#include <reg52.h>
#include <intrins.h>
#define ui unsigned int
#define uc unsigned char
sbit IIC_SCL = P0^1;
sbit IIC_SDA = P0^2;
sbit IIC_WP = P2^4;
void delay0(){;;}
void IIC_start(){
IIC_SDA = 1;
delay0();
IIC_SCL = 1;
delay0();
IIC_SDA = 0;
delay0();
}
void IIC_stop(){
IIC_SDA = 0;
delay0();
IIC_SCL = 1;
delay0();
IIC_SDA = 1;
delay0();
}
void IIC_ACK(){
uc i;
IIC_SCL = 1;
delay0();
while((IIC_SDA == 1) && (i < 250)) i++;
IIC_SCL = 0;
delay0();
}
void IIC_Init(){
IIC_SDA = 1;
delay0();
IIC_SCL = 1;
delay0();
}
void IIC_WR_byte(uc dat){
uc i;
for(i = 0;i < 8;i ++){
dat <<= 1;
IIC_SCL = 0;
delay0();
IIC_SDA = CY;
delay0();
IIC_SCL = 1;
delay0();
}
IIC_SCL = 0;
delay0();
IIC_SDA = 1;
delay0();
}
uc IIC_RD_byte(){
uc i,dat;
IIC_SCL = 0;
delay0();
IIC_SDA = 1;
delay0();
for(i = 0;i < 8;i ++){
IIC_SCL = 1;
delay0();
dat = (dat << 1) | IIC_SDA;
delay0();
}
return dat;
}
void IIC_WR_ADD_256(uc add1,add2,dat){
IIC_start();
IIC_WR_byte(0xa0);
IIC_ACK();
IIC_WR_byte(add1);
IIC_WR_byte(add2);
IIC_ACK();
IIC_WR_byte(dat);
IIC_stop();
}
uc IIC_RD_ADD_256(uc add1,add2){
uc dat;
IIC_start();
IIC_WR_byte(0xa0);
IIC_ACK();
IIC_WR_byte(add1);
IIC_WR_byte(add2);
IIC_ACK();
IIC_start();
IIC_WR_byte(0xa1);
IIC_ACK();
dat = IIC_RD_byte();
IIC_stop();
return dat;
}
void main(){
IIC_WP = 0;
IIC_Init();
IIC_WR_ADD_256(0x10,0x10,0xf0);
P0 = IIC_RD_ADD_256(0x00,0x01);
while(1);
}