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 ;******************************************************************************* *** ......
>>返回讨论的主题
|