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.

Timer2 of 89S52 - the code dosen't seem to work

Status
Not open for further replies.

lats

Full Member level 4
Joined
Oct 27, 2005
Messages
216
Helped
13
Reputation
26
Reaction score
6
Trophy points
1,298
Activity points
2,945
89s52 timer2 problem

hi,
I'm trying to toggle a led's state on timer2 overflow interrupt. But the code dosen't seem to work. Frequency at which led blinks (blinking may not be even visible) is not important. Below is the code:-

Code:
void timer2_ISR (void) interrupt 5 using 1	   
{
		OverFlowTimer2++;
	     

		if(OverFlowTimer2>=10)//1 seconds
	  	 	{
		  	 	OverFlowTimer2=0;
		  	 	TF2=0;
		  	 	led=!led;
			}

	  
}/////end of timer0_ISR











T2CON=0x00;
		T2MOD=0x01;
		TL2     = 0x00;   // Timer 2 low byte 
   		TH2     = 0xFF;   // Timer 2 high byte 
   		RCAP2L  = 0x00;   // Timer 2 reload capture register, low byte 
   		RCAP2H  = 0xFF;   // Timer 2 reload capture register, high byte 
		TR2 = 1;


& one thing more how will be the frequency calculated will it be Freq = Xtal Freq / (C*12 * 2)

waiting for your help.... thnx
 

Re: Timer2 of 89S52

you have to clear the timer overflow flag every time you are going in the interrupt
 

    lats

    Points: 2
    Helpful Answer Positive Rating
Re: Timer2 of 89S52

Thanks for replying. Yes I think i had placed TF2=0 in wrong place i tried changing it to
Code:
void timer2_ISR (void) interrupt 5 using 1	   //For LIM Mode
{
		OverFlowTimer2++;
	    TF2=0;
			if(OverFlowTimer2>=10)//1 seconds
	  	 	{
		  	 	OverFlowTimer2=0;
		  	 	led=!led;
			}

	  
}/////end of timer0_ISR

but still it's not working.
 

Re: Timer2 of 89S52

the interrupt part of the code seems correct
but did you enable the interrupts
because it is not shown in the code
 

    lats

    Points: 2
    Helpful Answer Positive Rating
Timer2 of 89S52

Thanks a lot. It has started working. I missed setting ET2 bit. One thing more if you could help, do I have to sure use P1.1(T2EX), for autorelaod mode of Timer2, (I just wanted to save my I/o). Thanks a lot again. ;-) I clicked "helped me" both times :)

hey, One thing more, in the statement

Code:
void timer2_ISR (void) interrupt 5 using 1

whats the use of "using 1"
 

Re: Timer2 of 89S52

using 1 is a referance to bank 1, if you do not have any push pop issues, you can remove it.


hock
 

    lats

    Points: 2
    Helpful Answer Positive Rating
Re: Timer2 of 89S52

you can skip setting the P1.1(T2EX) for timer two
you can use it as an gpio

and as told by hock, using 1 is selecting specifically the register bank 1 in 8051
its a compiler directive
you can skip it no problem for a simple program
 

    lats

    Points: 2
    Helpful Answer Positive Rating
Timer2 of 89S52

Thanks a lot once again. sau_sol do you check your private messages (here in your account)
 

Timer2 of 89S52

nice to c some revent information on following web pages.
**broken link removed**
and see also
**broken link removed**
 

Re: Timer2 of 89S52

lats said:
sau_sol do you check your private messages (here in your account)

yes I checked it but there is nothing new
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top