SCL BIT P3.2;EEPROM母片SDA BIT P3.3SCL1 BIT P1.2;寫入目標(biāo)EEPROMSDA1 BIT P1.3ORG 0000HLJMP A1ORG 002BHA1: MOV P0,#0FFHMOV P1,#0FFHMOV P2,#0FFHMOV P3,#0FFHA2: CLR P1.7;燒錄成功指示燈SETB P3.7;燒錄失敗指示燈JB P1.6,$;燒錄按鍵LCALL M001JNB P1.6,$CLR P1.7;燒錄時(shí)同時(shí)亮CLR P3.7;燒錄時(shí)同時(shí)亮MOV 39H,#0A0H;寫第一頁MOV 38H,#0A1H;讀第一頁MOV 37H,#1;總頁數(shù)A3: JB P1.5,A4;判斷外部選擇開關(guān)JB P1.4,A01;00---24C02MOV 37H,#1;1頁JMP A02;01---24C04A01: MOV 37H,#2;2頁JMP A02A4: JB P1.4,A5;10---24C08MOV 37H,#4;4頁JMP A02 ;11---24C16A5: MOV 37H,#8;8頁A02:X24C021:MOV 40H,#0;位置MOV 43H,#0FFH;一頁總數(shù)X24C022:LCALL R24C02;讀母片數(shù)據(jù)MOV 41H,32H;存到目標(biāo)板子片數(shù)據(jù)寄存器CALL W24C02;將母片數(shù)據(jù)寫到INC 40H;地址加1DJNZ 43H,X24C022;判斷是否完成255個(gè)LCALL R24C02;完成255個(gè)再寫1個(gè)公256個(gè)數(shù)MOV 41H,32H;CALL W24C02;MOV 40H,#0;位置MOV 43H,#0FFH;一頁總數(shù)INC 39H;寫頁碼加1由于頁碼是在123位不是在0位所以要加2次1INC 39H;INC 38H;讀頁碼INC 38H;DJNZ 37H,X24C022;判斷是否完成所以頁碼;********************************************************************; 比較是否相等;********************************************************************MOV 39H,#0A0H;寫第一頁MOV 38H,#0A1H;讀第一頁MOV 37H,#1;總頁數(shù)D24C021:MOV 40H,#0;位置MOV 43H,#0FFH;一頁總數(shù)D24C022:LCALL R24C02;讀母片數(shù)據(jù)MOV 41H,32H;保存母片數(shù)據(jù)CALL R24C02_1;讀子片數(shù)據(jù)MOV A,32H;CJNE A,41H,D24C023;判斷子片數(shù)據(jù)是否=母片數(shù)據(jù)INC 40H;數(shù)據(jù)位置加1DJNZ 43H,D24C022;判斷是否完成255個(gè)數(shù)對(duì)比LCALL R24C02;讀母片數(shù)據(jù)MOV 41H,32H;保存母片數(shù)據(jù)CALL R24C02_1;讀子片數(shù)據(jù)MOV A,32H;CJNE A,41H,D24C023;判斷子片數(shù)據(jù)是否=母片數(shù)據(jù)MOV 40H,#0;位置MOV 43H,#0FFH;一頁總數(shù)INC 39H;INC 39H;INC 38H;INC 38H;DJNZ 37H,D24C022;JMP A2D24C023:SETB P1.7;燒錄出錯(cuò)母片數(shù)據(jù)不等于子片數(shù)據(jù)CLR P3.7;亮指示燈JB P1.6,$;按燒錄鍵反回LCALL M001;JNB P1.6,$;CALL M003;JMP A2;W24C02: LCALL START1;開始子程序MOV A,39H;寫模式LCALL WRITE;寫數(shù)據(jù)MOV A,40H;存儲(chǔ)位置LCALL WRITEMOV A,41H;存儲(chǔ)數(shù)據(jù)LCALL WRITELCALL STOP1;結(jié)束LCALL M001RETM001: MOV 30H,#3M002: MOV 31H,#250DJNZ 31H,$DJNZ 30H,M002RETM003: MOV 3AH,#4M004: MOV 3BH,#248M005: MOV 3CH,#248DJNZ 3CH,$DJNZ 3BH,M005DJNZ 3AH,M004RETR24C02: LCALL START;開始子程序MOV A,39HLCALL WRITE0MOV A,40H;存儲(chǔ)位置LCALL WRITE0LCALL STARTMOV A,38H;讀模式LCALL WRITE0LCALL READ;讀取數(shù)據(jù)LCALL STOPRETR24C02_1:LCALL START1;開始子程序MOV A,39HLCALL WRITEMOV A,40H;存儲(chǔ)位置LCALL WRITELCALL START1MOV A,38H;讀模式LCALL WRITELCALL READ_1;讀取數(shù)據(jù)LCALL STOP1RETWRITE0: MOV R7,#8WRITE01:RLC AMOV SDA,CSETB SCLNOPNOPNOPNOPCLR SCLNOPDJNZ R7,WRITE01NOPNOPNOPLCALL ACKNOPNOPRET;寫WRITE: MOV R7,#8WRITE1: RLC AMOV SDA1,CSETB SCL1NOPNOPNOPNOPCLR SCL1NOPDJNZ R7,WRITE1NOPNOPNOPLCALL ACK1NOPNOPRET;讀READ: MOV R7,#8READ1: SETB SDASETB SCLMOV C,SDARLC AMOV 32H,ANOPNOPNOPNOPCLR SCLDJNZ R7,READ1LCALL NACKNOPNOPRET;讀READ_1: MOV R7,#8READ01: SETB SDA1SETB SCL1MOV C,SDA1RLC AMOV 32H,ANOPNOPNOPNOPCLR SCL1DJNZ R7,READ01LCALL NACK1NOPNOPRET;應(yīng)答ACK: CLR SDA ;響應(yīng)程序段 應(yīng)答程序NOPSETB SCLNOPNOPNOPNOPCLR SCLNOPNOPRETNACK: SETB SDA ;非應(yīng)答程序段NOPNOPSETB SCLNOPNOPNOPNOPCLR SCLNOPRET;開始START: SETB SCLSETB SDANOPNOPCLR SDANOPNOPNOPNOPCLR SCLRET;結(jié)束STOP: SETB SCLCLR SDANOPNOPNOPNOPSETB SDARET;*********************************************;應(yīng)答ACK1: CLR SDA1 ;響應(yīng)程序段 應(yīng)答程序NOPSETB SCL1NOPNOPNOPNOPCLR SCL1NOPNOPRETNACK1: SETB SDA1 ;非應(yīng)答程序段NOPNOPSETB SCL1NOPNOPNOPNOPCLR SCL1NOPRET;開始START1: SETB SCL1SETB SDA1NOPNOPCLR SDA1NOPNOPNOPNOPCLR SCL1RET;結(jié)束STOP1: SETB SCL1CLR SDA1NOPNOPNOPNOPSETB SDA1RETendSCL BIT P3.2;EEPROM母片SDA BIT P3.3SCL1 BIT P1.2;寫入目標(biāo)EEPROMSDA1 BIT P1.3ORG 0000HLJMP A1ORG 002BHA1: MOV P0,#0FFHMOV P1,#0FFHMOV P2,#0FFHMOV P3,#0FFH
評(píng)論