找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

求教各位大侠关于89S52和X5045的问题

[复制链接]
admin 发表于 2012-9-2 08:22:36 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
我想把一个数据存入x5045的EEPROM中,然后读出这个数据,并且输出到89S52的P2口中,但怎么调试都不对。
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit CS=P1^0;
sbit SO=P1^1;
sbit SI=P1^2;
sbit SCLK=P1^3;
delay1ms(int t)
{
int i,j;
for(i=0;i<t;i++)
for(j=0;j<120;j++) ;
}
void Write_X5045(unsigned char Writer_data) //写数据
{

unsigned char i;
for(i=0;i<8;i++)
{
SI=(bit)(Writer_data&0x80);
SCLK=0;
SCLK=1;
Writer_data<<=1;
}
SI=0; //使SI处于确定的状态
}
uchar Read_X5045(void) //读数据
{
unsigned char i,Read_data;
for(i=0;i<8;i++)
{
SCLK=1;
SCLK=0;
Read_data<<=1;
Read_data|=(uchar)(SO);
}
return Read_data;
}
void WREN_Cmd (void) //写使能
{
SCLK=0;
CS=0;
Write_X5045(0x06);
SCLK=0;
CS=1;
}
void WRDI_Cmd (void) //写关闭
{
SCLK=0;
CS=0;
Write_X5045(0x04);
SCLK=0;
CS=1;
}
void Write_StateReg(uchar Writer_data) //写寄存器
{
delay1ms(10); //等待器件稳定,经验值
WREN_Cmd (); //解锁
SCLK=0;
CS=0;
Write_X5045(0X01);
Write_X5045(Writer_data);
SCLK=0;
CS=1;
WRDI_Cmd (); //上锁
}
void Writer_to_X5045(unsigned char Writer_data,address) //把数据写到EEPROM
{
WREN_Cmd (); //解锁
SCLK=0;
CS=0;
Write_X5045(0X02);
Write_X5045(address);
Write_X5045(Writer_data);
SCLK=0;
CS=1;
WRDI_Cmd (); //上锁
}
uchar Read_form_X5045(uchar address) //从EEPROM中读取数据
{
uchar Read_data;
SCLK=0;
CS=0;
Write_X5045(0X03);
Write_X5045(address);
Read_data=Read_X5045();
SCLK=0;
CS=1;
return Read_data;
}
void Reset_Vtrip(void) //复位
{
CS=0;
delay1ms(50);
SCLK=0;
CS=0;
Write_X5045(0x06);
SCLK=0;
CS=1;
delay1ms(10);
SCLK=0;
CS=0;
Write_X5045(0X02);
Write_X5045(0x00);
Write_X5045(0x03);
Write_X5045(0x00);
SCLK=0;
CS=1;
}
void main(void) //主函数
{
Reset_Vtrip();
delay1ms(60000);
CS=0;
Writer_to_X5045(0x44,0x10); //把0x44写入0x10地址的EEPROM中
P2=Read_form_X5045(0x10); //把0x10中的数据读出来放到P2口中





}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 09:59 , Processed in 0.059073 second(s), 10 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表