1. harshasunder

    Thread Starter New Member

    Dec 1, 2010
    1
    0
    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
     
  2. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    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
     
  3. AMIT_GOHEL

    Member

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

    Code ( (Unknown Language)):
    1.    
    2.             MOV D3,#07H
    3. LOOP2:DEC D3
    4.             MOV D2,#0FFH
    5. LOOP1:DEC D2
    6.             MOV D1,#0FFH
    7. CHEAK:MOV A,D1
    8.             JZ LOOP1
    9.             MOV A,D2
    10.             JZ LOOP2
    11.             MOV A,D3
    12.             JZ TIMES_UP
    13.             DEC D1
    14.             MOV A,P2                
    15.             XRL A,#0FFH            
    16.              JZ CHEAK
    17.  
    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...:)
     
Loading...