导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→发表看法:[QZMARS]初学者:谁能帮我看一下以下x25045程



No.15893
作者:QZMARS
邮件:waveshot@vip.sina.com
ID:4357
登陆:5次
文章数:3篇
最后登陆IP:220.162.55.170
最后登陆:2005/12/28 15:37:46
注册:2002/10/7 19:42:00
财富:29
发帖时间:2002/12/16 16:59:00
发贴者IP:218.66.179.9
标题:QZMARS:初学者:谁能帮我看一下以下x25045程序问题出在哪?数据写不进去!我的MAIL:waveshot@vip.sina.com
摘要:No.15893初学者:谁能帮我看一下以下x25045程序问题出在哪?数据写不进去!我的MAIL:waveshot@vip.sina.com #define uchar unsigned char
#define uint  unsigned int
sbit CS_X25=0x90;
sbit SO=0x91;
sbit SCK=0x92;
sbit SI=0x93;
sfr  p1=0x90;

/*******************************************************************************
****
********************************************************************************
****
      Following routines use to operate X25045 

    ADDR_STATUS_READ
    7   6   5   4   3   2   1   0
    X   X  WD1 WD0 BL1 BL0 WEL WIP --- 正在写
            |   |   |   |   +--------- 写使能
            |   |   |---+-写保护------ 00:无    01:180~1FFH  10: 100~1FFH  
11:000~1FFH
            |---+---------看门狗------ 00:1.4S  01:0.6S      10: 0.2S      11 
Disable

/******************************* X25045 Functions 
***********************************/
#define WREN 0x06                   /* Write enable latch instruction 
(WREN)*/
#define WRDI 0x04                      /* Write disable latch instruction 
(WRDI)*/
#define RDSR 0x05                   /* Read status register instruction 
(RDSR)*/
#define WRSR 0x01                   /* Write status register instruction 
(WRSR)*/
#define WRITE_LOW 0x02              /* Write memory instruction 0x00 to 
0xFF (WRITE)*/
#define WRITE_HIGH 0x0A             /* Write memory instruction 0x100 to 
0x1FF(WRITE)*/ 
#define READ_LOW 0x03               /* Read memory instruction 0x00 to 
0xFF(READ)*/
#define READ_HIGH 0x0B              /* Read memory instruction 0x100 to 
0x1FF(READ)*/  
#define STATUS_REG 0x20             /* Status register,设置DOG时间设置为
200毫秒,无写保护*/
#define MAX_POLL 0x99                  /* Maximum number of polls*/
                                     /*最大写过程时间,确定25045的最大的写
入过程的时间*/
void wren_cmd(void);                 /*写使能子程序*/
void wrdi_cmd(void);                 /*写使能复位*/ 
void wrsr_cmd(void);                 /*复位时间位和数据保护位写入状态寄存
器*/ 
uchar rdsr_cmd(void);                /*读状态寄存器*/
void byte_write(uchar aa,uint dd);  /*字节写入,aa为写入的数据,dd为写入的地址*/
uchar byte_read(uint dd);           /*字节读出,dd为读出的地址,返回读出的数据*/
void rst_wdog(void);                 /*DOG复位*/
void outbyte(uchar aa);               /*输出一个字节到25045中,不包括先导字
等*/
uchar inputbyte();                    /*由25045输入一个字节,不包括先导字等
额外的东西*/ 
void wip_poll(void);                 /*检查写入过程是否结束*/
void delay(uchar x);

/*void CS_X25(bit i){
if(i)
{p25=0;p26=1;p27=1;}
else
{p25=0;p26=0;p27=0;}
delay(1);}
/*25045操作子程序集*/
/*;*****************************************************************************
**************
*
;* Name: WIP_POLL
;* Description: Write-In-Progress Polling
;* Function: This routine polls for completion of a nonvolatile write cycle by 
examining the
;* WIP bit of the status register
;*******************************************************************************
************
*/
/*检测写入的过程是否结束*/
void wip_poll(void){
 uchar aa;
 uchar idata my_flag;
 for(aa=1;aa<MAX_POLL;aa++)
   {
     my_flag=rdsr_cmd();   
     if((my_flag&0x01)==0) aa=MAX_POLL; /*判断是否WIP=0,即判断是否写入过程已经结
束,若结束就跳出,否则继续等待直到达到最大记数值*/
   }
}

/*;*****************************************************************************
**************
;* Name: outbyte
;* Description: Sends byte to EEPROM
;* Function: This routine shifts out a byte, starting with the MSB, to the 
EEPROM
;*******************************************************************************
**************/
void outbyte(uchar datu)
{
 uchar i;
 for (i=0;i<0;i++)
 { 
   SCK=0;               /* Data input on the SI line is latched on the rising 
edge of SCK */
   delay(1);
   SI=(bit)(datu&0x80);
   datu=datu<<1;
   SCK=1;
   delay(1);
 }
 SI=0;        /*使X25_SDA处于确定的状态*/ 
}

/*;*****************************************************************************
**************
;* Name: inputbyte
;* Description: Recieves byte from EEPROM
;* Function: This routine recieves a byte, MSB first, from the EEPROM
;*******************************************************************************
**************/
uchar inputbyte(void)
{
 uchar aa,my_flag;
 char i;
 for (i=7;i<0;i--)
 { 
   SCK=1;       /*Data is output on the SO line by the falling edge of SCK */
   delay(1);
   SCK=0;
   delay(1);
   my_flag=(uchar)(SO);
   aa=(aa|(my_flag<<i));
   my_flag=0x00;
 }
 return aa;
}
/*;*****************************************************************************
**************
;* Name: WREN_CMD
;* Description: Set write enable latch
;* Function: This routine sends the command to enable writes to the EEPROM 
memory array or
;* status register
;*******************************************************************************
*** ......

>>返回讨论的主题



  发表回复
用户名   *您没有注册?
密码   *
验证码   * .
标题   *
心情
随便说说    我回答你    最新发现    得意的笑   
气死我了    真是没劲    坚决同意    表示反对   
大家过来    好奇怪哟    懒得理它    大家小心   
文件上传
内容


字体:      字体大小:    颜色:
粗体 斜体 下划线 居中 超级连接 Email连接 图片 Flash图片 Shockwave文件 realplay视频文件 Media Player视频文件 QuickTime视频文件 引用 飞行字 移动字 发光字 阴影字 查看更多的心情图标 背景音乐
点击加入表情
                         
选项
有回复时用短消息通知您?

   




老古网执行:47毫秒 最大:7276毫秒 查询6次