新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 25045操作標(biāo)準(zhǔn)子程序

25045操作標(biāo)準(zhǔn)子程序

作者: 時(shí)間:2011-05-17 來源:網(wǎng)絡(luò) 收藏

25045

本文引用地址:http://butianyuan.cn/article/150741.htm

# 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時(shí)鐘*/
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的先導(dǎo)字,應(yīng)當(dāng)為0000A010,其中的A為寫入25045的高位地址
將此WRITE_INST和寫入高位地址相或后即為正確的寫先導(dǎo)字*/
uchar code READ_INST=0X03;
/* Read memory instruction (READ)*/
/*讀出25045的先導(dǎo)字,應(yīng)當(dāng)為0000A011,其中的A為讀出25045的高位地址
將此READ_INST和讀出高位地址相或后即為正確的讀先導(dǎo)字*/
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,設(shè)置DOG時(shí)間設(shè)置為200毫秒,無寫保護(hù)*/
/*這是狀態(tài)寄存器的值,他的意義在于第5,第4位為WDI1,WDI0代表DOG的時(shí)間,00為1.4秒,01為600毫秒,10為200毫秒,00為disabled
第3位和第2位為BL1,BL0,是寫保護(hù)設(shè)置位,00為無保護(hù),01為保護(hù)180-1FF,10為保護(hù)100-1FF,11為保護(hù)000-1FF.第1位為WEL,
當(dāng)他為1時(shí)代表已經(jīng)寫使能設(shè)置了,現(xiàn)在可以寫了,只讀位.第0位為WIP,當(dāng)他為1時(shí)代表正在進(jìn)行寫,是只讀*/
uchar code MAX_POLL=0x99;
/* Maximum number of polls*/
/*最大寫過程時(shí)間,確定25045的最大的寫入過程的時(shí)間*/
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);/*寫使能復(fù)位*/
void wrsr_cmd(void);/*復(fù)位時(shí)間位和數(shù)據(jù)保護(hù)位寫入狀態(tài)寄存器*/
uchar rdsr_cmd(void);/*讀狀態(tài)寄存器*/
void byte_write(uchar aa,uint dd);/*字節(jié)寫入,aa為寫入的數(shù)據(jù),dd為寫入的地址*/
uchar byte_read(uint dd);/*字節(jié)讀出,dd為讀出的地址,返回讀出的數(shù)據(jù)*/
void page_write(uchar aa1,uchar aa2,uchar aa3,uchar aa4,uint dd);/*頁寫入*/
void sequ_read(void);/*連續(xù)讀出*/
void rst_wdog(void);/*DOG復(fù)位*/
void outbyt(uchar aa);/*輸出一個(gè)字節(jié)到25045中,不包括先導(dǎo)字等*/
uchar inputbyt();/*由25045輸入一個(gè)字節(jié),不包括先導(dǎo)字等額外的東西*/
void wip_poll(void);/*檢查寫入過程是否結(jié)束*/


/*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
;***********************************************************
*/
/*寫使能復(fù)位子程序*/
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
;********************************************
*/
/*寫狀態(tài)寄存器子程序*/
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
;*******************************************************
*/
/*讀狀態(tài)寄存器,讀出的數(shù)據(jù)放入到aa中*/
uchar rdsr_cmd (void)
{
uchar aa;
SCK=0;
CS=0;
aa=RDSR_INST;
outbyt(aa);
aa=inputbyt();
SCK=0;
CS=1;
return aa;
}


上一頁 1 2 3 下一頁

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