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

 *第23901篇: 关于25045的问题!急!

  
楼 主:longxiuwei 2004年7月20日12:04
 关于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);
  } 

  
2楼:baolqkun 2004年7月20日21:12
 ;*The purpose of thi
;*The purpose of this code is to provide routines to interface the xicor x 25043 with the 8031
;*micorcontroller.The interface uses the 8031's general purpose parallel port 1 adn connects
;*p1.0 to the chip select line(/cs),p1.1 to the serial input data line(si),p1.2 to the
;*serial clock line (sck) and p1.3 to the serial output data line(so).
;*
;*All x25045 commands are provided. these are :-
;
;1. set write enable latch
;2. reset write enable latch
;3. write status register
;4. read status register
;5. signle byte read
;6. signle byte read
;7. page write
;8. sequential read
;9. reset watchdog timer
;
;*this code writes 00h to the status register; reads the status register; writes 11h to 
;*address 55h in byte mode;performs a single byte read from address 55h,writes 22h
;*33h,44h,to addresses 1f0h, 1f1h, 1f2h in page mode; performs a sequential read
;*from addresses 1f0h, 1f2h; and resets watchdog timer. this code can also be used with 
;*the x25045 which is identical to the x25045,except for its reset output polarity
;************************************************
;*constants

cs  bit p2.2
si  bit p2.0 
sck  bit p2.1
so  bit p1.7
wren_inst equ 06h
wrdi_inst equ 04h
wrsr_inst equ 01h
rdsr_inst equ 05h
write_inst equ 02h
read_inst equ 03h
byte_addr equ  99h
byte_data equ 5ah
page_addr equ 1f0h
page_data1 equ 22h
page_data2 equ 33h
page_data3 equ 44h
status_reg equ  00h
max_poll equ 99h
init_state equ 08h
inis_state equ 00h
slic  equ 030h

;************************************************
;*interal ram
stack_top equ 060h

;************************************************
;*code

 org 0000h
 ljmp main

 org 0100h
main: 
 mov sp,#stack_top
 clr ea
 setb so
 setb cs
 clr sck
 clr si
 lcall wren_cmd
 lcall wrsr_cmd
 lcall wren_cmd
 lcall byte_write
 lcall byte_read
 lcall wren_cmd
 lcall page_write
 lcall sequ_read
 lcall rst_wdog
 jmp main

;*****************************
;*name: wren_cmd
;*descritpion: set write enable latch
;*function:this routine sends the command to enable writes to the eeprom memory array or
;*status register
;*calls: outbyt
;*input: none
;*output:none
;*register usage: a
;****************************
wren_cmd:
 clr sck
 nop
 clr cs
 nop
 mov a,#wren_inst
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 ret

;****************************
;*name: wrdi_cmd
;*description:reset write enable latch
;*function:this routine sends the commond to disable writes to the eeprom memory array or
;*status register
;*calls: outbyt
;*input: none
;*output: none
;*register usage: a
;****************************
wrdi_cmd:
 clr sck
 nop
 clr cs
 nop
 mov a,#wrdi_inst
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 ret 

;****************************
;*name: wrsr_cmd
;*description: write status register
;*function:this routine sends the command to write the wd0,wd1,bpo and bp0 eeprom
;*bits in the status register
;*call: outbyt,wip_poll
;*input: none
;*output: none
;*register usage: a
;***************************
wrsr_cmd:
 clr sck
 nop
 clr cs
 nop
 mov a,#wrsr_inst
 lcall outbyt
 mov a,#status_reg
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 lcall wip_poll
 ret

;***************************
;*name: rdsr_cmd
;*description: read status register
;*function: this routine sends the command to read the status register
;*call: outbyt, inbyt
;*input: none
;*output: a=status register
;*register usage: a
;***************************
rdsr_cmd:
 clr sck
 nop
 clr cs
 nop
 mov a,#rdsr_inst
 lcall outbyt
 lcall inbyt
 clr sck
 nop
 setb cs
 nop
 ret

