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

Counter and printf

Hi all

I need a counter to to count up something

So I use follow code to do this work

unsigned long pdata counter[4]={0,0,0,0};

in the counting place,

counter[0]++;


when run finsih , I print the result

printf(%ld\n",counter[0]};


Maybe I have run to 1000 times ,so counter[0] value

will be to 1000 , but the printf result maybe very

large, like as 92343421;

why ?? how can I make sure to count up correctly??

Thanks a lot

best regards

Parents
  • Thanks for you relpy

    it is almost realy code I use , I just add that code in every where that I need to counting up

    Other code is need HW to work ,so I didn't use any
    Simulator or debugger ,just printf infomation only

    How do I to mark sure your PDATA is working & correctly configured? any infomation I can check??

    I thank ulong is 32bit , but 8051 is 8 bit , maybe
    just like you say , pdata is not working correctly

    the counter value maybe very large ,so will be round
    0xfffffff--->0x000000000

    Sometimes the printf value is correct , sometimes
    is samll number ,but print big number

    FYI

Reply
  • Thanks for you relpy

    it is almost realy code I use , I just add that code in every where that I need to counting up

    Other code is need HW to work ,so I didn't use any
    Simulator or debugger ,just printf infomation only

    How do I to mark sure your PDATA is working & correctly configured? any infomation I can check??

    I thank ulong is 32bit , but 8051 is 8 bit , maybe
    just like you say , pdata is not working correctly

    the counter value maybe very large ,so will be round
    0xfffffff--->0x000000000

    Sometimes the printf value is correct , sometimes
    is samll number ,but print big number

    FYI

Children
  • "it is almost realy code I use"

    Almost - but not exactly.

    "Almost" is not good enough - how do you know that it's not precisely that (possibly subtle) difference that causes the problem?!

    "How do I to make sure your PDATA is working & correctly configured? "

    My PDATA is irrelevant - you are the one that's observing the problem, so it's your PDATA that is concerned; ie, the PDATA in the target hardware that you are using.

    Do you actually understand how PDATA works?

    On some chips, XDATA and/or PDATA have to be sepcifically enabled and/or configured. Some chips possibly don't suppotr it at all...

    "any infomation I can check??"

    check in the chip's Datasheet.

    "I think ulong is 32bit"

    Don't just "think" - look it up in the compiler Manual and know for sure!
    http://www.keil.com/support/man/docs/c51/c51_ap_datastorage.htm

    "maybe just like you say, pdata is not working correctly"

    Try moving the variable to DATA or IDATA - if the problem then goes away, that strongly suggests a problem with (or, at least, related to) PDATA...

  • Thanks a lot

    I have more question ^^"""

    My chip is similar to the DS80C320 in terms of hardware features and instruction cycle timing

    1 Can I use "pdata" specifier in the large memory model??

    The Keil Doc say "The pdata memory type specifier refers to only one (1) page or 256 bytes of external data memory"

    I have 8k external ram and I see the MAP file

    XDATA 0000H 0044H INPAGE ?PD?MYTEST
    XDATA 0044H 0240H UNIT ?XD?MYTEST
    XDATA 0284H 0073H UNIT _XDATA_GROUP_
    it seems look like ok

    2 when I use KEIL IDE to run ,I can't see the variable value is the watch windows, why??

  • "My chip is similar to the DS80C320"

    What what is the chip, exactly?
    Manufacturer name, nad Full part number with all suffix and prefix letters/digits?

    "Similar" doesn't help - even if there is only one small difference, that could be the one that stops your code from working, couldn't it?!

    How about providing a link to the Datasheet.

    "1 Can I use 'pdata' specifier in the large memory model??"

    Of course you can - the Memory Model simply specifies the default to be used in the absence of a specific memory space specifier.

    However, my earlier question still remains: Do you actually understand how PDATA works?

    And, are you certain that the PDATA implementation on your hardware is correct & working?

  • sorry ,my chip is ASIC IP only, So it is datasheet
    just say it like as DALLAS DS80C320

    http://www.keil.com/dd/chipinfo.asp?did=2975&bhcp=1

    I didn't know pdata too much , I just studing ^^"""

    There is no startup.a51 in my code , do I need to modify this file to use PDATA??

    Thanks a lot

  • "my chip is ASIC IP only"

    In that case, it is very likely that it handles PDATA in a special way - or may not support it at all.
    If the datasheet doesn't mention it, you need to ask the IP provider specifically about this.

    "I didn't know pdata too much"

    Don't try to use it until you really understand it, and how (if at all) it is implemented on your target.

    Get your code working first using DATA, IDATA, or XDATA.

    "There is no startup.a51 in my code , do I need to modify this file to use PDATA??"

    Yes!