微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 利用2051单片机烧录24C02,04,08,16

利用2051单片机烧录24C02,04,08,16

时间:11-30 来源:互联网 点击:
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,#0FFHA2: CLR P1.7SETB P3.7JB P1.6,$LCALL M001JNB P1.6,$SETB P1.7MOV 39H,#0A0H;写第一页MOV 38H,#0A1H;读第一页MOV 37H,#1;总页数A3: JB P1.5,A4JB P1.4,A01MOV 37H,#1;00---C02JMP A02A01: MOV 37H,#2;01---C04JMP A02A4: JB P1.4,A5MOV 37H,#4;10---C08JMP A02A5: MOV 37H,#8;11---C16A02:X24C021:MOV 40H,#0;位置MOV 43H,#0FFH;一页总数X24C022:LCALL R24C02;MOV 41H,32H;CALL W24C02INC 40HDJNZ 43H,X24C022MOV 40H,#0;位置MOV 43H,#0FFH;一页总数INC 39HINC 39HINC 38HINC 38HDJNZ 37H,X24C022MOV 39H,#0A0H;写第一页MOV 38H,#0A1H;读第一页MOV 37H,#1;总页数D24C021:MOV 40H,#0;位置MOV 43H,#0FFH;一页总数D24C022:LCALL R24C02;MOV 41H,32H;CALL R24C02_1MOV A,32HCJNE A,41H,D24C023INC 40HDJNZ 43H,D24C022MOV 40H,#0;位置MOV 43H,#0FFH;一页总数INC 39HINC 39HINC 38HINC 38HDJNZ 37H,D24C022JMP A2D24C023:SETB P1.7CLR P3.7JB P1.6,$LCALL M001JNB P1.6,$CALL M003JMP A2W24C02: LCALL START1;开始子程序MOV A,39H;写模式LCALL WRITE;写数据MOV A,40H;存储位置LCALL WRITEMOV A,41H;存储数据LCALL WRITELCALL STOP1;结束LCALL M001RETM001: MOV 30H,#1M002: MOV 31H,#248DJNZ 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 SDA1RETend

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top