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

Different ways to set registers in C and delays

Good Morning everyone.

A long time ago I seam to remember in AVR-GCC I could set registers using something like:

Register = b00001111;

Wonder if there is a variant like this in C51.

Also, are are there any standard delay function.

Begard Regards

Andy

  • A variant? Yes, put into a global header file:

    /* Helper macros HEX__ and B8__ not to be used directly */
    #define HEX__(n) 0x##n##UL
    #define B8__(x) (\ 
        (((x)&0xF0000000UL)?0x80:0) | \ 
        (((x)&0x0F000000UL)?0x40:0) | \ 
        (((x)&0x00F00000UL)?0x20:0) | \ 
        (((x)&0x000F0000UL)?0x10:0) | \ 
        (((x)&0x0000F000UL)?0x08:0) | \ 
        (((x)&0x00000F00UL)?0x04:0) | \ 
        (((x)&0x000000F0UL)?0x02:0) | \ 
        (((x)&0x0000000FUL)?0x01:0))
    
    /* For up to 8-bit binary constants */
    #define BIN(b) ((unsigned char)B8__(HEX__(b)))
    


    and use it like this:


    unsigned char temp = BIN(01010110);

    .