STC 89c51 Series EEPROM test procedure

Source: Internet
Author: User

1 Test procedure

2 Certification Procedures




1

/* Microcontroller built-in  eeprom test program for   stc89c51stc89c52stc89c53stc89c54stc89c58stc89c510stc89c512stc89c514 Test Crystal oscillator:11.05926m 12m  can be used   Function: Reads a byte content of the specified address, and displays the erase of a sector on the 8&NBSP;P1 bus, modifies a byte content of the specified address, and displays it on the 8&NBSP;P1 bus */#include  <reg51.h> #include  <intrins.h>/******************eeprom used in the SFR register address STC model different address different ************************************** /SFR&NBSP;IAP_DATA&NBSP;&NBSP;&NBSP;&NBSP;=&NBSP;0XE2;&NBSP;&NBSP;&NBSP;//IAP Data registers (read and write data from Flash) at the time of operation SFR&NBSP;IAP_ADDRH&NBSP;&NBSP;&NBSP;=&NBSP;0XE3;&NBSP;&NBSP;&NBSP;//IAP High 8-bit sfr iap_addrl  when operating the address register &NBSP;&NBSP;=&NBSP;0XE4;&NBSP;&NBSP;&NBSP;//&NBSP;IAP Operation address Register low 8-bit sfr iap_cmd     &NBSP;=&NBSP;0XE5;&NBSP;//IAP Command mode register (requires command trigger register trigger to take effect) 3 modes sfr iap_trig    = 0xe6; &NBSP;//IAP Command trigger register, at Iap_contr.7=1, Iap_trig first write//into 46h, then write B9H,IAP command takes effect sfr iap_contr   =  0XE7;&NBSP;//IAP Control Register  /*********** defines flash  operation wait time and constants that allow iap/isp/eeprom  operations (belonging to the IAP_CONTR register) * */#define &NBSP;ENABLE_ISP&NBSP;0X82&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//Measurement   12M   11.0592m  can use void delay_ms  (unsigned int a) {    unsigned  int i;    while  ( --a != 0 )     {         for  (i=0;i<=110;i++);     }}/************ * Close IAP Function subroutine *****************************/void iap_disable ()       //Close IAP   Function, -related special function register, so that cpu  in a safe state,{                        //It is recommended to close the IAP after a continuous iap  operation is completed   function, do not need to close every time         IAP_CONTR = 0;       //off iap  function     IAP_CMD   = 0;       //the command register so that the command registers are not deadOrder, this sentence can not be     iap_trig = 0;       //command trigger register, Make the command trigger register no trigger, this sentence can not     iap_addrh = 0;      //high eight-bit address clear 0     iap_addrl = 0;      //low eight-bit address clear 0} /********* *eeprom read a Byte subroutine ***********************/unsigned char byte_read (Unsigned int add)        //read a Byte, the call needs to open iap  function, the entry:dptr =  byte address, return:a =  Read bytes {     IAP_DATA = 0x00;            &NBSP;&NBSP;//IAP Data Register Clear 0    iap_contr = enable_isp;       //Open iap  function,  set flash  operation wait Time     IAP_CMD = 0x01;               //IAP/ISP/EEPROM  Byte Read command      iap_addrh =  (Unsigned char) (add>>8)     //set the destination cell address of the high 8  bit address      IAP_ADDRL =  (Unsigned char) (ADD&AMP;0XFF);     // Sets the low 8  bit address of the destination cell address      ea = 0;    iap_trig =  0x46;   //first Send  46h, and then send b9h  to the isp/iap  trigger register, each time need so &NBSP;&NBSP;&NBSP;&NBSP;IAP_ trig = 0xb9;   //,isp/iap  command is triggered immediately after delivery of the  B9h      _ Nop_ ();     ea = 1;    iap_disable ();  //Close iap  function,   Clear-related special function registers, so that the cpu  in a safe state,                     //once a continuous iap  operation is completed, it is recommended to turn off the iap  function, and do not need to close each      return  (iap_data);}   /************eeprom byte program subroutine **************************/void byte_program (Unsigned int  add, Unsigned char ch)   //byte programming, need to open iap  function before calling, ingress:dptr =  byte address, a=  Data {    iap_contr = enable_isp;        of the required programming bytes   //Open  IAP  function,  set flash  operation wait Time     IAP_CMD = 0x02;                  //iap/ isp/eeprom  byte Programming Command       IAP_ADDRH =  (Unsigned char) (add> &GT;8)     //set the high 8  address of the destination cell address     IAP_ADDRL =  (unsigned  char) (ADD&AMP;0XFF)     //set the low 8  bit address of the destination cell address      iap_data  = ch;                   //the data to be programmed is first sent to the iap_data  register     EA = 0;     iap_trig = 0x46;   //first Send  46h, and then send b9h  to the isp/iap  trigger register, each time need so     iap_trig =  0xb9;   //,isp/iap  command is triggered immediately after delivery  B9h      _nop_ ();     ea = 1;    iap_disable ();  //Close iap  function,  The cpu  is in a safe state by clearing the relevant special function registers,                     //once a continuous iap  operation is completed, it is recommended to turn off the iap  function, and do not need to close each time} /************* EEPROM Erase Sector Sub-program **************************/void sector_erase (Unsigned int add)         //Erase sector,  Ingress:dptr =  sector address {    iap_contr =  enable_isp;         //Open iap  function,  set flash  operation wait Time     IAP_CMD = 0x03;                  //iap/isp/eeprom  Sector Erase Command      IAP_ADDRH =  (Unsigned char) (add &GT;&GT;8)     //set the high 8  address of the destination cell address     IAP_ADDRL =  ( Unsigned char) (ADD&AMP;0XFF)     //set the low 8  address of the destination cell address       ea = 0;    iap_trig = 0x46;   //first Send  46h, then send b9h  To the isp/iap  trigger register, each time it needs to be so     iap_trig = 0xb9;   //sent out  b9h   Post,isp/iap  command is triggered immediately starting     _nop_ ();    ea = 1;     iap_disable ();      //off iap  function,  Clear related special function register, make cpu  In a safe State,                        //It is recommended to turn off the iap  function once a continuous iap  operation is complete, do not need to close}void main  (void) { Unsigned char mydata  = 0x0f;unsigned int  address = 0x2000; P1 = byte_read (address);      //reads the 8 bits of the current location store and displays the Delay_ms (1000); Sector_erase (address);        //Erase the Sector Byte_program (Address,mydata) where this address is located;// Writes a new 8 Bitp1 = byte_read (address),       //reads the 8 bits of the current location store and displays the while (1);}



