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

doubts

hello everyone,
I am writing a code in which, a variable is used in interrupt routine as well as in while(1) loop
I am changing that variable value in interrupt and in while(1) loop
I am confused, while handling it
how can I avoid clashes occurred in interrupt as well as in while(1) loop

another doubt is, if in c language, I want to change the value in a certain location say 0x1234H then how is it possible?

thank you all
take care

  • Try this thread...

    "How to get data out of an interrupt?"
    http://www.keil.com/forum/docs/thread12025.asp

    --Cpt. Vince Foster
    c/o VRWC (founding member)
    2nd Cannon Place
    Fort Marcy Park, VA

  • What kind of variable bit, byte, long?

    To change a variable at an address use a pointer. If it is a fixed address Keil offers absolute addressing

  • i do not think you can do that in c bcoz you need semifores and they are in java only. try looking for java in yahoo.

  • Semaphores only in Java?

    Semaphores are a concept - they are available, one way or another, in a large number of languages.

    A semaphore, or critical section, or mutex, ... is not always needed. Most processors have some form of operations that can be performed atomically, without the need for synchronization.

    INC @R0 will for example perform an atomic increment of a memory cell, i.e. if both the main loop and an interrupt tries to increment the cell, it will increment twice, without any need for any extra synchronization.

    An interrupt that produces data to be used by a thread (producer-consumer) can be implemented as a trivial round-robin buffer, where the producer owns the write pointer, and the consumer owns the read pointer. This means that only the interrupt will modify the write pointer and only the reading task will modify the read pointer. As long as the pointer size is small enough to be updated atomically, no semaphore is needed. An 8-bit processor can always update an 8-bit index atomically. Most 8-bit processors can also atomically update 16-bit data-pointer registers, greatly increasing the possible ring-buffer size.

  • hello everyone;
    thank you all for reply
    talking about variable size it is unsigned long integer
    I also have doubt in project:
    my project includes lots of peripheral interfaces
    eg: lcd, pckeyboard, printer, rs232, temperature etc
    what if I write separate c source files for everyone which include functions of peripherals
    and include these files in the main c source file to call the functions
    does more #include will cause processing slow?
    what are disadvantages of #include if I use it more?
    thank you all
    take care

  • Four byte variables must be protected when accessed. You may have to disable interrupts when reading out the current value.

    The only disadvantage of having many include files is that the compilation time will be a bit longer. But that should normally not be a problem, since C51 projects normally are so very small.

    It isn't the code you put in the header files. Just the function prototypes. The actual code is put into *.c files.

  • thank you for reply,
    I will take care of it.
    in embedded program, we use bit datatype for accessing bit addressable memory of 20h to 2fh
    can I use Boolean in c to access the bits,
    I tried to use it but it gives me an error
    eg: bool flag = true;
    it doesnot recognize it. theni include stebool.h
    but it was of no use
    does Boolean is used in c if yes then how?
    I read about absolute addressing, but it didn’t help me in understanding the access of certain address location
    how can I access an address location say 0x2300H directly in c?
    thank you all
    take care

  • Have you spent any time with the example programs supplied with the compiler?

    If not, do so now.

    Have you spent any time with the manual for the compiler?

    If not, do so now.

    bool is a C++ data type. C != C++. C and C++ does not have a one-bit data type, other than as a bit-field in a struct.

    The Keil examples and the C51 manual will clearly inform you about the Keil-specific extention for using bit variables on the C51 architecture.

    Don't ask generic questions about absolute addressing of variables. Post a specific question, with a specific reason for requiring an absolute address.

    The include file for your processor should take care of how to address special function registers in your processor. Your own program should normally not need any variables with absolute address, unless you are implementing a boot loader or similar, or you have added external hardware (other than memory) that you need to access.

    The majority of people who ask about absolute addressing have made a bad design decision, and are doing their best to quickly complicate their lives.