Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] seriall transmission on interrupts with 89c2051

Status
Not open for further replies.

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
Hello there,
i have been trying to accomplish the following task for about a week and couldn't get the 1st part of it to run in a loop. kindly help me debug the program in assembly language.

1- Power on the system auto blinks led 1 at 1hz

2- Microcontroller switch connected to int0 is pressed:

a. led1 should halt the routine loop & led 2 should start blinking at 2hz

b. At the same time, the circuit should send “ON” on HyperTerminal.

c. After that LED1 should resume blinking at 1HZ as usual.

3- On subsequent button press item “a” should repeat and item b should switch to “OFF”.

4- Cycle should repeat b/w “ONN & OFF”

P.S: Immediate printing




following is the bugged code. it doesnt return from printing "ON". I always have to reset the circuit manually.

Code:
ORG 000H
sjmp main
		
ORG 000BH;            interrupt TIIMER routine
		PUSH ACC;
		SETB P1.4;
		SETB P1.5;
		POP ACC;
		RETI;

		
ORG 0003H;
	LJMP  loop;

ORG 00F0H
	MS:DB 13,10,"ON",10,13,0		

ORG 00F9H
	MS1: DB 13,10, "OFF",10,13,0
  
ORG 030H
	main:	
MOV IE,#10000011B;
MOV TMOD,#29H;               '9600BAUD RATE,8-BIT,1-STOP BIT;;;;;;;;;;;;;;
MOV TH1,#0FDH;	
MOV SCON,#50H                ;01010000b
SETB TI;                      ; TRANSMIT BIT HIGH, TRANSMITS WHEN LOW
setb TR1;

start:

sjmp subloop1;
SJMP MAIN;

subloop1:                   
        CLR P1.5;
		setb p1.4;
		MOV R0,#4;     BLINK LOOP ON OFF
		ACALL BLINK
		JNB INT0,loop
BLINK:
		START1:
		MOV R1,#25;            LOOP FOR REPEATING COUNT
		RPT:                   ;1 sec DELAY
		MOV TL0,#0H;
        MOV TH0,#0H;
		SETB TR0;
		AGAIN: 
		JNB TF0, AGAIN;
		CLR TR0;
		CLR TF0;
		DJNZ R1,RPT;
		CPL P1.5;
		DJNZ R0,BLINK;
        LJMP MAIN;

loop:                       
		setb p1.5;
		mov R3,#4;
		BL:
		MOV R4,#30;              LOOP FOR REPEATING COUNT
		LRPT:                   ;2 sec 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;
		CLR A
		SJMP DISPLAY1
		
DISPLAY1:                   ;displays ON
setb p1.4
MOV DPTR,#MS;
MOV R4,3
dis:
CLR A
MOVC A,@A+DPTR;
JZ S1;
acall TRANS
S1:SJMP S1;
ret;
TRANS:
MOV SBUF, A;
JNB TI,$
CLR TI
INC DPTR;
DJNZ R4,dis;
reti;

END;
any help will be much appreciated. thank you
 

Hi,

First you need to reduce your code to the minimum.
The start to implement your first task.
Debug it, make it run.
Then start to inplement the next task (only if the previous running as desired)

If you encounter a problem, then give detailed description.
Post the code, tell us what you expect it to do, and tell us what happens instead.

Klaus
 
  • Like
Reactions: hsa.a

    hsa.a

    Points: 2
    Helpful Answer Positive Rating
I wish to run a subroutine continuously that should blink led on 1hz i.e, one second on and one second off. when a button on interrupt pin3.2 is pressed the subroutine should hault and should perform two functions before returning to the subroutine; a) display the following message on monitor, "ON"
b) 4 times blink another led for 2hz and then return to the subroutine.
the problem with the following code is that on int0 it 4 Times blinks the led at 2HZ and then displays "ON" but never returns to the subroutine(led blink at 1hz).
Code:
ORG 000H
sjmp main
		
ORG 000BH;            interrupt TIIMER routine
		PUSH ACC;
		SETB P1.4;
		SETB P1.5;
		POP ACC;
		RETI;

		
ORG 0003H;
	LJMP  loop;

ORG 00F0H                          ;MEMORY ADDRESS FOR THE STRING "ON"
	MS:DB 13,10,"ON",10,13,0		
  
ORG 030H
	main:	
	MOV IE,#10000011B;            : ENABLING INTERRUPT
MOV TMOD,#29H;               '9600BAUD RATE,8-BIT,1-STOP BIT;;;;;;;;;;;;;;
MOV TH1,#0FDH;	
MOV SCON,#50H                ;01010000b
SETB TI;                      ; TRANSMIT BIT HIGH, TRANSMITS WHEN LOW
setb TR1;

start:
sjmp subloop1;
SJMP MAIN;

subloop1:                   
        CLR P1.5;
		setb p1.4;
		MOV R0,#4;     BLINK LOOP ON OFF
		ACALL BLINK
		JNB INT0,loop
