Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
12/11/09 07:40
Read: times


 
#171550 - I got (I)T2 working !!!
Responding to: ???'s previous message
Hello everybody!
I was trying to use T2 interrupt alongwith counter to call Inputs & Display subroutines after counter becomes Zero. I was Setting or Clearing LEDs in Display subroutine according to ACC bits loaded during Inputs subroutine. I was using LEDs at P1.0 & P1.1 alongwith other LEDs.
Earlier code used T2 in auto reload, (not in plain timer mode)which I think used to cause flickerring the LED at P1.0. Also, when LED at P1.1 was toggled in Display subroutine, the ISR_T2 didn't work & program remained in Main loop.
It was after I went through your (everyone who helped) messages, I was able to run the complete program successfully.
I'm putting here the ISR_T2 code for your reference, wherein I've tried to improve upon comments side. Hope I am on the right track!

        ;DEFINE  SFRs RELATED TO TIMER2
	
        T2MOD EQU 0C9H	;
        T2CON EQU 0C8H	;
        RCAP2H EQU 0CBH	;
        RCAP2L EQU 0CAH	;
        TL2 EQU 0CCH	;
        TH2 EQU 0CDH	;
        CTR EQU 2AH	; USED AS COUNTER FOR T2 INTERRUPT
        TR2 BIT 0CAH	;
        EXF2 BIT 0CEH	;
        TF2 BIT 0CFH	;
;***********************************************************************
;***********************************************************************	
                ORG 0000H	;
                LJMP BOOT	; INITIALIZATION

                ORG 002BH	; 
                SJMP ISR_T2	; JUMP TO ISR_T2
		
                ORG 0030H       ; INTERRUPT SERVICE ROUTINE FOR T2
ISR_T2:         PUSH PSW        ;
                CLR TR2	        ; STOP TIMER2 
                CLR TF2	        ; CLEAR TIMER2 FLAG
                CLR EXF2        ; (CLR EXF2 => T2CON.6)
                DJNZ CTR, EXIT  ; DON'T CALL INPUTS SUBROUTINE UNLESS COUNTER=0
                                ; CTR IS USED AS COUNTER 
                ACALL INPUTS    ; ELSE GET INPUTS IN ACCUMULATOR
                ACALL DISPLAY   ; & DISPLAY LEDs ACCORDINGLY
                MOV CTR, #10H   ; RESET COUNTER TO 10h
                JNB 2DH, EXIT1  ; IS FAULTY CONDITION? IF NO, JMP (2Dh used to aknowledge Fault)
                MOV CTR, #20H   ; FAULT=YES, THEN INCREASE TIME TO CALL INPUTS & DISPLAY
EXIT1:          JNB 30H, EXIT   ; IS INSIDE MAIN LOOP, IF NO, JMP (30h used to aknowledge Main loop)
                MOV CTR, #40H   ; YES, THEN FURTHER INCREASE TIME TO CALL INPUTS & DISPLAY
EXIT:           MOV TL2, #32H   ;
                MOV TH2, #32H   ;
                SETB TR2        ; START TIMER2
                POP PSW         ;
                RETI            ; RETURN FROM INTERRUPT


 

Though T2_ISR and the whole program is running well,I would like to know, whether using P1.0 & P1.1 for toggling LEDs during display subroutine along with T2 in auto reload mode was the problem! As it seems, when T2 used as plain timer, is working well!

Thanks!
Sandy

List of 19 messages in thread
TopicAuthorDate
Problem using Timer2 in 89S52!            01/01/70 00:00      
   not a very useful suggestion from 'Plz'            01/01/70 00:00      
      further suggestion            01/01/70 00:00      
         Message & Readable code is here...            01/01/70 00:00      
            look in the assembler manual            01/01/70 00:00      
               New Code, hope it helps!            01/01/70 00:00      
                  what You are trying to make ?            01/01/70 00:00      
                     mov T2MOD,#4            01/01/70 00:00      
                        sorry            01/01/70 00:00      
                            t2mod=0 ; t2con=4 (tr2=1) It worked!            01/01/70 00:00      
                        PSW            01/01/70 00:00      
                  that is not a comment!            01/01/70 00:00      
                     Comments OR Explaination!!!            01/01/70 00:00      
                        Comments are mainly for YOU            01/01/70 00:00      
                        WRONG!            01/01/70 00:00      
                           Answer the "why" in your comments.            01/01/70 00:00      
                              I got (I)T2 working !!!            01/01/70 00:00      
                  Clear TF2 in your service routine            01/01/70 00:00      
                     Clearing TF2 in ISR            01/01/70 00:00      

Back to Subject List