hsa.a
Junior Member level 3
- Joined
- Dec 15, 2016
- Messages
- 30
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 232
So think where the code goes back to after the 'reti'. It tries to resume form the address it saved when the interrupt occurred - but no address was saved so it jumps to a random address.
Brian.
ORG 000H
SJMP CHECK;
org 003H;
AJMP INITIAL
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;
MS:DB 13,10,"ON",10,13,0
MS1:DB 13,10,"OFF",10,13,0
sjmp loop;
loop:
MOV R0,2 ;LOADING THE VALUE FOR THE INTERNAL INTERRUPT COUNTER
led4:
clr p1.4
setb p1.5;
mov R3,#4;
JNB INT0,INITIAL;
BL:
MOV R4,#15; ;LOOP FOR REPEATING COUNT
LRPT: ;MAX DELAY
MOV TL0,#0H;
MOV TH0,#0H;
SETB TR0;
LAGAIN:
JNB TF0, LAGAIN;
CLR TR0;
CLR TF0;
DJNZ R4,LRPT;
CPL P1.4;
DJNZ R3,BL;
SJMP led4;
INITIAL: ; im suspecting this check loop for interrupt as well
[COLOR="#FF0000"][U][B]dec r0
cjne @R0,#1,OFFloop
acall ONloop;
reti[/B][/U][/COLOR]
ONloop:
ACALL DISPLAY1
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;
ret
TRANS:
MOV SBUF, A;
JNB TI,$
CLR TI
ret
OFFloop:
ACALL DISPLAY2
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;
RETI ; interrupt routine doesnt return to the loop. it turns the led on constantly after blinking it 4 times
DISPLAY2:
CLR A
setb p1.4
MOV DPTR,#MS1;
MOV R2,4
dis1:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis1
ret
DISPLAY1: ;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;
END
Hi,
But you used a JUMP (not a CALL) to enter INITIAL, therefore there is n return address on the stack.
Never enter a subroutine with a JUMP (unless you are experienced enough)
Klaus
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;
MS:DB 13,10,"ON",10,13,0
MS1:DB 13,10,"OFF",10,13,0
loop:
MOV R0,2 ;LOADING THE VALUE FOR THE INTERNAL INTERRUPT COUNTER
led4:
clr p1.4
setb p1.5;
mov R3,#4;
JNB INT0,INITIAL;
BL:
MOV R4,#15; ;LOOP FOR REPEATING COUNT
LRPT: ;MAX DELAY
MOV TL0,#0H;
MOV TH0,#0H;
SETB TR0;
LAGAIN:
JNB TF0, LAGAIN;
CLR TR0;
CLR TF0;
DJNZ R4,LRPT;
CPL P1.4;
DJNZ R3,BL;
ret;
INITIAL:
dec r0
cjne @R0,#1,OFFloop
acall ONloop;
ret
ONloop:
ACALL DISPLAY1
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;
ret
TRANS:
MOV SBUF, A;
JNB TI,$
CLR TI
ret
OFFloop:
ACALL DISPLAY2
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;
RETI ; interrupt routine doesnt return to the loop. it turns the led on constantly after blinking it 4 times
DISPLAY2:
CLR A
setb p1.4
MOV DPTR,#MS1;
MOV R2,4
dis1:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis1
ret
DISPLAY1: ;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;
END
Hi,
A hint:
I assume your editor has a search function. Search on "ret". It will show all RET and RETI. Decide on every single item if it is correct.
Still missing the fow chart.
Klaus
start --> initialize the registers
loop:
wait for a signal to say the interrupt occurred --> go back to loop until you see it.
reset the signal so you are ready for the next interrupt
increment a counter
if the LSB of the counter is set, point to the address of "MS" otherwise point to the address of "MS1"
blink the LED
call a subroutine to send the message
jump back to loop:
set the signal to say there was an interrupt
reti
get the first character
sendloop:
if it is zero then return (ret)
wait until the UART is free to accept a character
pass the character to the UART
point to the next character
jump back to sendloop:
Thank you for the flow chart, I have some questions which mightl help to simplify it:
1. take the 'ON' route, when you say 'blink LED at 2Hz" do you mean just one flash lasting 0.5 seconds or a continuous flash at that speed? Bear in mind the next stop along the flow says "Blink LED at 1Hz" so somewhere there has to be a gap or you get a single flash at 0.75 seconds!Brian.
2. the "OFF" route is similar but resets R0 along the way. Again, exactly what blink is needed?
Brian.
Well, led1 blinks continuously until an interrupt is generated. it was, for this reason, I used "sjmp led4" commandHi,
Here you see that immediately after each "Set 2Hz" there follows the "Set 1Hz" ... so how long do you think the "1Hz "is valid?
Klaus
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;
MS:DB 13,10,"ON",10,13,0
MS1:DB 13,10,"OFF",10,13,0
loop:
MOV R0,2 ;LOADING THE VALUE FOR THE INTERNAL INTERRUPT COUNTER
led4:
clr p1.4
setb p1.5;
mov R3,#4;
JNB INT0,INITIAL;
BL:
MOV R4,#15; ;LOOP FOR REPEATING COUNT
LRPT: ;MAX DELAY
MOV TL0,#0H;
MOV TH0,#0H;
SETB TR0;
LAGAIN:
JNB TF0, LAGAIN;
CLR TR0;
CLR TF0;
DJNZ R4,LRPT;
CPL P1.4;
DJNZ R3,BL;
ret;
INITIAL:
dec R0
cjne @R0,#1,ONloop
acall OFFloop;
ret
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;
END
ON
OFF
¨Â”Ò•{0²|uŠuŒÒŒ0ýÂŒÂÜï²”Ûé"¶¡"ЕҔ}~uŠuŒÒŒ0ýÂŒÂÞﲕÝé2õ™0™
i didnt quite understand what you mean by making a seperate flow chart for ISR.
I understand what you mean but you actually have it backwards... Hz is a measure of frequency, 1Hz means it happens once a second, 2Hz means twice a second so it takes half as long, not twice as long! 1Hz = 1 second, 2 Hz = 0.5 seconds so you actually want 1Hz and 0.5Hz to give 1 second blink and 2 second blinks.by 2 hz i mean that turn on and off time will be off 2sec. i am runinng this 4 times so altogether it takes 8 sec to execute the interrupt loop.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?