BLINK:
		START1:
		MOV R1,#25;            LOOP FOR REPEATING COUNT
		RPT:                   ;1 sec DELAY
		MOV TL0,#0H;
        MOV TH0,#0H;
		SETB TR0;
		AGAIN: 
		JNB TF0, AGAIN;
		CLR TR0;
		CLR TF0;
		DJNZ R1,RPT;
		CPL P1.5;
		DJNZ R0,BLINK;
        LJMP MAIN;

loop:                       
		
		setb p1.5;
		mov R3,#4;
		BL:
		MOV R4,#30;              LOOP FOR REPEATING COUNT
		LRPT:                   ;2 sec 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;
		clr A
		ACALL DISPLAY1
		RETI
DISPLAY1:                   ;displays ON
setb p1.4
MOV DPTR,#MS;
MOV R4,3
dis:
CLR A
MOVC A,@A+DPTR;
JZ S1;
acall TRANS
S1:SJMP S1;
ret;
TRANS:
MOV SBUF, A;
JNB TI,$
CLR TI
INC DPTR;
DJNZ R4,dis;
reti;
END;
 

Hi,

some problems:
* 1s ON and 1s OFF makes 2s in total = 0.5Hz
--> if you want 1Hz, then you should go for 0.5s ON and 0.5s OFF

* "I wish to run a subroutine continuously". Continously makes no sense. If you do so, then no processing power is available for other tasks.
Including a second task is impossible.

--> you may run it repeatedly. You should decide how often per second.
This could be done in a timer controlled ISR, but you can do this also in main loop by checking a timer/counter flag.

Example:
For the 1Hz blinking LED you need to run it at least twice per second. = every 500ms.
So you could use a timer to create an overflow (set flag) every 500ms. then toggle the LED on every timer event.
you could run a timer to create an event every 100ms and toggle the LED on every 5th event. (you need a counter to count from 0 to 4 ... or back)

Look ahead for future tasks:
To react on key press you should run the keyboard task about 20 times per second, to be able to react on short key press.
This means every 50ms. I think this is your fastest task.

Back to the LED:
If you create an event every 50ms then the LED has to toggle every 10th event.

***
Pseudo code:

Set up hardware
set up timer to set a flag every 50ms
main loop:
{
wait for flag
run LED blink task
(later you will include here other tasks)
}

***
Mind that all tasks together should not last longer than 50ms. --> only very short busy waits are allowed.

Klaus
 
  • Like
Reactions: hsa.a

    hsa.a

    Points: 2
    Helpful Answer Positive Rating
what you are suggesting regarding the count of blinks and then over flow is what i have done i guess in the following program
Code:
subloop1:                   
        CLR P1.5;
		setb p1.4;
		MOV R0,#4;     BLINK LOOP ON OFF
		ACALL BLINK
		JNB INT0,loop
BLINK:
		START1:
		MOV R1,#20;            LOOP FOR REPEATING COUNT
		RPT:                   ;1 sec DELAY
		MOV TL0,#0H;
        MOV TH0,#0H;
		SETB TR0;
		AGAIN: 
		JNB TF0, AGAIN;
		CLR TR0;
		CLR TF0;
		DJNZ R1,RPT;
		CPL P1.5;
		DJNZ R0,BLINK;
        LJMP main;
 

i changed the code a bit, the program wasn't returning from the int0 loop to my sub routine despite writing "reti" command. therefore, i have given "sjmp main" in the into loop. Although it returns to the subroutine but does'nt read int0 again. what could be the possible error?
Code:
main:	
CLR IE.7;
MOV IE,#10000011B;            : ENABLING INTERRUPT
MOV TMOD,#29H;               '9600BAUD RATE,8-BIT,1-STOP BIT;;;;;;;;;;;;;;
MOV TH1,#0FDH;	
MOV SCON,#50H                ;01010000b
SETB TI;                      ; TRANSMIT BIT HIGH, TRANSMITS WHEN LOW
setb TR1;

subloop1:                   ; subroutine
        CLR P1.5;
		setb p1.4;
		MOV R0,#4;     BLINK LOOP ON OFF
		ACALL BLINK
		JNB INT0,loop
BLINK:
		START1:
		MOV R1,#20;            LOOP FOR REPEATING COUNT
		RPT:                   ;1 sec DELAY
		MOV TL0,#0H;
        MOV TH0,#0H;
		SETB TR0;
		AGAIN: 
		JNB TF0, AGAIN;
		CLR TR0;
		CLR TF0;
		DJNZ R1,RPT;
		CPL P1.5;
		DJNZ R0,BLINK;
        LJMP main;

loop:                                           ;interrupt routine
		ACALL DISPLAY1
		LOP:
		setb p1.5;
		mov R3,#4;
		BL:
		MOV R4,#30;              LOOP FOR REPEATING COUNT
		LRPT:                   ;2 sec 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 MAIN

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


END;
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top