+ Post New Thread
Results 1 to 6 of 6
  1. #1
    Junior Member level 3
    Points: 175, Level: 2

    Join Date
    Dec 2016
    Posts
    30
    Helped
    0 / 0
    Points
    175
    Level
    2

    seriall transmission on interrupts with 89c2051

    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

    •   Alt14th March 2017, 07:50

      advertising

        
       

  2. #2
    Super Moderator
    Points: 48,654, Level: 53
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    9,971
    Helped
    2387 / 2387
    Points
    48,654
    Level
    53

    Re: seriall transmission on interrupts with 89c2051

    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


    1 members found this post helpful.

    •   Alt14th March 2017, 08:05

      advertising

        
       

  3. #3
    Junior Member level 3
    Points: 175, Level: 2

    Join Date
    Dec 2016
    Posts
    30
    Helped
    0 / 0
    Points
    175
    Level
    2

    Re: seriall transmission on interrupts with 89c2051

    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;



    •   Alt14th March 2017, 09:11

      advertising

        
       

  4. #4
    Super Moderator
    Points: 48,654, Level: 53
    Awards:
    Most Frequent Poster

    Join Date
    Apr 2014
    Posts
    9,971
    Helped
    2387 / 2387
    Points
    48,654
    Level
    53

    Re: seriall transmission on interrupts with 89c2051

    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


    1 members found this post helpful.

  5. #5
    Junior Member level 3
    Points: 175, Level: 2

    Join Date
    Dec 2016
    Posts
    30
    Helped
    0 / 0
    Points
    175
    Level
    2

    Re: seriall transmission on interrupts with 89c2051

    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;



    •   Alt15th March 2017, 06:37

      advertising

        
       

  6. #6
    Junior Member level 3
    Points: 175, Level: 2

    Join Date
    Dec 2016
    Posts
    30
    Helped
    0 / 0
    Points
    175
    Level
    2

    Re: seriall transmission on interrupts with 89c2051

    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;



--[[ ]]--