STC單片機EEPROM讀寫

來源:互聯網
上載者:User

 

//**************************************************************** //  STC單片機EEPROM讀寫--最簡潔的的拿來就用保證沒錯^_^簡潔至上! //---------------------------------------------------------------- //--------------------------------//-------------------------------- //注意:以下為STC89系列的地址 //--------------------------------//-------------------------------- sfr isp_data  = 0xe2;//ISP/IAP操作時的資料寄存器 sfr isp_addrh = 0xe3;//高地址 sfr isp_addrl = 0xe4;//低地址 sfr isp_cmd   = 0xe5;//命令模式寄存器 sfr isp_trig  = 0xe6;//命令觸發寄存器 sfr isp_contr = 0xe7;//ISP/IAP控制寄存器 */ /* //--------------------------------//-------------------------------- //注意:以下為1T新STC系列的地址 //--------------------------------//-------------------------------- sfr isp_data  = 0xc2;//ISP/IAP操作時的資料寄存器 sfr isp_addrh = 0xc3;//高地址 sfr isp_addrl = 0xc4;//低地址 sfr isp_cmd   = 0xc5;//命令模式寄存器 sfr isp_trig  = 0xc6;//命令觸發寄存器 sfr isp_contr = 0xc7;//ISP_IAP控制寄存器 //---------------------------------------------------------------- uchar eeprom_read(uint addres);// void  eeprom_write(uint address,uchar wdata);// void  eeprom_eares(uint addres);//扇區擦除 //**************************************************************** //  扇區擦除 //---------------------------------------------------------------- void eeprom_eares(uint addres) {          uchar i;          isp_addrl=addres;     //低位地址     isp_addrh=addres>>8;  //高位地址     isp_contr=0x01;      isp_contr=isp_contr|0x80; //設時間與充ISP操作。     isp_cmd=0x03;         //扇區命命令     isp_trig=0x46;        //觸發     isp_trig=0xb9;        //觸發啟動。     for(i=0;i<3;i++)         ;     isp_addrl=0xff;     isp_addrh=0xff;     isp_contr=0x00;     isp_cmd=0x00;     isp_trig=0x00;  } //**************************************************************** //  讀資料 //---------------------------------------------------------------- unsigned char eeprom_read(unsigned int addres) {     unsigned char i,z;          isp_addrl=addres;     //低位地址     isp_addrh=addres>>8;  //高位地址     isp_contr=0x01;      isp_contr=isp_contr|0x80; //設時間與充ISP操作。     isp_cmd=0x01;         //寫命令     isp_trig=0x46;        //觸發     isp_trig=0xb9;        //觸發啟動。     for(i=0;i<3;i++)         ;     isp_addrl=0xff;     isp_addrh=0xff;     isp_contr=0x00;     isp_cmd=0x00;     isp_trig=0x00;     z=isp_data;          return(z);         } //**************************************************************** //  寫資料 //---------------------------------------------------------------- void eeprom_write(unsigned int addres,unsigned char write_data) {     unsigned char i;          isp_data=write_data;  //要寫入的資料。     isp_addrl=addres;     //低位地址     isp_addrh=addres>>8;  //高位地址     isp_contr=0x01;      isp_contr=isp_contr|0x80; //設時間與充ISP操作。     isp_cmd=0x02;         //寫命令     isp_trig=0x46;        //觸發     isp_trig=0xb9;        //觸發啟動。     for(i=0;i<3;i++)         ;     isp_addrl=0xff;     isp_addrh=0xff;     isp_contr=0x00;     isp_cmd=0x00;     isp_trig=0x00;   } 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.