导航: 老古网老古论坛XMOS公共讨论区XMOS开源项目区单片机程序设计嵌入式系统广告区域
→硬件:16位单片机[bitluo]

 *第5688篇: 硬件:16位单片机

  
楼 主:bitluo 2002年10月24日15:05
 硬件:16位单片机
请教各位高手,当用C编写16位单片机程序时,如何更方便地定义、操作字节/位变量,同时
提高RAM/SRAM的利用率。条件是该编译器支持的数据类型都是16位的(如:char 表示 -
32768 to 32768)。
  
2楼:wucang_deng 2002年10月24日16:07
 如此便可!!
struct bit_def {
        char    b0:1;
        char    b1:1;
        char    b2:1;
        char    b3:1;
        char    b4:1;
        char    b5:1;
        char    b6:1;
        char    b7:1;
        char    b8:1
        char    b9:1
  ......
};
struct byte_def{
      char    byteh:8
      char    bytel:8

union byte_def{
    struct bit_def bit;
    char    byte;
    struct byte_def byte;
}; 
example:
union byte_def tabsr_addr;
#define     tabsr       tabsr_addr.byte

#define     ta0s        tabsr_addr.bit.b0   
#define     ta1s        tabsr_addr.bit.b1   
#define     ta2s        tabsr_addr.bit.b2   
#define     ta3s        tabsr_addr.bit.b3   
#define     ta4s        tabsr_addr.bit.b4   
#define     tb0s        tabsr_addr.bit.b5   
#define     tb1s        tabsr_addr.bit.b6   
#define     tb2s        tabsr_addr.bit.b7
......
#define     tbbytel      tabsr_adr.byte.bytel
#define     tbbyteh      tabsr_adr.byte.byteh   

以后引用就直接用了。
比如
   tabbyteh=0x45;
   tab1=1;
............
   

  
3楼:dws457 2002年10月24日17:35
 好像不错耶。

>>>>>>对该主题发表你的看法

本主题贴数3,分页: [第1页]


[上一篇主题]:C51编程:大家帮我看看通讯!!!

[下一篇主题]:硬件:那有RTL8019的10M网卡,我想买几块试验