📄 x25045.c
字号:
#define WREN 0x06 /* Set the write enable latch(enable write operations) */
#define SFLB 0x00 /* Set flag bit */
#define WRDI 0x04 /* Reset the write enable latch/reset flag bit */
#define RSDR 0x05 /* Read status register */
#define WRSR 0x01 /* Write status register */
#define READ 0x03 /* Read data from memory array beginning at selacted address */
#define WRITE 0x02 /* Write data to memory array beginning at selacted address */
char byte_read_eeprom(unsigned char address){
unsigned char i,command;
EEPROMCS = 0;
command = READ;
for(i=0;i<8;i++){
SCLK = 0;
if(command & 0x80) SI = 1;
else SI = 0;
command = (command << 1);
SCLK = 1;
}
for(i=0;i<8;i++){
SCLK = 0;
if(address & 0x80) SI = 1;
else SI = 0;
address = (address << 1);
SCLK = 1;
}
for(i=0;i<8;i++){
SCLK = 0;
_nop_();
command = (command << 1) | SO;
SCLK = 1;
}
EEPROMCS = 1;
return command;
}
char read_status(){
unsigned char i,command;
EEPROMCS = 0;
command = RSDR;
for(i=0;i<8;i++){
SCLK = 0;
if(command & 0x80) SI = 1;
else SI = 0;
command = (command << 1);
SCLK = 1;
}
for(i=0;i<8;i++){
SCLK = 0;
_nop_();
command = (command << 1) | SO;
SCLK = 1;
}
EEPROMCS = 1;
return command;
}
void write_status(char status){
unsigned char i,command;
EEPROMCS = 0;
command = WRSR;
for(i=0;i<8;i++){
SCLK = 0;
if(command & 0x80) SI = 1;
else SI = 0;
command = (command << 1);
SCLK = 1;
}
command = status;
for(i=0;i<8;i++){
SCLK = 0;
if(command & 0x80) SI = 1;
else SI = 0;
command = (command << 1);
SCLK = 1;
}
EEPROMCS = 1;
}
write_enable_latch(){
unsigned char i,command;
EEPROMCS = 0;
command = WREN;
for(i=0;i<8;i++){
SCLK = 0;
if(command & 0x80) SI = 1;
else SI = 0;
command = (command << 1);
SCLK = 1;
}
EEPROMCS = 1;
}
byte_write_eeprom(unsigned char address,char wdata){
unsigned char i,command;
write_enable_latch();
EEPROMCS = 0;
command = WRITE;
for(i=0;i<8;i++){
SCLK = 0;
if(command & 0x80) SI = 1;
else SI = 0;
command = (command << 1);
SCLK = 1;
}
for(i=0;i<8;i++){
SCLK = 0;
if(address & 0x80) SI = 1;
else SI = 0;
address = (address << 1);
SCLK = 1;
}
command = wdata;
for(i=0;i<8;i++){
SCLK = 0;
if(command & 0x80) SI = 1;
else SI = 0;
command = (command << 1);
SCLK = 1;
}
EEPROMCS = 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -