导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→X5045程序,什么问题,请大侠门看看[jxcrg_t35]

 *第40422篇: X5045程序,什么问题,请大侠门看看

  
楼 主:jxcrg_t35 2011年12月25日18:11
 X5045程序,什么问题,请大侠门看看
#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。郁闷,一直调试不出来,请大侠门看看。
 


>>>>>>对该主题发表你的看法

本主题贴数1,分页: [第1页]


[上一篇主题]:太平洋安防奥斯卡之夜投票赢IPAD 更多好礼送不停

[下一篇主题]:[原创]你想做点什么吗?深圳嵌入式那个机构培训好?什么是嵌入式培训?什么是嵌入式?