<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51單片機(jī)資源擴(kuò)展:擴(kuò)展片外RAM

          51單片機(jī)資源擴(kuò)展:擴(kuò)展片外RAM

          作者: 時間:2016-11-19 來源:網(wǎng)絡(luò) 收藏
          51單片機(jī)資源擴(kuò)展:從片內(nèi)ROM跳轉(zhuǎn)到片外ROM 一文中擴(kuò)展了單片機(jī)程序存儲器,4KB存儲空間提升到64KB。其實(shí),4K的代碼空間還湊合,但是51自帶的256B數(shù)據(jù)存儲空間使用起來還真緊張,其中留給用戶的連128B都不到,所以不得不擴(kuò)展片外RAM。擴(kuò)展RAM方法和擴(kuò)展ROM差不多,都是占用P0/P2口做地址線,同時P0用鎖存器74373分時復(fù)用地址和數(shù)據(jù)信號。

          以前擴(kuò)展RAM是用匯編語言訪問存儲器,好處是定位精準(zhǔn),指哪打哪,壞處就是:程序規(guī)模一大就有點(diǎn)難維護(hù)了,所以還得改用C實(shí)現(xiàn)。

          本文引用地址:http://www.ex-cimer.com/article/201611/318425.htm

          對應(yīng)于匯編語言用R1,R0/DPTR訪問外部RAM,keil C擴(kuò)展了存儲類型,增加了如pdata(等同用movx @Rn訪問方式)/xdata(等同于movx @DPTR訪問方式)存儲類型用于訪問片外ram。同時,還提供了絕對地址訪問的宏,如PBYTE/XBYTE,查看定義:

          #define PBYTE((unsigned char volatile pdata*)0);#define XBYTE((unsigned char volatile xdata*)0);

          其實(shí),也還是定義相應(yīng)存儲類型的指針~。

          上仿真圖和代碼前,整理一下keil c提供訪問絕對地址的方法:

          1._at_定義變量:

          變量類型 [存儲類型] 變量名 _at_ 常數(shù),指定變量存放在常數(shù)所指定的ram位置,注意bit型變量不能使用_at_指定位置;

          2.絕對地址訪問:

          頭文件absacc.h提供了絕對地址訪問宏,用于字節(jié)/字尋址,如

          val=XBYTE[0x0000];讀片外ram 0x00處內(nèi)存值

          XBYTE[0x0200]=val;寫片外ram 0x0200處內(nèi)存值

          擴(kuò)展ram仿真圖:

          上段去年用匯編寫的訪問ram的代碼:

          ORG  0SJMP  STARTORG  10HSTART:;1456是要訪問的內(nèi)存地址MOV  DPTR,#1456H;MOV  A,  #0FFH;;0xFF移入[1456]MOVX @DPTR,A;CLR  A;MOVX  A, @DPTR; ;對外部RAM 1456H讀出數(shù)據(jù)到ANOPMOV  A, #0A0H;INC  DPLMOVX @DPTR,A; ;將0xA0寫入外部RAM 1457HNOP;從外部RAM [1457]H讀出數(shù)據(jù)到AMOVX  A, @DPTR; NOPSJMP STARTEND
          c語言版本:

          #include #include #define OFFRAMBASE 0x100unsigned char xdata offRamVal0 _at_ OFFRAMBASE*2;unsigned char xdata offRamVal1 _at_ 0x00;int main(){unsigned char idata index = 0;offRamVal0 = 0xAA;offRamVal1 = 0xCC;for(index=0;index<0x10;index++){XBYTE[index+OFFRAMBASE] = 0x55;	}		return 0;}
          最后看下程序運(yùn)行后6264內(nèi)部存儲的數(shù)據(jù):
          0000: CC 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................00A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................00B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................00C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................00D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................00E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................00F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................0100: 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 | UUUUUUUUUUUUUUUU0110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................0120: 00 00 00 00 00 00 00 00 00 00 0001E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................01F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................0200: AA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 | ................


          評論


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

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();