本帖最后由 ewewre 于 2011-6-19 15:12 编辑
一个程序里,两个中断,怎样联系起来呀!求大侠指点下!
串口是给数码管赋初值的,外部中断是加1
还有这数据是怎么存进时钟芯片DS12C887的
程序如下:
ORG 0000H
LJMP START
ORG 0003H
LJMP IRREC
ORG 0013H
LJMP COUNTER
ORG 0023H
LJMP RS232
ORG 0030H
START: MOV SP,#70H
RESET: MOV R1,#00H
RESET_1:MOV R2,#00H
DJNZ R2,$
DJNZ R1,RESET_1
MOV PCON,#00H
MOV TMOD,#21H
MOV SCON,#50H
MOV TH1,#0FDH
MOV TL1,#0FDH
MOV TH0,#00H
MOV TL0,#00H
MOV TCON,#45H
MOV IE,#95H
MOV R0,#30H
MOV R5,#08H
MOV DPTR,#000EH
SJMP $
MOV DPTR,#000AH
MOV A,#20H
MOVX @DPTR,A
MOV DPTR,#000BH
MOV A,#02H
MOVX @DPTR,A
MAIN: MOV SP,#70H
DISPL: MOV DPTR,#000AH
MOVX A,@DPTR
JB ACC.7,DISPL
MOV R1,#30H
MOV R2,#0CH
MOV DPTR,#000EH
DISPL_1:MOVX A,@DPTR
MOV @R1,A
INC DPL
INC R1
DJNZ R2,DISPL_1
DISPL_2:MOV R0,#30H
LCALL UNDISP0_4
MOV R0,#34H
LCALL UNDISP0_4
DISPL_3:MOV R1,#3BH
MOV R2,#0CH
DISPL_4:MOV A,@R1
LCALL BDISP
DEC R1
DJNZ R2,DISPL_4
SETB P1.2
NOP
NOP
CLR P1.2
LCALL DELAY
LJMP MAIN
UNDISP0_4:
MOV A,@R0
CJNE A,#00H,OUTUNDISP0_4
MOV @R0,#0AH
INC R0
MOV A,@R0
CJNE A,#00H,OUTUNDISP0_4
MOV @R0,#0AH
INC R0
MOV A,@R0
CJNE A,#00H,OUTUNDISP0_4
MOV @R0,#0AH
OUTUNDISP0_4:
RET
BDISP: PUSH DPL
PUSH DPH
MOV DPTR,#LED
MOVC A,@A+DPTR
MOV R4,#08H
BDISP_1:JB ACC.1,BDISP_2
SETB P1.0
SJMP BDISP_3
BDISP_2:CLR P1.0
BDISP_3:CLR P1.1
NOP
NOP
SETB P1.1
RR A
DJNZ R4,BDISP_1
CLR P1.2
POP DPH
POP DPL
RET
DELAY: MOV R5,#02H
DELAY_1:MOV R6,#00H
DELAY_2:MOV R7,#00H
DJNZ R7,$
DJNZ R6,DELAY_2
DJNZ R5,DELAY_1
RET
COUNTER:CLR EX0
CLR EX1
CLR EA
MOV R5,#02H
COUNTER_1:
MOV R6,#00H
COUNTER_2:
MOV R7,#00H
DJNZ R7,$
DJNZ R6,COUNTER_2
DJNZ R5,COUNTER_1
JB P3.3,OUTCOUNTER
MOV R1,#30H
MOV R2,#0CH
MOV DPTR,#000EH
COUNTER_4:
MOVX A,@DPTR
MOV @R1,A
INC DPL
INC R1
DJNZ R2,COUNTER_4
MOV R0,#37H
MOV R1,#04H
LCALL NUMADD
LCALL DISPERSION
COUNTER_5:
MOV R1,#30H
MOV R2,#0CH
MOV DPTR,#000EH
COUNTER_6:
MOV A,@R1
MOVX @DPTR,A
INC DPL
INC R1
DJNZ R2,COUNTER_6
OUTCOUNTER:
POP DPH
POP DPL
MOV DPTR,#MAIN
PUSH DPL
PUSH DPH
CLR IE0
SETB EX0
CLR IE1
SETB EX1
SETB EA
RETI
RS232: JBC RI,RS232_1;是接收中断,清除此标志,转向LOOP接收
CLR TI;是发送中断,清除此标志,中断返回
SJMP ENDT
RS232_1:CLR RI
CLR EX0
CLR EX1
CLR ES
CLR EA
MOV A,SBUF
MOVX @DPTR,A;存放接收数据
MOV @R0,A;存放数据到30H开头的RAM-----------
MOV 6AH,A
MOV A,#88H;
MOV SBUF,A;发送"正确"应答信号
RS232_2:MOV A,@R0
LCALL BDISP
SETB P1.2
NOP
NOP
CLR P1.2
NOP
NOP
INC DPTR ;修改数据区指针
INC R0 ;修改数据区指针-------------
DJNZ R5,ENDT;数据块尚未接完,返回
CJNE A,#'$',ENDT
CLR ES ;所有数据接收完毕,禁止串行中断
ENDT: CLR IE0
SETB EX0
CLR IE1
SETB EX1
CLR RI
SETB ES
SETB EA
RETI
NUMADD: MOV B,#01H
NUMADD_1:
MOV A,@R0
ADD A,B
DA A
MOV B,A
ANL A,#0FH
MOV @R0,A
MOV A,B
ANL A,#0F0H
SWAP A
MOV B,A
DEC R0
DJNZ R1,NUMADD_1
RET |