1. mayank rob

    Thread Starter New Member

    Sep 18, 2012
    17
    0
    Hi there
    I am new to embedded,i have programmed my boards using assembly language but now m trying to learn it using embedded C.
    I am using keil, controller-89V51RD2
    I want to use timer without using interrupt.
    my code is:


    #include<reg51.h>
    sbit LED1=P3^0;

    //Timer 0 is used
    void main()
    {

    while(1)
    {
    unsigned int x;
    //Mode 1 is used
    TMOD=0x01;
    TH0=0xFF;
    TL0=0xFF;
    LED1=1;
    TF0=0; //clearing the overflow flag
    TR0=1; //START TIMER

    while(TF0==0)
    {
    //waiting till the timer flag overflows
    }
    x=x+1;
    if(x%99==0)
    {
    LED1=!LED1;
    }
    TF0=0;
    TR0=0;

    }
    }


    the code shows 2 warning when i execute it.
    I am wondering that if something is wrong with my code or logic...not able to figure it out.
    thanks
     
  2. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    1. You did not say what the "2 warnings" are.

    2. You did not say what the problem is, and what result you get.
     
    mayank rob likes this.
  3. embpic

    Member

    May 29, 2013
    187
    3
    as you have given TH0 and TL0 as 0xFF so at every time it get overflow when it get initialize. so no need to use of timer then.
    and if you are going to use it without interrupt then no use of timer then use delay instead.
     
    mayank rob likes this.
  4. mayank rob

    Thread Starter New Member

    Sep 18, 2012
    17
    0
    embpic: thank you for realizing me for such a such a silly mistake,it was blunder i realized.
    And i didnt use interrupt because am a beginner,so just a thought came into mind of using it without interrupt but then its not working and now am wondering whats wrong.
    and i tested it again changing the values to 0x00,but no effect.
    The warning it showed is:
    *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL: ?C_START
    MODULE: STARTUP.obj (?C_STARTUP)
    *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL: ?C_START
    MODULE: STARTUP.obj (?C_STARTUP)
    ADDRESS: 080AH

    And if i compile it and burn it anyway then i see no response in LED.
    LED is in active low configuration
    the timers and circuit is working well since i have tested the default codes by the board provider n they run smoothly. Its something wrong with my logic.
     
  5. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    This error is issued by the linker and means that there is no object file containing a routine labeled ?C_START.

    ?C_STARTUP (in STARTUP.A51) LJMPs to ?C_START which has been declared EXTERN (in another file - to be resolved by the linker).

    In my older version of Keil C51, ?C_START is in INIT.A51 which must be assembled and linked. ?C_START is declared PUBLIC.

    Attempting to run with this error means you have a big hole in your code. Any indication of the code working is pure happenstance.

    EDIT:
    It looks like ?C_START usage is controlled by PPAGEENABLE which in turn is controlled by the memory model used. Using the COMPACT model should remove the LJMP to ?C_START (which looks like it initializes variables in paged memory). Read the memory model documentation for your chip.

    From STARTUP.A51:
    Code ( (Unknown Language)):
    1. ;------------------------------------------------------------------------------
    2. ;
    3. ;  Page Definition for Using the Compact Model with 64 KByte xdata RAM
    4. ;
    5. ;  The following EQU statements define the xdata page used for pdata
    6. ;  variables. The EQU PPAGE must conform with the PPAGE control used
    7. ;  in the linker invocation.
    8. ;
    9. PPAGEENABLE    EQU    0    ; set to 1 if pdata object are used.
    10. PPAGE        EQU    0    ; define PPAGE number.
    11. ;
    12. ;------------------------------------------------------------------------------
    and later - ?C_START is used only when PPAGEENABLE is <>0 i.e. a non-compact memory model.
    Code ( (Unknown Language)):
    1. IF PPAGEENABLE <> 0
    2.         MOV    P2,#PPAGE
    3. ENDIF
    4.  
    5.         MOV    SP,#?STACK-1
    6.         LJMP    ?C_START
    7.  
    Finally, there are various versions of STARTUP.A51 tailored to different 8051 variants. Presumably, the IDE project configuration selects the proper one to fit the chip/memory model. You'll have to figure out why the disagreement.
    Whew. Have fun!
     
    Last edited: Dec 21, 2013
    mayank rob likes this.
  6. mayank rob

    Thread Starter New Member

    Sep 18, 2012
    17
    0
    Thank you
    I found the solution.
    I just removed the startup.a51 file and the program is running smoothly and behaving as expected.
     
  7. JohnInTX

    Moderator

    Jun 26, 2012
    2,347
    1,029
    I'm not sure that is a good idea. startup.a51 initializes the C environment including setting variables to 0, loading initialized variables and initializing the 8051 stack pointer.

    The startup code runs from reset then jumps to main() to start the user program. Without it or something that does the same thing, you may be in for trouble.

    As I said, your problem could be one of confusion between modules about the memory model used. You should resolve that problem instead of removing the startup code.

    Look at the link map and see where main() is. If its at the reset vector i.e. no startup code, you have problems.

    OTOH, you might find another, correct version of startup.A51 is now in use. In that case you are good to go.
     
    mayank rob likes this.
Loading...