;***************************
;*name: byte_write
;*description: signle byte write
;*funtion:this routine sends the command to write a signle byte to the eeprom memory array
;*calls: outbyt, wip_poll
;*input: none
;*output: none
;*register usage: a,b
;**************************
byte_write:
 mov dptr,#byte_addr
 clr sck
 nop
 clr cs
 nop
 mov a,#write_inst
 mov b,dph
 mov c,b.0
 mov acc.3,c
 lcall outbyt
 mov a,dpl
 lcall outbyt
 mov a,#byte_data
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 lcall wip_poll
 ret

;******************************
;*name: byte_read
;*description: signle byte read
;*function: this routine sends the commond to read a signle byte from the eeprom momery array
;*calls: outbyt, inbyt
;*input: none
;*output: a=read byte
;*register usage: a,b
;*****************************
byte_read:
 mov dptr,#byte_addr
 clr sck
 nop
 clr cs
 nop
 mov a,#read_inst
 mov b,dph
 mov c,b.0
 mov acc.3,c
 lcall outbyt
 mov a,dpl
 lcall outbyt
 lcall inbyt
 clr sck
 nop
 setb cs
 nop
 ret

;*****************************
;*name: page_write
;*description: page write
;*function: this routine sends the commond to write three consecutive bytes to the eeprom
;*memory array using page mode
;*calls: outbyt,wip_poll
;*input:none
;*output:none
;*register usage: a, b
;****************************
page_write:
 mov dptr,#page_addr
 clr sck
 nop
 clr cs
 nop
 mov a,#write_inst
 mov b,dph
 mov c,b.0
 mov acc.3,c
 lcall outbyt
 mov a,dpl
 lcall outbyt
 mov a,#page_data1
 lcall outbyt
 mov a,#page_data2
 lcall outbyt
 mov a,#page_data3
 lcall outbyt
 clr sck
 nop
 setb cs
 nop
 lcall wip_poll
 ret

;*******************************
;*name: sequ_read
;*description: sequential read
;*function: this routine sends the command to read three consecutive bytes from the 
;*memory array using sequential mode
;*calls: outbyt, inbyt
;*input: none
;*output:a=last byte read
;*register usage: a,b
;******************************
sequ_read:
 mov dptr,#page_addr
 clr sck
 nop
 clr cs
 nop
 mov a,#read_inst
 mov b,dph
 mov c,b.0
 mov acc.3,c
 lcall outbyt
 mov a,dpl
 lcall outbyt
 lcall inbyt
 lcall inbyt
 lcall inbyt
 clr sck
 nop 
 setb cs
 nop
 ret

;******************************
;*name: rst_wdog
;*description: reset watchdog timer
;*function : this routine resets the watchdog timer without sending a command
;*call: none
;*input: none
;*output: none
;*register usage: none
;*****************************
rst_wdog:
 clr cs
 nop
 setb cs
 ret

;*****************************
;*name: wip_poll
;*description: write-in-progress polling
;*function: this routine polls for completion of a nonvolatile write cycle by examine
;*wip bit of the status register
;*calls: rdsr_cmd
;*input: none
;*output: none
;*register usage:r1,a
;*****************************
wip_poll: 
 mov r1,#max_poll
wip_poll1:
 lcall rdsr_cmd
 jnb acc.0,wip_poll2
 djnz r1,wip_poll1
wip_poll2:
 ret

;*****************************
;*name: outbyt
;*description: sends byte to eeprom
;*function: this routine shifts out a byte,starting with the msb, to the eeprom
;*calls: none
;*input: a=byte to be sent
;*output: none
;*register usage: r0,a
;*****************************
outbyt:
 mov r0,#08
outbyt1:
 clr sck
 rlc a
 mov si,c
 setb sck
 djnz r0,outbyt1
 clr si
 ret

;****************************
;*name: inbyt
;*description: receives byte from eeprom
;*function: this routine receives a byte ,msb first from the eeprom
;*calls: none
;*input: none
;*output: a=revceive byte
;*register usage: r0,a
;***************************
inbyt: 
 mov r0,#08
inbyt1: 
 setb sck
 nop
 clr sck
 mov c,so
 rlc a
 djnz r0,inbyt1
 ret
 
 END


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

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


[上一篇主题]:有谁用过DS1337啊,进来一下

[下一篇主题]:高薪招聘数字电路单片机开发工程师