STC89C51¡¢52ÄÚ²¿¶¼×Ô´øÓÐ2K×Ö½ÚµÄEEPROM£¬54¡¢55ºÍ58¶¼×Ô´øÓÐ16K×Ö½ÚµÄEEPROM£¬STCµ¥Æ¬»úÊÇÀûÓÃIAP¼¼ÊõʵÏÖµÄEEPROM£¬ÄÚ²¿Flash²Áд´ÎÊý¿É´ï100£¬000´ÎÒÔÉÏ£¬ÏÈÀ´½éÉÜÏÂISPÓëIAPµÄÇø±ðºÍÌص㡣֪ʶµã£ºISPÓëIAP½éÉÜISP£ºInSystemProgramableÊÇÖ¸ÔÚϵͳ±à³Ì£¬Í¨Ë׵Ľ²£¬¾ÍÊÇƬ×ÓÒѾº¸°å×ÓÉÏ£¬²»ÓÃÈ¡Ï£¬¾Í¿ÉÒÔ¼òµ¥¶ø·½±ãµØ¶ÔÆä½øÐбà³Ì¡£±ÈÈçÎÒÃÇͨ¹ýµçÄÔ¸øSTCµ¥Æ¬»úÏÂÔسÌÐò£¬»ò¸øAT89S51µ¥Æ¬»úÏÂÔسÌÐò£¬Õâ¾ÍÊÇÀûÓÃÁËISP¼¼Êõ¡£IAP£ºInApplicationProgramableÊÇÖ¸ÔÚÓ¦Óñà³Ì£¬¾ÍÊÇƬ×ÓÌṩһϵÁеĻúÖÆ(Ó²¼þ/Èí¼þÉϵÄ)µ±Æ¬×ÓÔÚÔËÐгÌÐòµÄʱºò¿ÉÒÔÌṩһÖָıäflashÊý¾ÝµÄ·½·¨¡£Í¨Ë׵㽲£¬Ò²¾ÍÊÇ˵³ÌÐò×Ô¼º¿ÉÒÔÍù³ÌÐò´æ´¢Æ÷ÀïдÊý¾Ý»òÐ޸ijÌÐò¡£ÕâÖÖ·½Ê½µÄµäÐÍÓ¦ÓþÍÊÇÓÃһС¶Î´úÂëÀ´ÊµÏÖ³ÌÐòµÄÏÂÔØ£¬Êµ¼ÊÉϵ¥Æ¬»úµÄISP¹¦ÄܾÍÊÇͨ¹ýIAP¼¼ÊõÀ´ÊµÏֵģ¬¼´Æ¬×ÓÔÚ³ö³§Ç°¾ÍÒѾÓÐÒ»¶ÎСµÄboot³ÌÐòÔÚÀïÃ棬Ƭ×ÓÉϵçºó£¬¿ªÊ¼ÔËÐÐÕâ¶Î³ÌÐò£¬µ±¼ì²âµ½ÉÏλ»úÓÐÏÂÔØÒªÇóʱ£¬±ãºÍÉÏλ»úͨÐÅ£¬È»ºóÏÂÔØÊý¾Ýµ½´æ´¢Çø¡£´ó¼ÒҪעÒâǧÍò²»Òª³¢ÊÔÈ¥²Á³ýÕâ¶ÎISPÒýµ¼³ÌÐò£¬·ñÔò¿ÖÅÂÒÔºóÔÙÒ²ÏÂÔز»Á˳ÌÐòÁË¡£STCµ¥Æ¬»úÄÚ²¿Óм¸¸öרÃŵÄÌØÊ⹦ÄܼĴæÆ÷¸ºÔð¹ÜÀíISP/IAP¹¦Äܵģ¬¼û±í1¡£Ã¿¸öÉÈÇøΪ512×Ö½Ú£¬½¨Òé´ó¼ÒÔÚд³ÌÐòʱ£¬½«Í¬Ò»´ÎÐ޸ĵÄÊý¾Ý·ÅÔÚͬһ¸öÉÈÇø£¬·½±ãÐ޸ģ¬ÒòΪÔÚÖ´ÐвÁ³ýÃüÁîʱ£¬Ò»´Î×îÉÙÒª²Á³ýÒ»¸öÉÈÇøµÄÊý¾Ý£¬Ã¿´ÎÔÚ¸üÐÂÊý¾ÝÇ°¶¼±ØÐëÒª²Á³ýÔÊý¾Ý·½¿ÉÖØÐÂдÈëÐÂÊý¾Ý£¬²»ÄÜÖ±½ÓÔÚÔÀ´Êý¾Ý»ù´¡ÉϸüÐÂÄÚÈÝ¡£ÏÂÃæͨ¹ýÒ»¸öÀý×ÓÀ´½²½âSTCϵÁе¥Æ¬»úEEPROMµÄ¾ßÌåÓ÷¨¡£¡¾Àý¡¿£ºÔÚTX-1CʵÑé°åÉÏʵÏÖÈçÏÂÃèÊö£¬²Ù×÷STCµ¥Æ¬»ú×Ô´øµÄEEPROM£¬´æ´¢Ò»×é°´ÃëµÝÔöµÄ¶þλÊý¾Ý£¬²¢ÇÒ½«Êý¾ÝʵʱÏÔʾÔÚÊýÂë¹ÜÉÏ£¬Êý¾Ýÿ±ä»¯Ò»´Î¾ÍÍùEEPROMÖÐдÈëÒ»´Î£¬µ±¹Ø±ÕʵÑé°åµçÔ´£¬ÔٴοªÆôµçԴʱ£¬´ÓEEPROMÖжÁÈ¡ÏÈÇ°´æ´¢µÄÊý¾Ý£¬½Ó×ŵÝÔöÏÔʾ¡£Ð½¨Îļþpart3.4.4.c£¬³ÌÐò´úÂëÈçÏ£º#includeintrins.h#includereg52.h//52ϵÁе¥Æ¬»úÍ·Îļþ#defineucharunsignedchar#defineuintunsignedint#defineRdCommand0x01//¶¨ÒåISPµÄ²Ù×÷ÃüÁî#definePrgCommand0x02#defineEraseCommand0x03#defineError1#defineOk0#defineWaitTime0x01//¶¨ÒåCPUµÄµÈ´ýʱ¼äsfrISP_DATA=0xe2;//¼Ä´æÆ÷ÉêÃ÷sfrISP_ADDRH=0xe3;sfrISP_ADDRL=0xe4;sfrISP_CMD=0xe5;sfrISP_TRIG=0xe6;sfrISP_CONTR=0xe7;sbitdula=P2^6;//ÉêÃ÷U1Ëø´æÆ÷µÄËø´æ¶Ësbitwela=P2^7;//ÉêÃ÷U2Ëø´æÆ÷µÄËø´æ¶Ëucharcodetable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};ucharnum;voiddelayms(uintxms){uinti,j;for(i=xms;i0;i--)//i=xms¼´ÑÓʱԼxmsºÁÃëfor(j=110;j0;j--);}voiddisplay(ucharshi,ucharge)//ÏÔʾ×Óº¯Êý{dula=1;P0=table[shi];//ËÍʮλ¶ÎÑ¡Êý¾Ýdula=0;P0=0xff;//ËÍλѡÊý¾ÝÇ°¹Ø±ÕËùÓÐÏÔʾ£¬·ÀÖ¹´ò¿ªÎ»Ñ¡Ëø´æʱwela=1;//ÔÀ´¶ÎÑ¡Êý¾Ýͨ¹ýλѡËø´æÆ÷Ôì³É»ìÂÒP0=0xfe;//ËÍλѡÊý¾Ýwela=0;delayms(5);//ÑÓʱdula=1;P0=table[ge];//Ë͸öλ¶ÎÑ¡Êý¾Ýdula=0;P0=0xff;wela=1;P0=0xfd;wela=0;delayms(5);}/*================´ò¿ªISP,IAP¹¦ÄÜ=================*/voidISP_IAP_enable(void){EA=0;/*¹ØÖжÏ*/ISP_CONTR=ISP_CONTR&0x18;/*0001,1000*/ISP_CONTR=ISP_CONTR|WaitTime;/*дÈëÓ²¼þÑÓʱ*/ISP_CONTR=ISP_CONTR|0x80;/*ISPEN=1*/}/*===============¹Ø±ÕISP,IAP¹¦ÄÜ==================*/voidISP_IAP_disable(void){ISP_CONTR=ISP_CONTR&0x7f;/*ISPEN=0*/ISP_TRIG=0x00;EA=1;/*¿ªÖжÏ*/}/*================¹«ÓõĴ¥·¢´úÂë====================*/voidISPgoon(void){ISP_IAP_enable();/*´ò¿ªISP,IAP¹¦ÄÜ*/ISP_TRIG=0x46;/*´¥·¢ISP_IAPÃüÁî×Ö½Ú1*/ISP_TRIG=0xb9;/*´¥·¢ISP_IAPÃüÁî×Ö½Ú2*/_nop_();}/*====================×Ö½Ú¶Á========================*/unsignedcharbyte_read(unsignedintbyte_addr){ISP_ADDRH=(unsignedchar)(byte_addr8);/*µØÖ·¸³Öµ*/ISP_ADDRL=(unsignedchar)(byte_addr&0x00ff);ISP_CMD=ISP_CMD&0xf8;/*Çå³ýµÍ3λ*/ISP_CMD=ISP_CMD|RdCommand;/*дÈë¶ÁÃüÁî*/ISPgoon();/*´¥·¢Ö´ÐÐ*/ISP_IAP_disable();/*¹Ø±ÕISP,IAP¹¦ÄÜ*/return(ISP_DATA);/*·µ»Ø¶Áµ½µÄÊý¾Ý*/}/*==================ÉÈÇø²Á³ý========================*/voidSectorErase(unsignedintsector_addr){unsignedintiSectorAddr;iSectorAddr=(sector_addr&0xfe00);/*È¡ÉÈÇøµØÖ·*/ISP_ADDRH=(unsignedchar)(iSectorAddr8);ISP_ADDRL=0x00;ISP_CMD=ISP_CMD&0xf8;/*Çå¿ÕµÍ3λ*/ISP_CMD=ISP_CMD|EraseCommand;/*²Á³ýÃüÁî3*/ISPgoon();/*´¥·¢Ö´ÐÐ*/ISP_IAP_disable();/*¹Ø±ÕISP,IAP¹¦ÄÜ*/}/*====================×Ö½Úд========================*/voidbyte_write(unsignedintbyte_addr,unsignedcharoriginal_data){ISP_ADDRH=(unsignedchar)(byte_addr8);/*È¡µØÖ·*/ISP_ADDRL=(unsignedchar)(byte_addr&0x00ff);ISP_CMD=ISP_CMD&0xf8;/*ÇåµÍ3λ*/ISP_CMD=ISP_CMD|PrgCommand;/*дÃüÁî2*/ISP_DATA=original_data;/*дÈëÊý¾Ý×¼±¸*/ISPgoon();/*´¥·¢Ö´ÐÐ*/ISP_IAP_disable();/*¹Ø±ÕIAP¹¦ÄÜ*/}voidmain(){uchara,b,num1;TMOD=0x01;//ÉèÖö¨Ê±Æ÷0Ϊ¹¤×÷·½Ê½1(00000001)TH0=(65536-50000)/256;TL0=(65536-50000)%256;EA=1;ET0=1;TR0=1;num1=byte_read(0x2000);//³ÌÐò¿ªÊ¼Ê±¶ÁÈ¡EEPROMÖÐÊý¾Ýif(num1=60)//·ÀÖ¹Ê×´ÎÉϵçʱ¶ÁÈ¡³ö´ínum1=0;while(1){if(num=20){num=0;num1++;SectorErase(0x2000);//²Á³ýÉÈÇøbyte_write(0x2000,num1);//ÖØÐÂдÈëÊý¾Ýif(num1==60){num1=0;}a=num1/10;b=num1%10;}display(a,b);}}voidtimer0()interrupt1{TH0=(65536-50000)/256;TL0=(65536-50000)%256;num++;}