打印

X5045程序,什么问题,请大侠看看

[复制链接]
1919|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jxcrg_t35|  楼主 | 2011-12-26 21:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include   <reg51.h>  
#include   <intrins.h>  
#include   <config.h>   

extern bit x5045useflag;
void x5045_write_onebyte(unsigned char onedata){//只做时钟,不判断其他,在调用程序中加读写条件

unsigned char i;

   
for(i=0;i  <8;i++){  //上升沿写入SI
  x5045_si=(bit)(onedata&0x80);
  x5045_sck=0;
  onedata  <  <=1;
  x5045_sck=1;      //SCK=1;
  }

}

unsigned char x5045_read_onebyte(void){//只做时钟,不判断其他,在调用程序中加读写条件

unsigned char i,onedata;

   
for(i=0;i  <8;i++){  //下降沿读入So
  x5045_sck=1;
  x5045_sck=0;  //sck=0;
  onedata|=x5045_si;
  onedata  <  <=1;
  }
return(onedata);

}

unsigned char x5045_read_status(void){
unsigned char temp;
//*****************************
x5045_so=1;
x5045_si=1;

//*****************************/


x5045_cs=0;
x5045useflag=1;
x5045_write_onebyte(RSDR);
temp=x5045_read_onebyte();
x5045_cs=1;
x5045useflag=0;
return(temp);

}

void x5045_write_status(unsigned char vdata){
x5045_cs=0;
x5045useflag=1;
x5045_write_onebyte(WREN);
x5045_cs=1;

x5045_cs=0;
x5045_write_onebyte(WRSR);
x5045_write_onebyte(vdata);
x5045_cs=1;
x5045useflag=0;

}

void x5045_write_data(unsigned int adders,unsigned char data_buff){  //len  <16,每页为16BYTE字节
x5045useflag=1;
x5045_cs=0;
x5045_write_onebyte(WREN);//写完后,CS需被拉高,write enble  SCK=1
x5045_cs=1;

//temp=(adders>  255)?WRITE_ADDERS_H:WRITE_ADDERS_L; //写入高地址
  
  x5045_cs=0;
  x5045_write_onebyte((adders>  255)?WRITE_ADDERS_H:WRITE_ADDERS_L); //写入write 指令地址
   
  //temp=(unsigned char)adders; //写入真实地址
  x5045_write_onebyte((unsigned char)adders);  
   
  //temp=data_buff;//写入数据
  x5045_write_onebyte(data_buff);
   
  
  x5045_cs=1;  //写入完成  SCK=1
  x5045useflag=0;
  
  if(x5045_read_status()&0x01){x5045_cs=0;
   _nop_();
   x5045_cs=1;}; //检查WIP状态,喂狗,=0时,写入完成
  
}


unsigned char x5045_read_data(unsigned int adders){//返还指定地址的数据
unsigned char temp;
x5045useflag=1;
x5045_so=1;
x5045_cs=0;
//temp=(adders>  255)?READ_ADDERS_H:READ_ADDERS_L;//高地址读
x5045_write_onebyte((adders>  255)?READ_ADDERS_H:READ_ADDERS_L); //写入读地址指令
x5045_write_onebyte((unsigned char )adders); //sck=1  
temp=x5045_read_onebyte();
  
x5045_cs=1;
x5045useflag=0;
return(temp);
      
  
  }
调用读寄存器的状态是FE,分别写入指定地址0x55,0xaa,读出来是00,fe。郁闷,一直调试不出来,请大侠们帮帮看看。

相关帖子

沙发
jxcrg_t35|  楼主 | 2011-12-27 13:05 | 只看该作者
大家,看看

使用特权

评论回复
板凳
yuanquan12345| | 2015-9-13 17:26 | 只看该作者
问题解决了吗?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

2

帖子

1

粉丝