This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem in Interuppt Program

Hi,

I have written a interuppt program for 1 second time delay. I am inserting the code with this mail, I am using timer0 with 250ms which is inturn given to PCA with 4 times count. The code is working fine as single module , but when I attach this code with my on going project code the code is not working, I have not used any special registers of the chip AT89C51ED2, and in all EEPROM programs I have used EA=0 and EA=1 at begining and end of program. If there is any suggestion , plz help me to get out of this problem.

void timer_routine(void) interrupt 7  using 2
{
    EA=0;
    CL=0x5F;
    CH=0xF0;
    CCF1=0;
    CF=0;
    P2_6=~P2_6;
    EA=1;
}

void main()
{


                IEN0=0xC0;  //C2
                TMOD |=0x02;
                TL0=0x00;
                TH0=0x18;
                TF0=0;
                CMOD=0x05;
                CCAP1L=0x0A;
                CCAP1H= 0x4F;
                CCAPM1=0x49;
                CL=0x5F;
                CH=0xF0;
                CCAP1L=0xFF;
                CCAP1H= 0xFF;
                TR0=1;
                CR=1;
                P2_6=0;



                while(1);

}

  • If CY is carry, May i ask what are CL, CH, CCF1, CF, CCAP1L, CCAP1H, CCAPM1, CMOD and CR?

    what do they stand for?

  • Your code would be much easier to read if you gave meaningful symbolic names to your constants (rather than just use magic numbers), and documented (in comments) what your code is supposed to be doing.

    Do this now - the exercise on its own might well lead you to your problem!

  • one more case of "secrecy"

    I am using timer0 with 250ms
    sounds as iof you are using a very low oscillator ferquency, but you want to keep it secret what it is

    I have not used any special registers of the chip AT89C51ED2
    and the you go ahead and use the PCA which makes another poster (that need to read The PCA cookbook
    www.intel.com/.../270609.htm ) ask "what are these?"

    full info, commented code then maybe someone can help you.

    Keeping things secret (missing info scribbles (without comments nothing can be called 'code") are not conductive to getting an answer.

    Erik

  • "I have not used any special registers"

    Not forgetting, of course, that the 'S' in "SFR" stands for "Special"...!

    ;-)

  • Rajeesh:

    I can't help but notice that you don't put any comments in your code (or you feel like you need to take them out before posting).

    I think that many folks put in comments to tell others what the code does. However, I believe it is equally important to tell reviewers what you WANTED the code to do.

    It would be considerably easier if you put in comments to that effect. Otherwise, how could anyone tell what your desire was/is?

    Best Regards,

    -=Rich=-

  • Hello Hems Raj,

    First Learn the Registers what are present other than Lowend 8051.

    There are advanced 8051.

    Please go through the registers of ED2.

    Please dont confuse yourself and confuse others.

  • void timer_routine(void) interrupt 7  using 2
    {
        EA=0;        //disable all interrupt
        CL=0x5F;     //loading 0xfo5f to pca counter
        CH=0xF0;
        CCF1=0;      //clearing capture compare flag
        CF=0;        //clearing pca counter overflow flag
        P2_6=~P2_6;     //complementing the portpin
        EA=1;           //enable all interrupt
    }
    
    void main()
    {
    
    
                    IEN0=0xC0;  //enable all interupt and pca interupt
                    TMOD |=0x02; //set timer0 as timer
                    TL0=0x00;   //reload timer value as 0x1800
                    TH0=0x18;
                    TF0=0;
                    CMOD=0x05;  //select timer 0 as pca clock and enable pca capture interupt
                    CCAP1L=0x0A; //filling non zero values
                    CCAP1H= 0x4F;
                    CCAPM1=0x49;  //setting ecom1 and mat1 and eccf1bits to use as software timer and enabling capture interupt
                    CL=0x5F;   // filling the pca timer
                    CH=0xF0;
                    CCAP1L=0xFF; //filling the capture ,compare modules
                    CCAP1H= 0xFF;
                    TR0=1;    //run timer0
                    CR=1;    //run pca timer
                    P2_6=0;
    
    
    
                    while(1);
    
    }
    
    
    

  • Could you tell me this:

    the advanced 8051 instruction set that you say works on uvision2?

    rgds,

  • got any link ?

    either give this up and go buy a broom or start figuring the SIMPLEST things out by yourself.

    question 1: who makes tha chip
    question 2: does that company have a website
    question 3: does that webpage have a search window
    question 4: do you know how to type into such a window
    question 5: do you think that would be the way to do it

    Erik

  • you were told:
    There are advanced 8051.
    Please go through the registers of ED2.
    that, cutting it in cardborad, should have been the SFRs of ED2

    you ask
    the advanced 8051 instruction set that you say works on uvision2?
    1) who said ANYTHING about "instruction set"
    2) there is no "advanced instruction set"
    3) if you took the time to do what Rajesh suggested BEFORE posting another ELEMENTARY question you would not need to ask.

    Erik

    Read "the bible" 5 times or more, then read the ED datasheet 5 times or more, then when you have a question that can not be figured out by a 5 year old come back.

  • Hey, cool it,
    /* kidding, */

    sory

  • The comments are an improvement, but it's still a mass of magic numbers; eg,

    CCAPM1=0x49;  //setting ecom1 and mat1 and eccf1 bits
                  //to use as software timer and enabling capture interupt
    


    Are you sure that 0x49 is the right magic number for that particular set of bits? Wouldn't it be much clearer (and, hence, more maintainable) to define symbolic constants and write, say:

    CCAPM1 = ECOM1 + MAT1 + ECCF1; //to use as software timer and enabling capture interupt
    

  • "in all EEPROM programs I have used EA=0 and EA=1 at begining and end of program."

    What do you mean by that?
    Are you confusing "program" with "function"?

    "If there is any suggestion"

    If your timer code works alone, and then stops when integrated with something that's fiddling with the EA flag, I think there could be a clue there somewhere...

  • Somebody like who 's got an eye for detail could fix up the error..