导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→发表看法:[白莲]C51编程:25045操作标准子程序集



No.18850
作者:白莲
邮件:BaiKingSolar@163.com
ID:2166
登陆:1次
QQ:8706715
文章数:65篇
最后登陆IP:
最后登陆:2002/5/16 22:08:00
注册:2002/5/16 22:08:00
财富:152
发帖时间:2003/2/14 14:38:00
发贴者IP:210.75.244.150
标题:白莲:C51编程:25045操作标准子程序集
摘要:No.18850C51编程:25045操作标准子程序集 /*
;软 件 标 题:25045操作标准子程序集
;软 件 说 明:25045 I2C 串行EEPROM 驱动
;_________________________________________
*/
/*到现在为止所有的问题都已经解决,此版本已经较为完善*/
# include <stdio.h>
# include <reg52.h>
# define uchar unsigned char
# define uint unsigned int
 sbit SO=P1^1;/*25045输出*/
 sbit SI=P1^2;/*25045输入*/
 sbit SCK=P1^3;/*25045时钟*/
 sbit CS=P1^4;/*25045片选*/
 uchar code WREN_INST=0X06;
 /* Write enable latch instruction (WREN)*/
 uchar code WRDI_INST=0X04;
 /* Write disable latch instruction (WRDI)*/
 uchar code WRSR_INST=0X01;
 /* Write status register instruction (WRSR)*/
 uchar code RDSR_INST=0X05;
 /* Read status register instruction (RDSR)*/
 uchar code WRITE_INST=0X02;
 /* Write memory instruction (WRITE)*/
 /*写入25045的先导字,应当为0000A010,其中的A为写入25045的高位地址
 将此WRITE_INST和写入高位地址相或后即为正确的写先导字*/
 uchar code READ_INST=0X03;
 /* Read memory instruction (READ)*/
 /*读出25045的先导字,应当为0000A011,其中的A为读出25045的高位地址
 将此READ_INST和读出高位地址相或后即为正确的读先导字*/
 uint code BYTE_ADDR=0X55;
 /* Memory address for byte mode operations*/
 uchar code BYTE_DATA=0X11;
 /*Data byte for byte write operation*/
 uint  code PAGE_ADDR=0X1F;
 /* Memory address for page mode operations*/
 /*页面写入的其始地址*/
 uchar code PAGE_DATA1=0X22;
 /* 1st data byte for page write operation*/
 uchar code PAGE_DATA2=0X33;
 /* 2nd data byte for page write operation*/
 uchar code PAGE_DATA3=0X44;
 /* 3rd data byte for page write operation*/
 uchar code STATUS_REG=0X20;
 /* Status register,设置DOG时间设置为200毫秒,无写保护*/
 /*这是状态寄存器的值,他的意义在于第5,第4位为WDI1,WDI0代表DOG的时间,00为1.4秒,01
为600毫秒,10为200毫秒,00为disabled
 第3位和第2位为BL1,BL0,是写保护设置位,00为无保护,01为保护180-1FF,10为保护100-
1FF,11为保护000-1FF.第1位为WEL,
 当他为1时代表已经"写使能"设置了,现在可以写了,只读位.第0位为WIP,当他为1时代表正
在进行写操作,是只读*/
 uchar code  MAX_POLL=0x99;
 /* Maximum number of polls*/
 /*最大写过程时间,确定25045的最大的写入过程的时间*/
 uchar code INIT_STATE=0x09;
 /* Initialization value for control ports*/
 uint code SLIC=0x30;
 /* Address location of SLIC*/
 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 page_write(uchar aa1,uchar aa2,uchar aa3,uchar aa4,uint dd);/*页写入*/
 void sequ_read(void);/*连续读出*/ 
 void rst_wdog(void);/*DOG复位*/
 void outbyt(uchar aa);/*输出一个字节到25045中,不包括先导字等*/
 uchar inputbyt();/*由25045输入一个字节,不包括先导字等额外的东西*/ 
 void wip_poll(void);/*检查写入过程是否结束*/
 
 
/*25045操作子程序集*/
/*;*****************************************************************************
**************
*
;* 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
;* Calls: outbyt
;* Input: None
;* Outputs: None
;* Register Usage: A
;*******************************************************************************
************
*/
/*写使能子程序*/
void wren_cmd(void)
{
 uchar aa;
 SCK=0;/* Bring SCK low */
 CS=0;/* Bring /CS low */
 aa=WREN_INST;
 outbyt(aa);/* Send WREN instruction */
 SCK=0;/* Bring SCK low */
 CS=1;/* Bring /CS high */
}

/*;*****************************************************************************
**************
*
;* Name: WRDI_CMD
;* Description: Reset write enable latch
;* Function: This routine sends the command to disable writes to the EEPROM 
memory array or
;* status register
;* Calls: outbyt
;* Input: None
;* Outputs: None
;* Register Usage: A
;*******************************************************************************
************
*/
/*写使能复位子程序*/
void wrdi_cmd(void)
{
 uchar aa;
 SCK=0;/* Bring SCK low */
 CS=0;/* Bring /CS low */
 aa=WRDI_INST;
 outbyt(aa);/* Send WRDI instruction */
 SCK=0;/* Bring SCK low */
 CS=1;/* Bring /CS high */
}


/*;*****************************************************************************
**************
*
;* Name: WRSR_CMD
;* Description: Write Status Register
;* Function: This routine sends the command to write the WD0, WD1, BP0 and BP0 
EEPROM
;* bits in the status register
;* Calls: outbyt, wip_poll
;* Input: None
;* Outputs: None
;* Register Usage: A
;*******************************************************************************
************
*/
/*写状态寄存器子程序*/
void wrsr_cmd(void)
{
 uchar aa;
 SCK=0;/* Bring SCK low */
 CS=0;/* Bring /CS low */
 aa=WRSR_INST;
 outbyt(aa) ;/* Send WRSR instruction */
 aa=STATUS_REG;
 outbyt(aa);/* Send status register */
 SCK=0;/* Bring SCK low */
 CS=1;/* Bring /CS high */
 wip_poll();/* Poll for completion of write cycle */
}

/*;*****************************************************************************
**************
*
;* 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;
{
 SCK=0;
 CS=0;
 outbyt((((uchar)(dd-0XFF))<<3)|WRITE_INST);/* Send WRITE instruction including 
MSB of address */
 /*将高位地址左移3位与写入先导字相或,得到正确的先导字写入25045*/
 outbyt((uchar)(dd));
 /*输出低位地址到25045 ......

>>返回讨论的主题



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


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

   




老古网执行:31毫秒 最大:5594毫秒 查询6次