SCL BIT P3.2;EEPROM母片
SDA BIT P3.3SCL1 BIT P1.2;写入方针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;烧录时一起亮CLR P3.7;烧录时一起亮MOV 39H,#0A0H;写第一页MOV 38H,#0A1H;读第一页MOV 37H,#1;总页数A3: JB P1.5,A4;判别外部选择开关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;一页总数X24C022:LCALL R24C02;读母片数据MOV 41H,32H;存到方针板子片数据寄存器CALL W24C02;将母片数据写到INC 40H;地址加1DJNZ 43H,X24C022;判别是否完结255个LCALL R24C02;完结255个再写1个公256个数MOV 41H,32H;CALL W24C02;MOV 40H,#0;方位MOV 43H,#0FFH;一页总数INC 39H;写页码加1因为页码是在123位不是在0位所以要加2次1INC 39H;INC 38H;读页码INC 38H;DJNZ 37H,X24C022;判别是否完结所以页码;********************************************************************; 比较是否持平;********************************************************************MOV 39H,#0A0H;写第一页MOV 38H,#0A1H;读第一页MOV 37H,#1;总页数D24C021:MOV 40H,#0;方位MOV 43H,#0FFH;一页总数D24C022:LCALL R24C02;读母片数据MOV 41H,32H;保存母片数据CALL R24C02_1;读子片数据MOV A,32H;CJNE A,41H,D24C023;判别子片数据是否=母片数据INC 40H;数据方位加1DJNZ 43H,D24C022;判别是否完结255个数比照LCALL R24C02;读母片数据MOV 41H,32H;保存母片数据CALL R24C02_1;读子片数据MOV A,32H;CJNE A,41H,D24C023;判别子片数据是否=母片数据MOV 40H,#0;方位MOV 43H,#0FFH;一页总数INC 39H;INC 39H;INC 38H;INC 38H;DJNZ 37H,D24C022;JMP A2D24C023:SETB P1.7;烧录犯错母片数据不等于子片数据CLR P3.7;亮指示灯JB P1.6,$;按烧录键反回LCALL M001;JNB P1.6,$;CALL M003;JMP A2;W24C02: LCALL START1;开端子程序MOV A,39H;写形式LCALL WRITE;写数据MOV A,40H;存储方位LCALL WRITEMOV A,41H;存储数据LCALL WRITELCALL STOP1;完毕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;存储方位LCALL WRITE0LCALL STARTMOV A,38H;读形式LCALL WRITE0LCALL READ;读取数据LCALL STOPRETR24C02_1:LCALL START1;开端子程序MOV A,39HLCALL WRITEMOV A,40H;存储方位LCALL WRITELCALL START1MOV A,38H;读形式LCALL WRITELCALL READ_1;读取数据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;应对ACK: CLR SDA ;呼应程序段 应对程序NOPSETB SCLNOPNOPNOPNOPCLR SCLNOPNOPRETNACK: SETB SDA ;非应对程序段NOPNOPSETB SCLNOPNOPNOPNOPCLR SCLNOPRET;开端START: SETB SCLSETB SDANOPNOPCLR SDANOPNOPNOPNOPCLR SCLRET;完毕STOP: SETB SCLCLR SDANOPNOPNOPNOPSETB SDARET;*********************************************;应对ACK1: CLR SDA1 ;呼应程序段 应对程序NOPSETB SCL1NOPNOPNOPNOPCLR SCL1NOPNOPRETNACK1: SETB SDA1 ;非应对程序段NOPNOPSETB SCL1NOPNOPNOPNOPCLR SCL1NOPRET;开端START1: SETB SCL1SETB SDA1NOPNOPCLR SDA1NOPNOPNOPNOPCLR SCL1RET;完毕STOP1: SETB SCL1CLR SDA1NOPNOPNOPNOPSETB SDA1RETendSCL BIT P3.2;EEPROM母片SDA BIT P3.3SCL1 BIT P1.2;写入方针EEPROMSDA1 BIT P1.3ORG 0000HLJMP A1ORG 002BHA1: MOV P0,#0FFHMOV P1,#0FFHMOV P2,#0FFHMOV P3,#0FFH