2

/* Microcontroller built-in  eeprom test program for   stc89c51stc89c52stc89c53stc89c54stc89c58stc89c510stc89c512stc89c514 Test Crystal oscillator:11.05926m 12m  can be used   Function: Reads a byte content of the specified address, and displays the erase of a sector on the 8&NBSP;P1 bus, modifies a byte content of the specified address, and displays it on the 8&NBSP;P1 bus */#include  <reg51.h> #include  <intrins.h>/******************eeprom used in the SFR register address STC model different address different ************************************** /SFR&NBSP;IAP_DATA&NBSP;&NBSP;&NBSP;&NBSP;=&NBSP;0XE2;&NBSP;&NBSP;&NBSP;//IAP Data registers (read and write data from Flash) at the time of operation SFR&NBSP;IAP_ADDRH&NBSP;&NBSP;&NBSP;=&NBSP;0XE3;&NBSP;&NBSP;&NBSP;//IAP High 8-bit sfr iap_addrl  when operating the address register &NBSP;&NBSP;=&NBSP;0XE4;&NBSP;&NBSP;&NBSP;//&NBSP;IAP Operation address Register low 8-bit sfr iap_cmd     &NBSP;=&NBSP;0XE5;&NBSP;//IAP Command mode register (requires command trigger register trigger to take effect) 3 modes sfr iap_trig    = 0xe6; &NBSP;//IAP Command trigger register, at Iap_contr.7=1, Iap_trig first write//into 46h, then write B9H,IAP command takes effect sfr iap_contr   =  0XE7;&NBSP;//IAP Control Register  /*********** defines flash  operation wait time and constants that allow iap/isp/eeprom  operations (belonging to the IAP_CONTR register) * */#define &NBSP;ENABLE_ISP&NBSP;0X82&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//Measurement   12M   11.0592m  can use void delay_ms  (unsigned int a) {    unsigned  int i;    while  ( --a != 0 )     {         for  (i=0;i<=110;i++);     }}/************ * Close IAP Function subroutine *****************************/void iap_disable ()       //Close IAP   Function, -related special function register, so that cpu  in a safe state,{                        //It is recommended to close the IAP after a continuous iap  operation is completed   function, do not need to close every time         IAP_CONTR = 0;       //off iap  function     IAP_CMD   = 0;       //the command register so that the command registers are not deadOrder, this sentence can not be     iap_trig = 0;       //command trigger register, Make the command trigger register no trigger, this sentence can not     iap_addrh = 0;      //high eight-bit address clear 0     iap_addrl = 0;      //low eight-bit address clear 0} /********* *eeprom read a Byte subroutine ***********************/unsigned char byte_read (Unsigned int add)        //read a Byte, the call needs to open iap  function, the entry:dptr =  byte address, return:a =  Read bytes {     IAP_DATA = 0x00;            &NBSP;&NBSP;//IAP Data Register Clear 0    iap_contr = enable_isp;       //Open iap  function,  set flash  operation wait Time     IAP_CMD = 0x01;               //IAP/ISP/EEPROM  Byte Read command      iap_addrh =  (Unsigned char) (add>>8)     //set the destination cell address of the high 8  bit address      IAP_ADDRL =  (Unsigned char) (ADD&AMP;0XFF);     // Sets the low 8  bit address of the destination cell address      ea = 0;    iap_trig =  0x46;   //first Send  46h, and then send b9h  to the isp/iap  trigger register, each time need so &NBSP;&NBSP;&NBSP;&NBSP;IAP_ trig = 0xb9;   //,isp/iap  command is triggered immediately after delivery of the  B9h      _ Nop_ ();     ea = 1;    iap_disable ();  //Close iap  function,   Clear-related special function registers, so that the cpu  in a safe state,                     //once a continuous iap  operation is completed, it is recommended to turn off the iap  function, and do not need to close each      return  (iap_data);}   /************eeprom byte program subroutine **************************/void byte_program (Unsigned int  add, Unsigned char ch)   //byte programming, need to open iap  function before calling, ingress:dptr =  byte address, a=  Data {    iap_contr = enable_isp;        of the required programming bytes   //Open  IAP  function,  set flash  operation wait Time     IAP_CMD = 0x02;                  //iap/ isp/eeprom  byte Programming Command       IAP_ADDRH =  (Unsigned char) (add> &GT;8)     //set the high 8  address of the destination cell address     IAP_ADDRL =  (unsigned  char) (ADD&AMP;0XFF)     //set the low 8  bit address of the destination cell address      iap_data  = ch;                   //the data to be programmed is first sent to the iap_data  register     EA = 0;     iap_trig = 0x46;   //first Send  46h, and then send b9h  to the isp/iap  trigger register, each time need so     iap_trig =  0xb9;   //,isp/iap  command is triggered immediately after delivery  B9h      _nop_ ();     ea = 1;    iap_disable ();  //Close iap  function,  The cpu  is in a safe state by clearing the relevant special function registers,                     //once a continuous iap  operation is completed, it is recommended to turn off the iap  function, and do not need to close each time} /************* EEPROM Erase Sector Sub-program **************************/void sector_erase (Unsigned int add)         //Erase sector,  Ingress:dptr =  sector address {    iap_contr =  enable_isp;         //Open iap  function,  set flash  operation wait Time     IAP_CMD = 0x03;                  //iap/isp/eeprom  Sector Erase Command      IAP_ADDRH =  (Unsigned char) (add &GT;&GT;8)     //set the high 8  address of the destination cell address     IAP_ADDRL =  ( Unsigned char) (ADD&AMP;0XFF)     //set the low 8  address of the destination cell address       ea = 0;    iap_trig = 0x46;   //first Send  46h, then send b9h  To the isp/iap  trigger register, each time it needs to be so     iap_trig = 0xb9;   //sent out  b9h   Post,isp/iap  command is triggered immediately starting     _nop_ ();    ea = 1;     iap_disable ();      //off iap  function,  Clear related special function register, make cpu  In a safe State,                        //It is recommended to turn off the iap  function once a continuous iap  operation is complete, do not need to close}void main  (void) { Unsigned char mydata1  = 0xf0;unsigned char mydata2  = 0x0f;unsigned int   address1 = 0x2000;unsigned int  address2 = 0x21FF; Sector_erase (ADDRESS1);         //for data write Byte_program (ADDRESS1,MYDATA1) ; Byte_program (ADDRESS2,MYDATA2); P1 = byte_read (ADDRESS1);      //show Delay_ms (500); P1 = byte_read (Address2),      //show Delay_ms (//sector_erase);        //either erase Address1 or Address2sector_erase (address2);        p1 = byte_read (ADDRESS1);      //reads 0xffdelay_ms ( 500); P1 = byte_read (ADDRESS2);      //read 0xffdelay_ms (500);/* It can be proved that A and B belong to an address with a sector erase a or b  byte to read a again or b  has changed to 0xff*/while (1);}


This article is from the "Soul Bucket" blog, please be sure to keep this source http://990487026.blog.51cto.com/10133282/1762381

STC 89c51 Series EEPROM test procedure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.