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

Automatic RESET during operation

i am facing a wierd problem.. My MCU P89V51RD2BN resets during Execution...
i am a college student and a beginner Here so i dont know the Advanced Programming methods
i would also inform that..

i have a recursive function , a warning is issued by the compiler for the same. but....

earlier this was not a problem but since i have modified some of the Sub-Routines for 16Bit Data this Problem has come up, i need those functions to be 16 bit because of the limitation of the ALU i was earlier using 8bit and leaving most of the Task to Assumption which i cannot do so now..

i would also state that the Problem occurs in a fumction at a point when i call 2 functions in the same code, these themselves call around 5 sub-routines each but that wasnt a problem earlier (before i used the 16bit return type sub-routines).

now i found something in the manual stating reentrant Functions, but i really dont know how to use it

i used it like this

void Home_Screen_Instance() reentrant
{ ------------
} Do i need to use the keyword "reentrant" in the Function Decleration too?
but that didnt help either
but the compilers shows an error Home_Screen_Instance : redefinition.
Target Not Created

this was the first of a kind problem that i encountered, my MCU is resetting itself for sure(i checked that with a dummy subroutine of blinking LED) and it is not because of the watchdog timer, i am sure about that too..

so whats the Problem here?

is the Stack overflowing???
or there is any other reason behind this?
should i revert back to the 8bit versions of my subroutine (without any other choice)?
is it because of the recursive nature of the function H0me_screen_instance?

Related Data:

The Program is Display intensive, i mean there are a lot of Strings to be displayed and they are stored beforehand in XDATA,
message shown during sucessfull compilation, (still resets)
Program Size: data 9.4 xdata 252 code 9514
creating hex-----blah blah blah----
0 Error(s) 65 Warning(s)

Parents
  • You take as parameter what character that represents a break?

    But you use a global parameter for telling that your function was exited by a press of a break character.

    I would have thought that the break character was a constant.

    And that the return value from function would tell if data entered or cancel.

Reply
  • You take as parameter what character that represents a break?

    But you use a global parameter for telling that your function was exited by a press of a break character.

    I would have thought that the break character was a constant.

    And that the return value from function would tell if data entered or cancel.

Children
  • The Character 'C' on my Keypad is the Break Character
    Character 'B' Behaves as Backspace Key
    Character 'A' is used when the user is done entering the values less than the maximum limit
    ex: i have set a limit of 4 characters so maximum value is 9999 but he user wishes to enter just 99 then he presses 9->9->'A'

    a global bit variable 'Break' is used to notify that a user initiated break has occured and the system comes back to a state before the user input was requested.

  • Yes, but my question is why you used it as a configurable key - why a parameter to the function.

    When designing a user interface, it is normally very consistent which key is escape and which key is enter.

    Next thing - why a stack?

    You can just compute a numeric value as you go - only keep track of number of digits.

    if (num_digit < 4) {
        num *= 10;
        num + digit;
        num_digits++;
    }
    

    or for delete:

    if (num_digits) {
        num /= 10; // integer division strips last (least significant) digit.
        --num_digits;
    }
    

    Then return a value 0..9999 for valid input, and -1 if user cancels the input.

  • i was passing Parameters to the function because at some places
    The Space available at the LCD is limited its like XXXXXW 'X'is the available space for user input while the rest has been occupied by other text, so if the input is unbound in terms of number of digits it may overwrite, other strings on the LCD.

    Secondly, one of the parameters is "bit show" which is used to control if the characters being typed need to be visible at the LCD.

    i had doubts implementing it as a stack...but my main reason was the unknown Size(number of Characters) for the input, that's why i let it be a stack of 10 Characters, so that the same stack can be used if i made some other Sub-Routine which required Stack implementation.

    and one more question...
    i was searching for books on Programming both general Programming and Embedded Programming and of these the best i found was
    Embedded C by Micheal J Pont
    The art of Programming by Knuth

    can you suggest any other reads apart from these..
    the book by muhaamad ali mazidi is one of my textbook

  • I do know what you used the parameters for.

    But the interesting question is why you think you need the parameter "BreakC".

  • yeah... i didnt realize that was actually taking extra work all the time, i really didnt require BreakC... ill define a constant for that, it would atleast reduce the number of parameters

    here i got another problem, the code in between the Stars is being bypassed completely,
    i didnt understand it first but then i started inserting dummy routines in between codes and found out that the code (in Bold) is being completely bypassed every time.

    Home_Screen() //Draws the Home Screen
    Keypad_Instance() //Has been already posted in this thread
    Check_Lock1() //Checks if the code entered is correct or not and opens the lock if true

    void Start()
    {
             Lock_State = Closed;
            do
            {
                    Home_Screen();
             while(Keypad_Input() == False);// Wait for a key to be pressed.
    //*******************************************************************************************
          while(Lock_State == Closed)
             {
                            Lock_Screen();
                            Keypad_Instance(5,2,8,0,'C'); // 5 character password at pos 2,8, Hidden and 'C' is the break Character
    
    
                             Check_Lock1();   //Check the Password, if true then Lock_State=Open
                            if(Lock_State == Open)// Lock is Open
                                      break;
                            else
                            {
                                    LCD_Cursor_XY(3,7);
                                    LCD_Text("RETRY !!!");  //on entering Wrong Password
                            }
             }
                    Main_Menu1_Instance();
    //*********************************************************************************************
     }while(1);
    }
    

    i didnt get it, why is this not working,
    Note: i tried implemnting the Code in italics in a do-While loop, but the same problem creeped up,
    this was not a problem when i had those recursive functions LOL ;P!!

  • what if i have to enter a 4 digit number, 9999 the maximum value i permit in this project as an user input can be contained by an unsigned int variable..
    suggestions:

    if (num_digit <= 4)
    {
        num *= 10;
        num + digit;
        num_digits++;
    }
    

    or

    if (num_digit <= 5 && Stack[0]<7) // im using a stack here,first element (MSB) is always at Stack[0]
     {
        num *= 10;
        num + digit;
        num_digits++;
    }
    

    will this be fine?

    also i suggest we do it at the end.. when the user has completed entering all the details, well it depends upon the number of characters being entered... yours look really good if the number of characters is large more than 5... i modified your code

    unsigned int Temp2=0;
    
    while(Size>0) //Stack begins at 0, but Size is  a natural Number
            {
                    Temp2*=10;
                    Temp2+=Stack[Stack_Top - Size]-'0'; //Stack_Top is at Size after the Execution
                    --Size;
            }
    

    now if the user is done with just one digit or two and i separately need to know that then
    Temp2%10 or Temp2%100 or like that..

  • what you are trying to overcomplicate has been done in very simple ways many, many times before.

    Erik

  • sum = 0
    for >max
    if !digit break
    sum *10
    sum += digit

  • Note of course that the pseudocode for storing the digits in a integer do require an integer of proper size.

    So an unsigned 8-bit variable have max range 255 and room for 2 digits.
    An unsigned 16-bit variable have max range 65,535 and room for 4 digits.
    An unsigned 32-bit variable have max range 4,294,967,295 and room for 9 digits.

    In this specific case, a signed 8, 16 or 32-bit integer will have room for the same number of base-10 digits, allowing the function to return -1 for cancel or a value >= 0 for a properly entered number.

    It takes many machine-code instructions to perform a 32-bit divide (for handling "backspace") but the C code will be very clean, saving coding and debugging time.