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 C's programming concept for ucontroller

Sir,
I am frequent user of assembly language regarding MCS 51 family but now I want to shift on C programming I have understanding of C language. I am facing lot of difficulties in C for ucontroller programming.For assembly the instruction set is available is there any C's instruction set for controller to understand app notes of examples available in C. How can I use internal ram (bit addressable), rotate commands,interrupt vectors,serial interrupts, data pointer,bit checking.
How can I interpret these commands use in Keil examples? Is any help or guidance for me....?

LCD_DATA = (LCD_DATA&0x0F)|((value<<4)&0xF0);
SDA = (bit)((value&0x80) >> 7);
TMOD &= ~0xF0;
TMOD |= 0x20;

Parents
  • I'd suggest reading the C51 compiler manual. It describes in detail how to use all sorts of extended features in the Keil toolset to use specific 8051 features.

    >How can I use internal ram

    See the memory qualifer keywords, in particular data and idata

    >(bit addressable)

    bdata, bit

    > rotate commands

    There is no rotate operator in C. Check the Keil C library reference under "intrinsic functions" and you'll see they've provided a number of efficient, low-level rotate functions such as _crol_ and _cror_.

    > interrupt vectors, serial interrupts,

    Keil lets you declare functions as interrupt routines, e.g.

    void MyInterrupt (void) interrupt 3

    >data pointer,

    The different memory areas on the 8051 means that you have to deal with different pointer types in Keil, including the "generic" pointer which can point to any area, and uses an extra tag byte to keep track.

    >bit checking

    You can test data of type bit just as with any C variable: if (myBit), if (myBit == 1).


    LCD_DATA = (LCD_DATA&0x0F)|((value<<4)&0xF0);
    SDA = (bit)((value&0x80) >> 7);
    TMOD &= ~0xF0;
    TMOD |= 0x20;


    These examples are all standard C; no Keil extensions involved. If you understand C you should have no trouble.

    They're using the bitwise AND and OR operators to construct a value or set individual bits in a byte. The variable TMOD is almost certainly defined to be the timer mode register in a header file somewhere.

    TMOD &= ~0xF0;

    means "clear the top four bits of TMOD". And-eq-not is a common idiom for clearing bits. It's the same as TMOD = TMOD & 0x0F.

    TMOD |= 0x20

    means "set bit 5 of TMOD". The long form is TMOD = TMOD | 0x20.

Reply
  • I'd suggest reading the C51 compiler manual. It describes in detail how to use all sorts of extended features in the Keil toolset to use specific 8051 features.

    >How can I use internal ram

    See the memory qualifer keywords, in particular data and idata

    >(bit addressable)

    bdata, bit

    > rotate commands

    There is no rotate operator in C. Check the Keil C library reference under "intrinsic functions" and you'll see they've provided a number of efficient, low-level rotate functions such as _crol_ and _cror_.

    > interrupt vectors, serial interrupts,

    Keil lets you declare functions as interrupt routines, e.g.

    void MyInterrupt (void) interrupt 3

    >data pointer,

    The different memory areas on the 8051 means that you have to deal with different pointer types in Keil, including the "generic" pointer which can point to any area, and uses an extra tag byte to keep track.

    >bit checking

    You can test data of type bit just as with any C variable: if (myBit), if (myBit == 1).


    LCD_DATA = (LCD_DATA&0x0F)|((value<<4)&0xF0);
    SDA = (bit)((value&0x80) >> 7);
    TMOD &= ~0xF0;
    TMOD |= 0x20;


    These examples are all standard C; no Keil extensions involved. If you understand C you should have no trouble.

    They're using the bitwise AND and OR operators to construct a value or set individual bits in a byte. The variable TMOD is almost certainly defined to be the timer mode register in a header file somewhere.

    TMOD &= ~0xF0;

    means "clear the top four bits of TMOD". And-eq-not is a common idiom for clearing bits. It's the same as TMOD = TMOD & 0x0F.

    TMOD |= 0x20

    means "set bit 5 of TMOD". The long form is TMOD = TMOD | 0x20.

Children