新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 25045操作標準子程序

        25045操作標準子程序

        作者: 時間:2011-05-17 來源:網絡 收藏

        /*;*******************************************************
        *
        ;* 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*/
        outbyt(aa);
        /*寫入數據到25045的對應單元*/
        SCK=0;
        CS=1;
        wip_poll();
        /*檢測是否寫完*/
        }

        /*;********************************************************
        *
        ;* 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;
        SCK=0;
        CS=0;
        outbyt((((uchar)(dd-0XFF))3)|READ_INST);/* Send READ_INST instruction including MSB of address */
        /*將高位地址左移3位與讀出先導字相或,得到正確的先導字寫入25045*/
        outbyt((uchar)(dd));
        /*輸出低位地址到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;in;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



        關鍵詞: 子程序 標準 操作

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 常熟市| 印江| 云浮市| 金塔县| 和田市| 宝应县| 曲麻莱县| 天峨县| 宕昌县| 肇东市| 祁阳县| 固原市| 汾西县| 贵溪市| 大名县| 河北区| 河曲县| 西吉县| 车险| 扎鲁特旗| 滨海县| 河北区| 合作市| 宜宾市| 潞城市| 东方市| 南靖县| 健康| 蓝山县| 五家渠市| 永顺县| 泰安市| 泸西县| 库伦旗| 巧家县| 定兴县| 长治县| 缙云县| 吉首市| 札达县| 竹北市|