新聞中心

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

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

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

/*;*******************************************************
*
;* 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
;**********************************************************
*/
/*字節(jié)寫入,aa為寫入的數(shù)據(jù),dd為寫入的地址,對(duì)于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位與寫入先導(dǎo)字相或,得到正確的先導(dǎo)字寫入25045*/
outbyt((uchar)(dd));
/*輸出低位地址到25045*/
outbyt(aa);
/*寫入數(shù)據(jù)到25045的對(duì)應(yīng)單元*/
SCK=0;
CS=1;
wip_poll();
/*檢測(cè)是否寫完*/
}

/*;********************************************************
*
;* 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
;********************************************************
*/
/*字節(jié)讀出,其中dd為讀出的地址,返回的值為讀出的數(shù)據(jù)*/
uchar byte_read(dd)
uint dd;
{
uchar cc;
SCK=0;
CS=0;
outbyt((((uchar)(dd-0XFF))3)|READ_INST);/* Send READ_INST instruction including MSB of address */
/*將高位地址左移3位與讀出先導(dǎo)字相或,得到正確的先導(dǎo)字寫入25045*/
outbyt((uchar)(dd));
/*輸出低位地址到25045*/
cc=inputbyt();/*得到讀出的數(shù)據(jù)*/
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
;*****************************************************
*/
/*頁(yè)面寫入,其中aa1,aa2,aa3,aa4為需要寫入的4個(gè)數(shù)據(jù)(最大也就只能一次寫入4個(gè)字,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位與寫入先導(dǎo)字相或,得到正確的先導(dǎo)字寫入25045*/
outbyt((uchar)(dd));
/*寫入低位地址到25045*/
outbyt(aa1);
/*寫入數(shù)據(jù)1到25045的對(duì)應(yīng)單元*/
outbyt(aa2);
/*寫入數(shù)據(jù)2到25045的對(duì)應(yīng)單元*/
outbyt(aa3);
/*寫入數(shù)據(jù)3到25045的對(duì)應(yīng)單元*/
outbyt(aa4);
/*寫入數(shù)據(jù)4到25045的對(duì)應(yīng)單元*/
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
;*********************************************************
*/
/*連續(xù)讀出,由于函數(shù)的返回值只能為1個(gè),對(duì)于連續(xù)讀出的數(shù)據(jù)只能使用指針作為函數(shù)的返回值才能做到返回一系列的數(shù)組*/
/*sequ_read:*/
unsigned int *page_read(n,dd)
uchar n;/*n是希望讀出的數(shù)據(jù)的個(gè)數(shù),n=11*/
unsigned int dd;/*dd是讀出數(shù)據(jù)的首地址*/
{
uchar i;
uchar pp[10];
unsigned int *pt=pp;
SCK=0;
CS=0;
outbyt((((uchar)(dd-0XFF))3)|READ_INST);
for (i=0;in;i++)
{
pp[i]=inputbyt();
}
return (pt);
}
/*調(diào)用的方法如下*/
/*unsigned int *p;*/
/*p=page_read(4,100);*/
/*a=*(p)*/
/*b=*(p+1)*/
/*c=*(p+2)*/
/*d=*(p+3)*/
/*abcd中存放25045中由100地址開始的4個(gè)數(shù)據(jù)*/
/* 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



評(píng)論


相關(guān)推薦

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

關(guān)閉