ORG 000H
SJMP CHECK;
org 003H;
Acall INITIAL;
reti
ORG 000BH; interrupt TIIMER routine
ajmp timer
ORG 0030H
CHECK:
MOV TMOD,#29H; ;TR1 M2 / TM0-CT0 M1
MOV IE,#10000011B;
MOV TH1,#0FDH; ;9600BAUD RATE, ,8-BIT,1-STOP BIT;;;;;;;;;;;;;;
MOV SCON,#50H ;01010000b
SETB TI; ; TRANSMIT BIT HIGH, TRANSMITS WHEN LOW
setb TR1;
loop:
MOV R0,2 ;LOADING THE VALUE FOR THE INTERNAL INTERRUPT COUNTER
led4:
clr p1.4
setb p1.5;
mov R3,#10;
JNB INT0,INITIAL;
BL:
MOV R4,#20; ;LOOP FOR REPEATING COUNT
LRPT: ;MAX DELAY
MOV TL1,#0H;
MOV TH1,#0H;
SETB TR1;
LAGAIN:
JNB TF1, LAGAIN;
CLR TR1;
CLR TF1;
DJNZ R4,LRPT;
CPL P1.4;
DJNZ R3,BL;
ret;
[B][COLOR="#FF0000"]INITIAL: This is where the interrupt is being checked
dec R0
cjne @R0,#0,ONloop
MOV A,R0
JNZ OFFloop;
ret[/COLOR][/B]
ONloop:
ACALL DISPLAY_ON
LOP:
clr p1.5;
setb p1.4
mov R5,#4;
BLINK:
MOV R6,#30; LOOP FOR REPEATING COUNT
RPT: ;2 sec DELAY
MOV TL0,#0H;
MOV TH0,#0H;
SETB TR0;
AGAIN:
JNB TF0, AGAIN;
CLR TR0;
CLR TF0;
DJNZ R6,RPT;
CPL P1.5;
DJNZ R5,BLINK;
reti
TRANS:
MOV SBUF, A;
JNB TI,$
CLR TI
ret
OFFloop:
ACALL DISPLAY_OFF
LOP2:
clr p1.5;
setb p1.4
mov R5,#4;
BLINK2:
MOV R6,#30; LOOP FOR REPEATING COUNT
RPT2: ;2 sec DELAY
MOV TL0,#0H;
MOV TH0,#0H;
SETB TR0;
AGAIN2:
JNB TF0, AGAIN2;
CLR TR0;
CLR TF0;
DJNZ R6,RPT2;
CPL P1.5;
DJNZ R5,BLINK2;
RET ; interrupt routine doesnt return to the loop. it turns the led on constantly after blinking it 4 times
DISPLAY_OFF:
setb p1.4
MOV DPTR,#MS1;
MOV R2,4
dis1:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis1
ret
DISPLAY_ON: ;displays ON
setb p1.4
MOV DPTR,#MS;
MOV R7,2
dis:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R7, dis
ret
timer:
PUSH ACC;
SETB P1.4;
SETB P1.5;
POP ACC;
RETI;
MS:DB 13,10,"ON",10,13,0
MS1:DB 13,10,"OFF",10,13,0
END