timers in 8951

Thread Starter

harshasunder

Joined Dec 1, 2010
1
Hi,
Im having trouble using both timer0 and timer 1 in the at89s51.Ive looked all over and not found anybody saying you cant use both simultaneously. But im finding that when i switch one off then the other one works just fine. Both timers are pretty resource hungry.I want timer1 to generate a frequency btween 200 and 600 hz and timer0 is presently being used to refresh a seven segment display .The while loop is pretty large also and im polling many buttons and various conditions.
Can someone send me some sample code? Do i have to use mode 3 only by any chance?
Thanks
Harsha
 

Papabravo

Joined Feb 24, 2006
21,225
You can use both timers simultaneously, but you must be careful how you set them up because both timers are controlled by the same register. There are two ways to do this:

  1. Figure out how you want each timer to work and write the appropriate values to TCON and TMOD
  2. Setup Timer 0 with the appropriate values, then use a READ-MODIFY-WRITE construct to setup Timer 1
 

AMIT_GOHEL

Joined Jul 13, 2010
67
i was facing same problem,but at last found solution.
from 2 timers a low priority timer can be replaced by

Rich (BB code):
            MOV D3,#07H
LOOP2:DEC D3
            MOV D2,#0FFH
LOOP1:DEC D2
            MOV D1,#0FFH
CHEAK:MOV A,D1
            JZ LOOP1
            MOV A,D2
            JZ LOOP2
            MOV A,D3
            JZ TIMES_UP
            DEC D1
            MOV A,P2                
            XRL A,#0FFH            
             JZ CHEAK
it's kind of timer i made ,which cheak the port 2 for input for 5 second at crystal 11.0592MHz.

but keep in mind that it'll decrease your input fetches..

have happy coding...:)
 
Top