导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→关于25045的问题!急!

* 58538: 关于25045的问题!急!

   longxiuwei 
longxiuwei发表的帖子 

 关于25045的问题!急!
我现在在写25045的驱动程序出了个问题!我把读状态寄存器的指令写入后可读出的数据全是高不知道是什么原因!那为大虾写个这方面的程序望指点一下!谢谢!
程序如下::
#include  <reg52.h>  
#include  <intrins.h>  
#define uchar unsigned char
#define uint  unsigned char
/*****************指令宏定义******************/
#define WREN 0x06//写允许
#define WRDI 0x04//写禁止
#define RSDR 0x05//读状态寄存器
#define WRSR 0x01//写状态寄存器
#define READ0 0x02//选定读地址0
#define READ1 0x0b//选定读地址1
#define WRIT0 0x03//选定写地址0
#define WRIT1 0x0a//选定写地址1
/****************端口引脚定义*****************/
sbit cs=P1^0;//片选低电平有效
sbit so=P1^1;//串行数据输出
sbit sck=P1^2;//串行时钟输出
sbit si=P1^3;//串行数据输入
uchar DD[2];
void delay(uchar n)
 {
  while(n--);
 }
/****************8位数据传送函数*************/
void write8byte(uchar byte)
  {
   uchar i;
   
   for(i=0;i  <8;i++)
    {
     
 if(byte&0x80)
 {
      si=1;
 }
     else 
  {
  si=0;
  }
     sck=0;
     sck=1;
     byte=byte  <  <1;
  }
   
 }
/****************8位数据传送函数************/
uchar read8byte(void)
 {
   bit r_byte;
   uchar i;
   uchar byte1=0;
   for(i=0;i  <8;i++)
    {
     sck=1;
     sck=0;
     r_byte=so;
     byte1  <  <=1;
  if(r_byte) 
  {
  byte1|=0x01;
    }}
 
 return(byte1);
 
}  
/**************************读状态寄存器函数*****************/
uchar readcom(void)
 {
  uchar byte2;
 cs=0;
  
  write8byte(RSDR);
  delay(50);
  byte2=read8byte();
  cs=1;
  return(byte2);
}
/*************************写状态寄存器函数***************/
void writecom(uchar dd)
 {
  
  cs=0;
  while((readcom()&0x01)==1);
  cs=0;
  write8byte(WREN);
  cs=1;
  cs=0;
  write8byte(WRSR);
  write8byte(dd);
  cs=1;
 
 }

/**************************页写入数据函数***************/
void writepage(uchar setcom,uchar address,uchar bb[],uchar k,bit n)
  {//uchar bata;
   uchar i;
   cs=0;
   sck=0;
   writecom(setcom);
   while((readcom()&0x01)==1);
   cs=0;
   write8byte(WREN);
   cs=1;
   cs=0;
   if(n) write8byte(WRIT0);
   else  write8byte(WRIT1);
   write8byte(address);
   for(i=0;i  <k;i++)
   write8byte(bb[i]);
   cs=1;
   sck=0;
  }
/**********************连续读出函数*****************/
void readpage(uchar address,uchar k,bit n)
  {
   uchar i;
   //uchar rbyte;
   while((readcom()&0x01)==1);
   cs=0;
   sck=0;
   if(n)write8byte(READ0);
   else write8byte(READ1);
   write8byte(address);
   for(i=0;i  <k;i++)
    {
     //rbyte=read8byte();
  DD[i]=read8byte();
    }
   cs=1;
   sck=0;
  }


main()
 {
  uchar dd[2]={0xff,0x22};
  delay(10);
  while((readcom()&0x01)==1) 
  {
  }

  writepage(0x020,0x20,dd,2,1);
  readpage(0x20,2,1);
  } 

发表时间:2004年7月20日12:04:14

  
回复该帖

本主题共有 2 帖,分页:>>>>>该主题的所有内容[2]条

 *树形目录 只列出部分跟帖的标题以及简单的摘要信息 该主题的部分跟帖如下:

  58598.[详细];*The purpose of this code&nb..
摘要:;*The purpose of this code is to provide routines to interface th......(7451字)
- [baolqkun][740次] 2004年7月20日

[上一篇帖子]:有谁用过DS1337啊,进来一下在加电后就开始工作吗? 有相关资料吗? IIC程序。
[下一篇帖子]:How much in  RMB