STC MCU EEPROM read and write

Publisher:未来感觉Latest update time:2017-01-10 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

//************************************************ ****************   

// STC MCU EEPROM reading and writing--the simplest one, just use it and it will work. ^_^ Simplicity comes first!   

//------------------------------------------------ ----------------   

  

//--------------------------------//------------- ------------------   

//Note: The following are the addresses of the STC89 series   

//--------------------------------//------------- ------------------   

  

sfr isp_data = 0xe2; //Data register for ISP/IAP operation   

sfr isp_addrh = 0xe3; //high address   

sfr isp_addrl = 0xe4; //low address   

sfr isp_cmd = 0xe5; // Command mode register   

sfr isp_trig = 0xe6; // Command trigger register   

sfr isp_contr = 0xe7; //ISP/IAP control register   

*/   

/*   

//--------------------------------//------------- ------------------   

//Note: The following is the address of the 1T new STC series   

//--------------------------------//------------- ------------------   

sfr isp_data = 0xc2; //Data register for ISP/IAP operation   

sfr isp_addrh = 0xc3; //high address   

sfr isp_addrl = 0xc4; //low address   

sfr isp_cmd = 0xc5; // Command mode register   

sfr isp_trig = 0xc6; // Command trigger register   

sfr isp_contr = 0xc7; //ISP_IAP control register   

  

//------------------------------------------------ ----------------   

uchar eeprom_read(uint addres);//   

void eeprom_write(uint address,uchar wdata);//   

void eeprom_eares(uint addres); // sector erase   

//************************************************ ****************   

// sector erase   

//------------------------------------------------ ----------------   

void eeprom_eares(uint addres)   

{        

    uchar i;   

       

    isp_addrl=addres; //low address   

    isp_addrh=addres>>8; //high address   

    isp_contr=0x01;    

    isp_contr=isp_contr|0x80; //Set time and charge ISP operation.   

    isp_cmd=0x03; //sector command   

    isp_trig=0x46; //trigger   

    isp_trig=0xb9; //Trigger start.   

    for(i=0;i<3;i++)   

        ;   

    isp_addrl=0xff;   

    isp_addrh=0xff;   

    isp_contr=0x00;   

    isp_cmd=0x00;   

    isp_trig=0x00;    

}   

//************************************************ ****************   

// Read data   

//------------------------------------------------ ----------------   

unsigned char eeprom_read(unsigned int addres)   

{   

    unsigned char i,z;   

       

    isp_addrl=addres; //low address   

    isp_addrh=addres>>8; //high address   

    isp_contr=0x01;    

    isp_contr=isp_contr|0x80; //Set time and charge ISP operation.   

    isp_cmd=0x01; //write command   

    isp_trig=0x46; //trigger   

    isp_trig=0xb9; //Trigger start.   

    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);           

}   

//************************************************ ****************   

// Write data   

//------------------------------------------------ ----------------   

void eeprom_write(unsigned int addres,unsigned char write_data)   

{   

    unsigned char i;   

       

    isp_data=write_data; //Data to be written.   

    isp_addrl=addres; //low address   

    isp_addrh=addres>>8; //high address   

    isp_contr=0x01;    

    isp_contr=isp_contr|0x80; //Set time and charge ISP operation.   

    isp_cmd=0x02; //write command   

    isp_trig=0x46; //trigger   

    isp_trig=0xb9; //Trigger start.   

    for(i=0;i<3;i++)   

        ;   

    isp_addrl=0xff;   

    isp_addrh=0xff;   

    isp_contr=0x00;   

    isp_cmd=0x00;   

    isp_trig=0x00;     

}   


Reference address:STC MCU EEPROM read and write

Previous article:Application of SD card in microcontroller
Next article:STC89C58 serial port receives GPS signal

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号