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

Back to Subject List

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


 
#171496 - Message & Readable code is here...
Responding to: ???'s previous message
When using Timer-2 to generate interrupt using the following code, one LEDs which is driven using P1.1 gets complimented everytime TF2 flag is raised, which is undesirable.
Also during Display subroutine, when ever P1.1 is Set, the T2-ISR dosen't start.
How can I get out of this problem? (I can't use any other Port pin because I've already ran out of those.) Also T0 & T1 are already used in other part of the code and any of those can't be used to generate the interrupt.
This is what I found in Datasheet of 89S52...

-----------------
10.1 Capture Mode
In the capture mode, two options are selected by bit EXEN2 in T2CON. If EXEN2 = 0, Timer 2 is a 16-bit timer or counter which upon overflow sets bit TF2 in T2CON. This bit can then be used to generate an interrupt. If EXEN2 = 1, Timer 2 performs the same operation, but a 1-to-0 transition
at external input T2EX also causes the current value in TH2 and TL2 to be
captured into RCAP2H and RCAP2L, respectively. In addition, the transition at T2EX causes bit EXF2 in T2CON to be set. The EXF2 bit, like TF2, can generate an interrupt.
-----------------

The part of the code is embedded here. P1.1 is used for LED, which happens to be T2EX for Timer-2.
During Display subroutine, P1.1 is Set or Cleared as per inputs at P3.(During Inputs subroutine, P3 is stored in ACC after verifying for consistant values 4 times. These bits in ACC are used in Display subroutine to Set or Clr various LEDs. Actually, Display subroutine is quite large, hence only one part of it has been written here for reference.)

**********************CODE****************
;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	; CTR = COUNTER FOR T2 INTERRUPT
;*****************************************************************************
;*****************************************************************************	


		ORG 002BH	; INTERRUPT SERVICE ROUTINE FOR T2

ISR_T2:		DJNZ CTR, EXIT	; DECREMENT COUNTER, EXIT IF NOT ZERO
		ACALL INPUTS	; ELSE CALL INPUTS SUBROUTINE
		MOV CTR, #0AH	; RESET COUNTER TO 0Ah
EXIT:		CLR 0CEH          ; (CLR EXF2 => T2CON.6)
		RETI		; RETURN FROM INTERRUPT


		ORG 0050H	; THIS IS MAIN LOOP

MAIN:		ACALL DISPLAY   ; 
		........        ;
		........        ;
		........        ;
		........        ;
		
		SJMP MAIN	; 


		ORG 0100H	; BOOT / INITIALIZATION SUBROUTINE

BOOT:		MOV TMOD, #11H	; LOAD TMOD WITH 11H (1011 binary) 
		MOV T2MOD, #02H	; LOAD T2MOD WITH 0000 0010 BINARY
		MOV T2CON, #00H	;
		MOV RCAP2L, #00H  ;
		MOV RCAP2H, #00H  ;
		MOV SP, #60H	; LOAD SP WITH 60H
		MOV P3, #0FFH	; 
		MOV P0, #0FFH	; 
		MOV P2, #0FFH	; 
		MOV P1, #0FFH	; 
		CLR P1.1          ; TURN OFF LED1(This happens to be T2EX  
                                   ; Pin of Timer2)
		CLR P1.3        ; TURN OFF LED2
		CLR P0.2        ; TURN OFF LED3
		MOV CTR, #0AH   ; COUNTER = 0Ah
		MOV IE, #0A0H   ; (ENABLE T2, SET EA=1, REST ALL =0)
		SETB 0CAH       ; (SET TR2= START TIMER2)
		SJMP MAIN       ; LONG JMP TO 0030H


		ORG 0200H	; SUBRTN FOR TAKING INPUT FORM P3

INPUTS:		MOV R2, #04H	;
		......
		......
		......
		RET		;


		ORG 0300H	; DISPLAY SUBRTN

DISPLAY:         JB ACC.7, JMP1	; JMP IF ACC.7=1
		SETB P1.1       ; 
		CLR P1.3        ; 
		CLR P0.2        ; 
		SJMP JMP3       ; 
JMP1:		JB ACC.6, JMP2  ; JMP IF ACC.6=1
		CLR P1.1        ; 
		SETB P1.3       ; 
		CLR P0.2        ; 
		SJMP JMP3       ; 
JMP2:		CLR P1.1        ; 
		SETB P0.2       ; 
		CLR P1.3        ; 
JMP3:		RET	        ;


;*****************************************************************
;*****************************************************************



Please suggest whether the code is wrong somewhere! Or, Any change in code to get out of this. I am unable to get out of this myself.

How can I get rid of ORGs in assembly language? Anyway, I prefer to take a look at opcode in my programer window before programming the microcontroller. I cross check that the begining & end of the various subroutines do not overlap.

Erik, I've already defined RCAP2L EQU 0CAH in the begining. The instruction SETB 0CAH is SETB TR2. I thought I could not redifine TR2 EQU 0CAH, hence could not write meaningful name. Sorry for that.


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