+ Reply to Thread
Results 1 to 4 of 4

Thread: AT89S51 Timer sample program required?

  1. #1
    prevravanth Newbie
    Join Date
    Dec 2006
    Location
    Chennai,India
    Posts
    14

    Question AT89S51 Timer sample program required?

    I am using AT89S51 with 11.0592MHz crystal.

    I want to make timer for 5 minutes or some customised time.

    can u help me some sample source code in C.

    can i use 2 timings in same chip if so use timer o and timer 1 for specific timings.

    Can some body help in source code.

    Thanks
    Last edited by prevravanth; 16th December 2006 at 11:28 AM.


  2. #2
    ikalogic Good ikalogic Good ikalogic Good
    Join Date
    Dec 2003
    Location
    Limoges, France
    Posts
    632

    Default

    sure here you go:

    Here is a function to setup the timer interrupts

    setup_interrupts(){
    EA = 1;
    TMOD = 0X22; //timer mode (auto reload)
    TH0 = 0; // the auto loaded vaue
    TH1 = 200; // the auto loaded vaue
    TR1 = 1;
    ET0 = 1;
    ET1 = 1;
    }

    now, there are no variables that will hold a 5 minutes delay so you need to do it yourself like in this example:

    time_5_min interrupt 1{ //called each time timer 0 counts from 0 to 255
    counter1++;
    if (counter1 > 250){
    counter1 = 0;
    counter2++;
    if (counter2 > 250){
    counter2 = 0;
    ..
    .. //put here the code you want to be executed
    ..
    }
    }
    }

    this will give you delay of 255 * 250 * 250 pulses, i don't know exactly how much time this will give you.. but you should have got the idea!
    Ibrahim Kamal
    check my electronics and robotics page: http://www.ikalogic.com/

  3. #3
    ikalogic Good ikalogic Good ikalogic Good
    Join Date
    Dec 2003
    Location
    Limoges, France
    Posts
    632

    Default

    Tell me if you want a compleat source code of a program i wrote that uses timer 0 and timer1 interrupts..

    Also a note about using the 2 interrupts at the same time, if the 2 timers have very small time delays, your program will freeze, because each time the processor starts to execute a timer routine, the other timer calls it, and when before it finishes executing the 2nd timer, the first timer calls again.. even if you use priorities, your main program whill never get executed... so be careful
    Ibrahim Kamal
    check my electronics and robotics page: http://www.ikalogic.com/

  4. #4
    TronicBrain Newbie
    Join Date
    Aug 2003
    Location
    Syria
    Posts
    47

    Default

    Hi

    I made a small program that can calculate Delay loops and generate them

    you can test it

    http://members.lycos.co.uk/electrote.../DelayLoop.rar

    I hope it dose not have any bugs
    I’m from Syrian Arab Republic where lots of guys are trying to do better in electronics.

+ Reply to Thread

Similar Threads

  1. Automatic On/OFF Timer Circuit Required
    By mahesh_jo in forum General Electronics Chat
    Replies: 8
    Latest: 20th May 2005, 11:42 PM
  2. Newcomers, please read! (PIC regarded) Upd. 0xD
    By Jay.slovak in forum Micro Controllers
    Replies: 0
    Latest: 17th April 2005, 01:05 PM
  3. countdown timer code
    By ah_Hui in forum Micro Controllers
    Replies: 0
    Latest: 26th April 2004, 05:31 PM
  4. PicBasic Keypad program
    By Sora in forum Micro Controllers
    Replies: 0
    Latest: 20th April 2004, 07:02 PM
  5. Random timer circuit required
    By Tako Kichi in forum Electronic Projects Design/Ideas/Reviews
    Replies: 0
    Latest: 11th October 2003, 03:07 AM

Tags for this Thread