您当前的位置:五五电子网电子知识单片机-工控设备51单片机基于C51的X25045/X5045标准函数集 正文
基于C51的X25045/X5045标准函数集

基于C51的X25045/X5045标准函数集

点击数:7230 次   录入时间:03-04 11:50:32   整理:http://www.55dianzi.com   51单片机
CS=1;/* Bring /CS high */
wip_poll();/* Poll for completion of write cycle */

wrdi_cmd();//写使能复位,其实这句可以省略,每写一次就自动复位
}





/*;*************************************************************************
*
;* Name: RDSR_CMD
;* Description: Read Status Register
;* Function: This routine sends the command to read the status register
;* Calls: outbyt, inputbyt
;* Input: None
;* Outputs: A = status registerXicor Application Note AN21
;* Register Usage: A
;********************************************************************
*/
/*读状态寄存器,读出的数据放入到aa中*/
uchar rdsr_cmd (void)
{
uchar aa;
SCK=0;
CS=0;
aa=RDSR_INST;
outbyt(aa);
aa=inputbyt();
SCK=0;
CS=1;
return aa;
}







/*;**********************************************************************
*
;* Name: BYTE_WRITE
;* Description: Single Byte Write
;* Function: This routine sends the command to write a single byte to the EEPROM memory
array
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A, B
;***************************************************************
*/
/*字节写入,aa为写入的数据,dd为写入的地址,对于25045而言为000-1FF*/
void byte_write(aa,dd)
uchar aa;
uint dd;
{
uchar tmp;

wren_cmd();//写使能子程序

SCK=0;
CS=0;
if(dd>0xff)
    tmp =  WRITE_INST | 0x08;
else
    tmp = WRITE_INST;
outbyt(tmp);/* Send WRITE instruction including MSB of address */
/*将高位地址左移3位与写入先导字相或,得到正确的先导字写入25045*/
outbyt((uchar)(dd&0xff));
/*输出低位地址到25045*/
outbyt(aa);
/*写入数据到25045的对应单元*/
SCK=0;
CS=1;
wip_poll();
/*检测是否写完*/

wrdi_cmd();//写使能复位,其实这句可以省略,每写一次就自动复位
}



/*;***********************************************************************
*
;* Name: BYTE_READ
;* Description: Single Byte Read
;* Function: This routine sends the command to read a single byte from the EEPROM memory
array
;* Calls: outbyt, inputbyt
;* Input: None
;* Outputs: A = read byte
;* Register Usage: A, BXicor Application Note AN21
;*********************************************************************
*/
/*字节读出,其中dd为读出的地址,返回的值为读出的数据*/
uchar byte_read(dd)
uint dd;
{
uchar cc,tmp;
SCK=0;
CS=0;
if(dd>0xff)
    tmp =  READ_INST | 0x08;
else
    tmp = READ_INST;
outbyt(tmp);/* Send READ_INST instruction including MSB of address */
/*将高位地址左移3位与读出先导字相或,得到正确的先导字写入25045*/
outbyt((uchar)(dd&0xff));
/*输出低位地址到25045*/
cc=inputbyt();/*得到读出的数据*/
SCK=0;
CS=1;
return cc;
}


/*;**********************************************************************
*
;* Name: PAGE_WRITE
;* Description: Page Write
;* Function: This routine sends the command to write three consecutive bytes to the EEPROM
;* memory array using page mode
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A, B
;**************************************************************************
*/
/*页面写入,其中aa1,aa2,aa3,aa4为需要写入的4个数据(最大也就只能一次写入4个字,dd为写入的首地址*/
void page_write(aa1,aa2,aa3,aa4,dd)
uchar aa1,aa2,aa3,aa4;
uint dd;
{
SCK=0;
CS=0;
outbyt((((uchar)(dd-0XFF))<<3)|WRITE_INST);// Send WRITE instruction including MSB of address
//将高位地址左移3位与写入先导字相或,得到正确的先导字写入25045
outbyt((uchar)(dd));
//写入低位地址到25045
outbyt(aa1);
//写入数据1到25045的对应单元
outbyt(aa2);
//写入数据2到25045的对应单元
outbyt(aa3);
//写入数据3到25045的对应单元
outbyt(aa4);
//写入数据4到25045的对应单元
SCK=0;
CS=1;
wip_poll();
}




