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
ORG 000H
MAIN:
MOV IE,#10001011B;
MOV TMOD,#00101101B; ;TR1 M2 / TM0-CT0 M1
MOV TH1,#0FDH; ;9600BAUD RATE, ,8-BIT,1-STOP BIT;;;;;;;;;;;;;;
MOV SCON,#50H ;01010000b
SETB TI; ; TRANSMIT BIT HIGH, TRANSMITS WHEN LOW
setb TR1;
SJMP loop
ORG 000BH; interrupt TIIMER routine
PUSH ACC;
SETB P1.4;
SETB P1.5;
POP ACC;
RETI;
ORG 0003H;
AJMP INITIAL;
ORG 00F0H ;MEMORY ADDRESS FOR THE STRING "ON"
MS:DB 13,10,"ON",10,13,0
ORG 00F9H
MS1:DB 13,10,"OFF",10,13,0
ORG 0030H
loop:
MOV R0,0 ; LOADING THE VALUE FOR THE INTERNAL INTERRUPT COUNTER
led4:
clr p1.4
setb p1.5;
mov R3,#4;
JNB INT0,INITIAL;
BL:
MOV R4,#30; 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;
SJMP led4;
INITIAL:
INC R0
CJNE R0,#1,ONloop ; comparing the value of the register bank
CJNE R0,#2,OFFloop
LJMP MAIN;
ONloop:
ACALL DISPLAY1
LOP:
clr p1.5;
setb p1.4
mov R3,#4;
BLINK:
MOV R4,#150; 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 R4,RPT;
CPL P1.5;
DJNZ R3,BLINK;
SJMP led4
ORG 00B0H;
TRANS:
MOV SBUF, A;
JNB TI,$
CLR TI
ret
DISPLAY1: ;displays ON
setb p1.4
MOV DPTR,#MS;
MOV R2,2
dis:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis
RET
OFFloop:
ACALL DISPLAY2
ACALL LOP
LJMP MAIN;
DISPLAY2:
setb p1.4
MOV DPTR,#MS1;
MOV R2,3
dis1:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis1
RET
END
I'm no expert in 89C2051 but at first glance there is something wrong with the start of your program. You set ORG to 000H, follow it with 7 instructions (I'm not sure how many bytes they actually use) then later have an ORG 003H and another instruction. I think you are overwriting some of the resulting code, the part that initialises the UART.
Brian.
actually those addresses are of the Interrupt service routine for timer and interrupt 0.
They may well be vectors for the ISR but when you set ORG to 000H it sets the address where the following instructions are located. They then occupy consecutive addresses. By setting ORG to 003H you again set the location for the following instructions so you overwrite what you just placed there.
You probably want to make the instruction at 000H a jump to MAIN: rather than place the code at 000H.
Brian.
ORG 000H
Sjmp MAIN
ORG 000BH; interrupt TIIMER routine
PUSH ACC;
SETB P1.4;
SETB P1.5;
POP ACC;
RETI;
ORG 0003H;
AJMP INIT;
ORG 00F0H ;MEMORY ADDRESS FOR THE STRING "ON"
MS:DB 13,10,"ON",10,13,0
ORG 00F9H
MS1:DB 13,10,"OFF",10,13,0
ORG 0030H
MAIN:
MOV IE,#10001011B;
MOV TMOD,#00101101B; ;TR1 M2 / TM0-CT0 M1
MOV TH1,#0FDH; ;9600BAUD RATE, ,8-BIT,1-STOP BIT;;;;;;;;;;;;;;
MOV SCON,#50H ;01010000b
SETB TI; ; TRANSMIT BIT HIGH, TRANSMITS WHEN LOW
setb TR1;
SJMP loop
They may well be vectors for the ISR but when you set ORG to 000H it sets the address where the following instructions are located. They then occupy consecutive addresses. By setting ORG to 003H you again set the location for the following instructions so you overwrite what you just placed there.
You probably want to make the instruction at 000H a jump to MAIN: rather than place the code at 000H.
Brian.
ORG 000H
Sjmp MAIN
ORG 000BH; interrupt TIIMER routine
PUSH ACC;
SETB P1.4;
SETB P1.5;
POP ACC;
RETI;
ORG 0003H;
AJMP INIT;
ORG 00F0H ;MEMORY ADDRESS FOR THE STRING "ON"
MS:DB 13,10,"ON",10,13,0
ORG 00F9H
MS1:DB 13,10,"OFF",10,13,0
ORG 0030H
MAIN:
MOV IE,#10001011B;
MOV TMOD,#00101101B; ;TR1 M2 / TM0-CT0 M1
MOV TH1,#0FDH; ;9600BAUD RATE, ,8-BIT,1-STOP BIT;;;;;;;;;;;;;;
MOV SCON,#50H ;01010000b
SETB TI; ; TRANSMIT BIT HIGH, TRANSMITS WHEN LOW
setb TR1;
SJMP loop
They may well be vectors for the ISR but when you set ORG to 000H it sets the address where the following instructions are located. They then occupy consecutive addresses. By setting ORG to 003H you again set the location for the following instructions so you overwrite what you just placed there.
You probably want to make the instruction at 000H a jump to MAIN: rather than place the code at 000H.
Brian.
ORG 000H
MAIN:
MOV IE,#10001011B;
MOV TMOD,#00101101B; ;TR1 M2 / TM0-CT0 M1
MOV TH1,#0FDH; ;9600BAUD RATE, ,8-BIT,1-STOP BIT;;;;;;;;;;;;;;
MOV SCON,#50H ;01010000b
SETB TI; ; TRANSMIT BIT HIGH, TRANSMITS WHEN LOW
setb TR1;
SJMP loop
ORG 000BH; interrupt TIIMER routine
PUSH ACC;
SETB P1.4;
SETB P1.5;
POP ACC;
RETI;
ORG 0003H; interrupt 0 routine
AJMP INITIAL;
ORG 0030H
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,#30; 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;
SJMP led4;
INITIAL:
DEC R0
CJNE R0,#0,ONloop ; comparing the value of the register bank
SJMP OFFloop
LJMP MAIN;
ONloop:
ACALL DISPLAY1
LOP:
clr p1.5;
setb p1.4
mov R3,#4;
BLINK:
MOV R4,#150; 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 R4,RPT;
CPL P1.5;
DJNZ R3,BLINK;
SJMP led4;
TRANS:
MOV SBUF, A;
JNB TI,$
CLR TI
ret
DISPLAY1: ;displays ON
setb p1.4
MOV DPTR,#MS;
MOV R2,2
dis:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis
RET
MS:DB 13,10,"ON",10,13,0
OFFloop:
ACALL DISPLAY2
ACALL LOP
LJMP MAIN;
DISPLAY2:
setb p1.4
MOV DPTR,#MS1;
MOV R2,3
dis1:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis1
RET;
MS1:DB 13,10,"OFF",10,13,0
END
Please post the whole code.
Why do you have so many ORGs in your program? T
Brian.
There is no reti in org 3h interrupt. But i am not sure if that is the issue.
000 - ORG 000H
MAIN:
000 - MOV IE,#10001011B;
002 - MOV (the bytes for the AJMP instruction at 003 and 004)
005 - (the second half of the MOV TH1,#0FDH instruction)
006 - MOV SCON,#50H ;01010000b
008 - SETB TI; ; TRANSMIT BIT HIGH, TRANSMITS WHEN LOW
009 - setb TR1;
00A - SJMP C0 (then the accumulator address)
You still have the same problem with addresses - I will try to explain:...
which (if I got the instruction lengths right) is not what you thought you were coding!
ORG 000H
SJMP CHECK;
org 003H;
AJMP INITIAL
RETI
ORG 000BH; interrupt TIIMER routine
PUSH ACC;
SETB P1.4;
SETB P1.5;
POP ACC;
RETI;
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,#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:
DEC R0
CJNE R0,#0,ONloop ; comparing the value of the register bank
reti;
ONloop:
ACALL DISPLAY1
LOP:
clr p1.5;
setb p1.4
mov R3,#4;
BLINK:
MOV R4,#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 R4,RPT;
CPL P1.5;
DJNZ R3,BLINK;
SJMP led4;
TRANS:
MOV SBUF, A;
JNB TI,$
CLR TI
ret
DISPLAY1: ;displays ON
MS:DB 13,10,"ON",10,13,0
setb p1.4
MOV DPTR,#MS;
MOV R2,2
dis:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis
SJMP LOP
OFFloop:
ACALL DISPLAY2
ACALL LOP
LJMP CHECK;
DISPLAY2:
CLR A
setb p1.4
MOV DPTR,#MS1;
MOV R2,3
dis1:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis1
ljmp CHECK
MS1:DB 13,10,"OFF",10,13,0
END
ORG 000H
sjmp Main ;jump to start of main code
ORG 003H
ajmp Int0ISR ;jump to the INT0 ISR routine
ORG 00BH
ajmp TimerISR ;jump to the timer ISR routine
Main:
< code to initialize registers goes here >
Loop:
< code to be repeated goes here >
sjmp Loop ;go back to the start of Loop again
Int0ISR:
< code to process INTO goes here >
reti ;return back to code before the ISR was triggered
TimerISR:
< code to process timer interrupt goes here >
reti ;return back to code before the ISR was triggered
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
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;
JNB INT0,INITIAL;
LAGAIN:
JNB TF0, LAGAIN;
CLR TR0;
CLR TF0;
DJNZ R4,LRPT;
CPL P1.4;
DJNZ R3,BL;
JNB INT0,INITIAL;
SJMP check;
INITIAL:
dec r0
cjne R0,#1,OFFloop
acall ONloop;
reti
ONloop:
ACALL DISPLAY1
LOP:
clr p1.5;
setb p1.4
mov R3,#4;
BLINK:
MOV R4,#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 R4,RPT;
CPL P1.5;
DJNZ R3,BLINK;
ret
TRANS:
MOV SBUF, A;
JNB TI,$
CLR TI
ret
OFFloop:
ACALL DISPLAY2
ACALL LOP
reti
DISPLAY2:
CLR A
setb p1.4
MOV DPTR,#MS1;
MOV R2,3
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 R2,2
dis:
CLR A
MOVC A,@A+DPTR;
acall TRANS
INC DPTR;
DJNZ R2, dis
ret
timer:
PUSH ACC;
SETB P1.4;
SETB P1.5;
POP ACC;
RETI;
END
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?