E51p.asm
上传用户:qzrxzm02
上传日期:2013-04-11
资源大小:688k
文件大小:23k
- ;波特率28800
- ;for at89c51系列
- ;增加AT89S51串行编程功能
- ;删除了烧at89c2051系列芯片的代码
- VPP EQU P3.2;接三极管,vpp电压控制
- VPP_12 EQU P3.2;5-12V CONTROL FOR 89C51
- RST EQU P3.5;
- PROG EQU P3.3;编程脉冲控制
- BUSY EQU P3.4;
- MOSI EQU P1.5
- MISO EQU P1.6
- SCK EQU P1.7
- F_VPP EQU 00H ;vpp电压标志
- F_RST EQU 01H ;RST电压标志
- F_RXALL EQU 02H
- TX0 EQU 30H;
- TX1 EQU 31H;
- TX2 EQU 32H;发送缓存
- TX3 EQU 33H;30-41 18BYTES BUFFER
- TX4 EQU 34H
- TX17 EQU 41H
- RX0 EQU 42H;42-53 18BYTES BUFFER
- RX1 EQU 43H;
- RX2 EQU 44H;
- RX3 EQU 45H;接收缓存
- RX4 EQU 46H
- RX17 EQU 53H
- ADDRESS_L EQU 10H;
- ADDRESS_H EQU 11H;
- PARAM0 EQU 12H
- PARAM1 EQU 13H
- PARAM2 EQU 14H
- PARAM3 EQU 15H
- RET0 EQU 16H
- RET1 EQU 17H
- RET2 EQU 18H
- RET3 EQU 19H
- BITS1 EQU 22H
- BITS2 EQU 23H
- SOUT EQU 24H
- SIN EQU 25H
- SOUT1 EQU 26H
- SOUT2 EQU 27H
- SOUT3 EQU 28H
- SOUT4 EQU 29H
- SIN1 EQU 2AH
- SIN2 EQU 2BH
- SIN3 EQU 2CH
- SIN4 EQU 2DH
- _R0 EQU 08H
- _R1 EQU 09H
- ;RX1表示器件型号:0-C51,1-C52,2-C55,10-S51,11-S52,12-S55
- C51 EQU 0H
- C52 EQU 1H
- C55 EQU 2H
- S51 EQU 10H
- S52 EQU 11H
- S55 EQU 12H
- WAIT_VOL EQU 55H;等待电压稳定延时系数
- ORG 0000H
- SJMP START
- ORG 0023H
- ;SJMP RX_INT
- ORG 0030H
- START: MOV SP,#60H
- MOV WAIT_VOL,#0FH
- SETB F_VPP
- ACALL SET_VPP5
- SETB P3.5; SET AT89C51'S RST=1
- MOV R4,#08H
- MOV IP,#00H
- ;SCON: SM0|SM1|SM2|REN|TB8|RB8|TI|RI
- MOV SCON,#11010000B ; 1 1 0 1 0 0 0 0
- MOV A,PCON
- ANL A,#01111111B ;SMOD=0
- ;ORL A,#10000000B ;SMOD=1
- MOV PCON,A
- MOV TCON,#00H
- MOV IE,#00H
- MOV TH1,#0FFH ;波特率28800*TMOD
- MOV TL1,#0FFH
- ;TMOD: GATE|C/!T|M1|M0|GATE|C/!T|M1|M0
- MOV TMOD,#00100000B; 0 0 1 0 0 0 0 1
- MOV TH0,#0FFH
- MOV TL0,#0FFH
- SETB TR1
- CLR ES ;中断允许
- CLR EA ;
- CLR RI
- CLR RI
- CLR TI
- ACALL INIT_PIN
- TEST_TX: MOV R0,#255 ;检查串口通讯
- ACALL DELAY
- MOV R0,#255
- ACALL DELAY
- MOV TX0,#01H
- MOV TX1,#'M'
- MOV TX2,#'P'
- ACALL TX_PC
- ;RX1表示器件型号:0-C51,1-C52,2-C55,3-S51,4-S52,5-S55
- WAIT_COMM: ACALL RX_PC
- MOV A,RX0
- _TEST_MP: CJNE A,#01H,_ERASE_ROM
- AJMP TEST_MP
- _ERASE_ROM: CJNE A,#02H,_INIT_WRITE
- AJMP ERASE_ROM
- _INIT_WRITE:CJNE A,#03H,_WRITE_ROM
- AJMP INIT_WRITE
- _WRITE_ROM: CJNE A,#04H,_INIT_READ
- AJMP WRITE_ROM
- _INIT_READ: CJNE A,#05H,_READ_ROM
- AJMP INIT_READ
- _READ_ROM: CJNE A,#06H,_LOCK_BIT
- AJMP WAIT_COMM
- _LOCK_BIT: CJNE A,#07H,_READ_SIGN
- AJMP LOCK_BIT
- _READ_SIGN: CJNE A,#08,WAIT_COMM
- AJMP READ_SIGN
- AJMP WAIT_COMM
- TEST_MP: ACALL INIT_PIN
- MOV TX0,RX0
- MOV A,RX1
- MOV TX1,A
- MOV A,RX2
- MOV TX2,A
- ACALL TX_PC
- AJMP WAIT_COMM
- ERASE_ROM: MOV A,RX1
- MOV TX0,RX0
- MOV TX1,RX1
- ERASE_ROM_T0:
- CJNE A,#C51,ERASE_ROM_T1
- AJMP ERASE_C51
- ERASE_ROM_T1:
- CJNE A,#S51,ERASE_ROM_T2
- AJMP ERASE_S51
- ERASE_ROM_T2:
- AJMP _ERASE_20PINS
- _ERASE_C51:
- ACALL ERASE_C51
- ACALL TX_PC
- AJMP WAIT_COMM
- _ERASE_20PINS:
- ACALL REPORT_INVALID
- AJMP WAIT_COMM
- INIT_WRITE:
- MOV A,RX1
- MOV TX0,RX0
- MOV TX1,RX1
- INIT_WRITE_T0:
- CJNE A,#C51,INIT_WRITE_T1
- AJMP INIT_WRITE_C51
- INIT_WRITE_T1:
- CJNE A,#S51,INIT_WRITE_T2
- AJMP INIT_WRITE_S51
- INIT_WRITE_T2:
- AJMP _INIT_WRITE_20PINS
- _INIT_WRITE_20PINS:
- ACALL REPORT_INVALID
- AJMP WAIT_COMM
- WRITE_ROM: MOV A,RX1
- WRITE_ROM_T0:
- CJNE A,#C51,WRITE_ROM_T1
- AJMP WRITE_C51
- WRITE_ROM_T1:
- CJNE A,#S51,WRITE_ROM_T2
- AJMP WRITE_S51
- WRITE_ROM_T2:
- AJMP _WRITE_20PINS
- _WRITE_20PINS:
- ACALL REPORT_INVALID
- AJMP WAIT_COMM
- INIT_READ: SETB P3.0
- MOV A,RX1
- MOV TX0,RX0
- MOV TX1,RX1
- MOV ADDRESS_L,#00H
- MOV ADDRESS_H,#00H
- INIT_READ_C51:
- CJNE A,#C51,INIT_READ_S51
- SJMP INIT_READ_OVER
- INIT_READ_S51:
- CJNE A,#S51,INIT_READ_OVER
- ACALL READY_PROG
- INIT_READ_OVER:
- ACALL TX_PC
- CLR RI
- JNB RI,$; 检查接收的一个字节,查询是否结束
- MOV A,SBUF
- CJNE A,#01H,READ_ROM;01表示结束
- AJMP WAIT_COMM
- READ_ROM: MOV A,RX1
- MOV TX0,#06H
- MOV TX1,RX1
- READ_ROM_T0:
- CJNE A,#C51,READ_ROM_T1
- AJMP READ_C51
- READ_ROM_T1:
- CJNE A,#S51,READ_ROM_T2
- AJMP READ_S51
- READ_ROM_T2:
- AJMP _READ_20PINS
- _READ_20PINS:
- ACALL REPORT_INVALID
- AJMP WAIT_COMM
- LOCK_BIT: MOV TX1,RX1
- MOV TX0,RX0
- MOV A,RX1
- LOCK_BIT_T0:
- CJNE A,#C51,LOCK_BIT_T1
- AJMP LOCK_BIT_C51
- LOCK_BIT_T1:
- CJNE A,#S51,LOCK_BIT_T2
- AJMP LOCK_BIT_S51
- LOCK_BIT_T2:
- AJMP _LOCK_BIT_20PINS
- _LOCK_BIT_20PINS:
- ACALL REPORT_INVALID
- AJMP WAIT_COMM
- READ_SIGN: MOV TX0,RX0
- MOV TX1,RX1
- MOV A,RX1
- READ_SIGN_T0:
- CJNE A,#C51,READ_SIGN_T1
- AJMP READ_SIGN_C51
- READ_SIGN_T1:
- CJNE A,#S51,READ_SIGN_T2
- AJMP READ_SIGN_S51
- READ_SIGN_T2:
- READ_SIGN_20PINS:
- ACALL REPORT_INVALID
- AJMP WAIT_COMM
- ;---------------------------------------------------------------
- ; FOR C51
- ;---------------------------------------------------------------
- WRITE_C51:
- MOV _R0,#RX2
- MOV _R1,#TX2
- WRITE_16BYTES_C51:
- MOV R0,_R0
- MOV PARAM0,@R0
- ACALL _WRITE_C51
- MOV R1,_R1
- MOV @R1,RET0
- MOV A,RET0
- CJNE A,PARAM0,WRITE_RES_ERROR
- INC _R0
- INC _R1
- ACALL INC_ADDRESS
- MOV R0,_R0
- CJNE R0,#RX17+1,WRITE_16BYTES_C51
- AJMP WRITE_RES
- WRITE_RES: MOV SBUF,#00H
- CLR TI
- JNB TI,$
- CLR TI
- AJMP WAIT_COMM
- WRITE_RES_ERROR:
- MOV SBUF,#0FFH
- CLR TI
- JNB TI,$
- CLR TI
- AJMP WAIT_COMM
- INIT_WRITE_C51:
- ACALL MODE_C51
- MOV ADDRESS_L,#00H
- MOV ADDRESS_H,#00H
- ACALL TX_PC
- AJMP WAIT_COMM
- READ_C51:
- MOV _R1,#TX2
- READ_16BYTES_C51:
- ACALL _READ_C51
- MOV R1,_R1
- MOV @R1,RET0
- INC _R1
- ACALL INC_ADDRESS
- MOV R1,_R1
- CJNE R1,#TX17+1,READ_16BYTES_C51
- ACALL TX_PC
- READ_NEXT_C51:
- CLR RI
- JNB RI,$; 检查接收的一个字节,查询是否结束
- MOV A,SBUF
- CJNE A,#01H,READ_C51;01表示结束
- AJMP WAIT_COMM
- _READ_C51:
- SETB RST
- ACALL SET_VPP5 ;设置成读状态 P3.6=H P3.7=H
- SETB PROG ; P2.7=L P2.6=L
- SETB P3.6
- SETB P3.7
- CLR P2.6
- CLR P2.7
- MOV R0,#0FH
- DJNZ R0,$
- MOV P1,ADDRESS_L
- MOV A,#00111111B
- ANL A,ADDRESS_H
- MOV P2,A ;高地址
- MOV P0,#0FFH ;读先置1
- MOV R0,#05H
- DJNZ R0,$
- MOV A,P0
- MOV RET0,A
- RET
- _WRITE_C51:
- SETB PROG
- SETB BUSY
- SETB P2.7
- CLR P2.6
- SETB P3.7
- SETB P3.6
- MOV R0,#05H
- DJNZ R0,$
- MOV A,#10000000B
- ORL A,ADDRESS_H
- MOV P2,A
- MOV A,ADDRESS_L
- MOV P1,A
- MOV A,PARAM0
- MOV P0,A
- MOV R0,#05H
- DJNZ R0,$
- ACALL SET_VPP12
- MOV R0,#05H
- DJNZ R0,$
- CLR PROG
- MOV R0,#05H
- DJNZ R0,$
- SETB PROG
- MOV R0,#05H
- DJNZ R0,$
- MOV P0,#0FFH
- MOV R3,#0FFH
- MOV A,#00H
- DET_BUSY: DJNZ R3,DET_B
- AJMP DET_DATA;超时跳出到数据检测
- DET_B: INC A
- MOV RET2,A
- MOV R0,#05H
- DJNZ R0,$
- JNB BUSY,DET_BUSY
- DET_DATA: MOV R0,#0FFH
- MOV P0,#0FFH
- ACALL SET_VPP5
- CLR P2.7
- DET_D: DJNZ R0,DET_D2
- AJMP WRITE_ERROR
- DET_D2: MOV A,P0
- CJNE A,PARAM0,DET_D
- WRITE_SUC: MOV A,P0
- MOV RET0,A
- MOV RET1,#00H
- RET
- WRITE_ERROR:MOV A,P0
- MOV RET0,A
- ACALL MODE_C51
- MOV RET1,#0FFH
- RET
- LOCK_BIT_C51:
- ACALL MODE_C51
- ACALL SET_VPP5
- LOCK_BIT1_C51:
- MOV A,RX2
- CJNE A,#0FFH,LOCK_BIT2_C51
- SETB PROG
- SETB BUSY
- SETB P2.7
- SETB P2.6
- SETB P3.7
- SETB P3.6
- MOV R0,#0FH
- DJNZ R0,$
- ACALL SET_VPP12
- MOV R0,#0FH
- DJNZ R0,$
- CLR PROG
- MOV R0,#0FH
- DJNZ R0,$
- SETB PROG
- MOV R0,#0FH
- DJNZ R0,$
- ACALL SET_VPP5
- LOCK_BIT2_C51:
- MOV A,RX3
- CJNE A,#0FFH,LOCK_BIT3_C51
- SETB PROG
- SETB BUSY
- SETB P2.7
- SETB P2.6
- CLR P3.7
- CLR P3.6
- MOV R0,#0FH
- DJNZ R0,$
- ACALL SET_VPP12
- MOV R0,#0FH
- DJNZ R0,$
- CLR PROG
- MOV R0,#0FH
- DJNZ R0,$
- SETB PROG
- MOV R0,#0FH
- DJNZ R0,$
- ACALL SET_VPP5
- LOCK_BIT3_C51:
- MOV A,RX4
- CJNE A,#0FFH,LOCK_BIT_C51_RET
- SETB PROG
- SETB BUSY
- CLR P2.7
- SETB P2.6
- CLR P3.7
- SETB P3.6
- MOV R0,#0FH
- DJNZ R0,$
- ACALL SET_VPP12
- MOV R0,#0FH
- DJNZ R0,$
- CLR PROG
- MOV R0,#0FH
- DJNZ R0,$
- SETB PROG
- MOV R0,#0FH
- DJNZ R0,$
- ACALL SET_VPP5
- LOCK_BIT_C51_RET:
- ACALL MODE_C51
- MOV TX0,RX0
- MOV TX1,RX1
- MOV TX2,RX2
- MOV TX3,RX3
- MOV TX4,RX4
- ACALL TX_PC
- AJMP WAIT_COMM
- READ_SIGN_C51:
- MOV ADDRESS_H,#00H
- MOV ADDRESS_L,#30H
- ACALL _READ_SIGN_C51
- MOV TX2,RET0
- MOV ADDRESS_L,#31H
- ACALL _READ_SIGN_C51
- MOV TX3,RET0
- MOV ADDRESS_L,#32H
- ACALL _READ_SIGN_C51
- MOV TX4,RET0
- READ_SIGN_C51_RET:
- ACALL MODE_C51
- ACALL TX_PC
- AJMP WAIT_COMM
- _READ_SIGN_C51:
- SETB RST
- ACALL SET_VPP5 ;设置成读SIGN状态 P3.6=L P3.7=L
- SETB PROG ; P2.7=L P2.6=L
- CLR P3.6
- CLR P3.7
- CLR P2.6
- CLR P2.7
- MOV R0,#0FH
- DJNZ R0,$
- MOV P1,ADDRESS_L
- MOV A,#00111111B
- ANL A,ADDRESS_H
- MOV P2,A ;高地址
- MOV P0,#0FFH ;读先置1
- MOV R0,#0FH
- DJNZ R0,$
- MOV A,P0
- MOV RET0,A
- RET
- ERASE_C51:
- SETB PROG
- SETB P2.6
- CLR P2.7
- CLR P3.7
- CLR P3.6
- ACALL SET_VPP12
- MOV R0,#02H
- ACALL DELAY
- CLR PROG
- MOV R0,#10H
- ACALL DELAY
- SETB PROG
- ACALL MODE_C51
- ACALL TX_PC
- AJMP WAIT_COMM
- VPP_5V: ACALL SET_VPP5
- ACALL TX_PC
- AJMP WAIT_COMM
- VPP_12V: ACALL SET_VPP12
- ACALL TX_PC
- AJMP WAIT_COMM
- SET_VPP12: SETB VPP_12
- JNB F_VPP,WAIT_VPP12
- RET
- WAIT_VPP12: MOV R0,WAIT_VOL
- DJNZ R0,$
- SETB F_VPP
- RET
- SET_VPP5: CLR VPP_12
- JB F_VPP,WAIT_VPP5
- RET
- WAIT_VPP5: MOV R0,WAIT_VOL
- DJNZ R0,$
- CLR F_VPP
- RET
- MODE_C51: ACALL SET_VPP5
- SETB RST
- SETB PROG
- MOV P0,#0FFH
- SETB P3.6
- SETB P3.7
- CLR P2.7
- CLR P2.6
- MOV P2,#00000000B
- MOV P1,#0FFH
- RET
- INC_ADDRESS:MOV R0,ADDRESS_L
- MOV R1,ADDRESS_H
- CJNE R0,#0FFH,INC_LADDR
- INC_HADDR: MOV R0,#00H
- INC R1
- SJMP RET_ADDR
- INC_LADDR: INC R0
- RET_ADDR: MOV ADDRESS_L,R0
- MOV ADDRESS_H,R1
- RET
- ;------------------------------------------------------------
- ; FOR AT89S51
- ;------------------------------------------------------------
- ERASE_S51: ACALL READY_PROG
- MOV SOUT1,#10101100B
- MOV SOUT2,#10000000B
- ACALL SCK_INSTRUC
- MOV R0,#255
- ACALL DELAY
- MOV R0,#255
- ACALL DELAY
- ACALL MODE_S51
- ACALL TX_PC
- AJMP WAIT_COMM
- INIT_WRITE_S51:
- MOV ADDRESS_L,#00H
- MOV ADDRESS_H,#00H
- ACALL READY_PROG
- ACALL TX_PC
- AJMP WAIT_COMM
- WRITE_S51: MOV _R0,#RX2
- MOV _R1,#TX2
- WRITE_16BYTES_S51:
- MOV R0,_R0
- MOV PARAM0,@R0
- ACALL _WRITE_S51
- MOV R1,_R1
- MOV @R1,RET0
- MOV A,RET0
- CJNE A,PARAM0,WRITE_S51_RES_ERROR
- INC _R0
- INC _R1
- ACALL INC_ADDRESS
- MOV R0,_R0
- CJNE R0,#RX17+1,WRITE_16BYTES_S51
- WRITE_S51_RES:
- MOV SBUF,#00H
- CLR TI
- JNB TI,$
- CLR TI
- AJMP WAIT_COMM
- WRITE_S51_RES_ERROR:
- MOV SBUF,#0FFH
- CLR TI
- JNB TI,$
- CLR TI
- ACALL MODE_S51
- AJMP WAIT_COMM
- _WRITE_S51:
- MOV SOUT1,#01000000B
- MOV SOUT2,ADDRESS_H
- MOV SOUT3,ADDRESS_L
- MOV SOUT4,PARAM0
- ACALL SCK_INSTRUC
- MOV RET0,PARAM0
- MOV R0,#1
- ACALL DELAY
- RET
- READ_S51: MOV _R1,#TX2
- READ_16BYTES_S51:
- ACALL _READ_S51
- MOV R1,_R1
- MOV @R1,RET0
- INC _R1
- ACALL INC_ADDRESS
- MOV R1,_R1
- CJNE R1,#TX17+1,READ_16BYTES_S51
- ACALL TX_PC
- READ_NEXT_S51:
- CLR RI
- JNB RI,$; 检查接收的一个字节,查询是否结束
- MOV A,SBUF
- CJNE A,#01H,READ_S51;01表示结束
- ACALL MODE_S51
- AJMP WAIT_COMM
- _READ_S51: MOV SOUT1,#00100000B
- MOV SOUT2,ADDRESS_H
- MOV SOUT3,ADDRESS_L
- MOV SOUT4,#00
- ACALL SCK_INSTRUC
- MOV RET0,SIN4
- RET
- LOCK_BIT_S51:
- ACALL READY_PROG
- MOV SOUT1,#10101100B
- MOV SOUT2,#11100000B
- MOV SOUT3,#00000000B
- MOV SOUT4,#00000000B
- LOCK_BIT1_S51:
- MOV A,RX2
- CJNE A,#0FFH,LOCK_BIT2_S51
- MOV SOUT2,#11100001B
- ACALL SCK_INSTRUC
- MOV R0,#1
- ACALL DELAY
- LOCK_BIT2_S51:
- MOV A,RX3
- CJNE A,#0FFH,LOCK_BIT3_S51
- MOV SOUT2,#11100010B
- ACALL SCK_INSTRUC
- MOV R0,#1
- ACALL DELAY
- LOCK_BIT3_S51:
- MOV A,RX4
- CJNE A,#0FFH,_LOCK_BIT_S51
- MOV SOUT2,#11100011B
- ACALL SCK_INSTRUC
- MOV R0,#1
- ACALL DELAY
- _LOCK_BIT_S51:
- ACALL MODE_S51
- ACALL TX_PC
- AJMP WAIT_COMM
- READ_SIGN_S51:
- ACALL READY_PROG
- MOV SOUT1,#00101000B
- MOV SOUT2,#00000000B
- MOV SOUT3,#00000000B
- ACALL SCK_INSTRUC
- MOV TX2,SIN4
- MOV SOUT1,#00101000B
- MOV SOUT2,#00000001B
- MOV SOUT3,#00000000B
- ACALL SCK_INSTRUC
- MOV TX3,SIN4
- MOV SOUT1,#00101000B
- MOV SOUT2,#00000010B
- MOV SOUT3,#00000000B
- ACALL SCK_INSTRUC
- MOV TX4,SIN4
- ACALL MODE_S51
- ACALL TX_PC
- AJMP WAIT_COMM
- MODE_S51: ACALL INIT_PIN
- CLR SCK
- SETB MISO
- CLR MOSI
- RET
- READY_PROG: ACALL MODE_S51
- SETB RST
- MOV R0,#10
- ACALL DELAY
- MOV SOUT1,#10101100B
- MOV SOUT2,#01010011B
- MOV SOUT3,#00
- MOV SOUT4,#00
- ACALL SCK_INSTRUC
- RET
- SCK_INSTRUC:CLR MOSI
- SETB MISO
- MOV SOUT,SOUT1
- ACALL SCK_BYTE
- MOV SIN1,SIN
- MOV SOUT,SOUT2
- ACALL SCK_BYTE
- MOV SIN2,SIN
- MOV SOUT,SOUT3
- ACALL SCK_BYTE
- MOV SIN3,SIN
- MOV SOUT,SOUT4
- ACALL SCK_BYTE
- MOV SIN4,SIN
- RET
- SCK_BYTE: CLR SCK
- MOV C,SOUT.7
- MOV MOSI,C
- NOP
- SETB SCK
- NOP
- MOV C,MISO
- MOV SIN.7,C
- CLR SCK
- CLR SCK
- MOV C,SOUT.6
- MOV MOSI,C
- NOP
- SETB SCK
- NOP
- MOV C,MISO
- MOV SIN.6,C
- CLR SCK
- CLR SCK
- MOV C,SOUT.5
- MOV MOSI,C
- NOP
- SETB SCK
- NOP
- MOV C,MISO
- MOV SIN.5,C
- CLR SCK
- CLR SCK
- MOV C,SOUT.4
- MOV MOSI,C
- NOP
- SETB SCK
- NOP
- MOV C,MISO
- MOV SIN.4,C
- CLR SCK
- CLR SCK
- MOV C,SOUT.3
- MOV MOSI,C
- NOP
- SETB SCK
- NOP
- MOV C,MISO
- MOV SIN.3,C
- CLR SCK
- CLR SCK
- MOV C,SOUT.2
- MOV MOSI,C
- NOP
- SETB SCK
- NOP
- MOV C,MISO
- MOV SIN.2,C
- CLR SCK
- CLR SCK
- MOV C,SOUT.1
- MOV MOSI,C
- NOP
- SETB SCK
- NOP
- MOV C,MISO
- MOV SIN.1,C
- CLR SCK
- CLR SCK
- MOV C,SOUT.0
- MOV MOSI,C
- NOP
- SETB SCK
- NOP
- MOV C,MISO
- MOV SIN.0,C
- CLR SCK
- RET
- ;------------------------------------------------------------
- ; GOBAL SUB PROCESSES
- ;------------------------------------------------------------
- SET_WAIT: MOV A,RX1 ;设置电压转换所用的时间WAIT_VOL*2 US
- MOV WAIT_VOL,A
- MOV TX1,A
- MOV TX2,A
- ACALL TX_PC
- AJMP WAIT_COMM
- TX_PC: MOV R0,#TX0
- TX_BYTE: CLR TI
- MOV A,@R0
- MOV SBUF,A
- INC R0
- JNB TI,$
- CJNE R0,#TX17+1,TX_BYTE
- CLR TI
- RET
- RX_PC: SETB P3.0
- MOV R0,#RX0
- RX_BYTE: CLR RI
- JNB RI,$
- MOV A,SBUF
- MOV @R0,A
- INC R0
- CJNE R0,#RX17+1,RX_BYTE
- CLR RI
- RET
- DELAY: MOV R1,#0FBH ;延时R0*MS
- MOV R2,#0FBH
- DJNZ R1,$
- DJNZ R2,$
- DJNZ R0,DELAY
- RET
- INIT_PIN: CLR VPP
- CLR RST
- SETB BUSY
- SETB PROG
- MOV P0,#0FFH
- MOV P1,#0FFH
- MOV P2,#0FFH
- SETB P3.7
- SETB P3.6
- RET
- REPORT_ERROR:
- MOV TX0,#0FFH
- ACALL TX_PC
- RET
- REPORT_INVALID:
- MOV TX0,#0F0H
- ACALL TX_PC
- RET