/*;**********************************************
*
;* Name: SEQU_READ
;* Description: Sequential Read
;* Function: This routine sends the command to read three consecutive bytes from the EEPROM
;* memory array using sequential mode
;* Calls: outbyt, inputbyt
;* Input: None
;* Outputs: A = last byte read
;* Register Usage: A, B
;************************************************************
*/
/*连续读出,由于函数的返回值只能为1个,对于连续读出的数据只能使用指针作为函数的返回值才能做到返回一系列的数组*/
//sequ_read:
unsigned int *page_read(n,dd)
uchar n;//n是希望读出的数据的个数,n<=11
unsigned int dd;//dd是读出数据的首地址
{
uchar i;
uchar pp[10];
unsigned int *pt=pp;
SCK=0;
CS=0;
outbyt((((uchar)(dd-0XFF))<<3)|READ_INST);
for (i=0;i<n;i++)
{
   pp[i]=inputbyt();
}
return (pt);
}
/*调用的方法如下
unsigned int *p;
p=page_read(4,100);
a=*(p)  
b=*(p+1)
c=*(p+2)
d=*(p+3)
//abcd中存放25045中由100地址开始的4个数据
*/
/* Send WRITE
mov DPTR, #PAGE_ADDR ; Set address of 1st byte to be read
clr sck ; Bring SCK low
clr cs ; Bring /CS low
mov A, #READ_INST
mov B, DPH
mov C, B.0
mov ACC.3, C
lcall outbyt ; Send READ instruction with MSB of address
mov A, DPL
lcall outbyt ; Send low order address byte
lcall inputbyt ; Read 1st data byte
lcall inputbyt ; Read 2nd data byte
lcall inputbyt ; Read 3rd data byte
clr sck ; Bring SCK low
setb cs ; Bring /CS high
ret*/




/*;*********************************************************************
*
;* Name: RST_WDOG
;* Description: Reset Watchdog Timer
;* Function: This routine resets the watchdog timer without sending a command
;* Calls: None
;* Input: None
;* Outputs: None
;* Register Usage: None
;***********************************************************************
*/
/*复位DOG*/
void rst_wdog (void)
{
CS=0;
CS=1;
}





/*;************************************************************************
*
;* 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
;* Calls: rdsr_cmdXicor Application Note AN21
;* Input: None
;* Outputs: None
;* Register Usage: R1, A
;************************************************************************
*/
/*检测写入的过程是否结束*/
void wip_poll(void)
{
uchar aa;
uchar my_flag;
for (aa=0;aa<MAX_POLL;aa++)
{
  my_flag=rdsr_cmd();
  if ((my_flag&0x01)==0) {aa=MAX_POLL;}/*判断是否WIP=0,即判断是否写入过程已经结束,若结束就跳出,否则继续等待直到达到最大记数值*/
}
//aa=1;
//while(aa){
//   my_flag=rdsr_cmd();
//   if ((my_flag&0x01)==0){
//      aa=0;/*判断是否WIP=0,即判断是否写入过程已经结束,若结束就跳出,否则继续等待直到达到最大记数值*/
//   }
//}
aa = 0;
}




/*;**************************************************************************
*
;* 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
;* Outputs: None
;* Register Usage: R0, A
;***********************************************************************
*/
/*输出一个数据到25045,此数据可能为地址,先导字,写入的数据等*/
void outbyt(aa)
uchar aa;
{
uchar my_flag1,my_flag2,i;
my_flag1=aa;

上一页  [1] [2] [3]  下一页


本文关键字:暂无联系方式51单片机单片机-工控设备 - 51单片机