在C語言程式中使用二進位控制暫存器

網路上一堆奇淫技巧,但在前處理器的都是八位元為主,16~32位元就要寫程式,這不好單晶片可沒空間和資源算這玩意。
VC的巨集辦的到但太噁心了,還好沒有單晶片是用VC的。怎樣,阿是不能用位元操作寫單晶片呦,控制週邊用高階語言太麻煩了。
不過 KEIL C沒有這個擴展可以用,但 GCC有(歡呼)

6.60 Binary constants using the `0b' prefix

Integer constants can be written as binary constants, consisting of a sequence of `0' and `1' digits, prefixed by `0b' or `0B'. This is particularly useful in environments that operate a lot on the bit-level (like microcontrollers).
The following statements are identical:
     i =       42;
     i =     0x2a;
     i =      052;
     i = 0b101010;
The type of these constants follows the same rules as for octal or hexadecimal integer constants, so suffixes like `L' or `UL' can be applied.

http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html
簡單好用!

0 個留言: