OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3006|回复: 6

我又来骚扰大家了,这次,我给大家分享的是,联合体的使用!

[复制链接]

22

主题

181

帖子

0

精华

高级会员

Rank: 4

积分
878
金钱
878
注册时间
2014-7-7
在线时间
311 小时
发表于 2015-7-29 09:46:55 | 显示全部楼层 |阅读模式
相比大家都对原子哥的usart模块和捕获模块那个寄存器式的操作手段好有兴趣!

是很妙的,但是,我感觉例程上的操作手段是有风险的,我来把风险降低,风险是什么,后面给大家说!
原子哥的我就不截图了,使用最高位作为处理完成位,次高位作为最后处理位,但是,我想到的风险是,
加入单片机中断多,例程没有加入原子操作(这个原子操作不是说原子哥哈!),有可能会让变量产生
溢出,也就是莫名的使能里次高位的处理位和最高位,导致处理失败的BUG。

我这里对这个寄存器进行了分解,使用了联合体的方式,其实最主要是位域的操作!大家可以看看下面的
截图,这个不需要担心溢出问题,把几个位分解开,而且也不会多占用资源(对齐之类的要大家自己探讨了!)。
而且很直观的看出想干嘛~所以,我在这里听听大家的建议和批评!同时也推荐大家多用结构!这样会使得程序
更加的直观!


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

9

主题

1385

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
11964
金钱
11964
注册时间
2013-3-8
在线时间
1274 小时
发表于 2015-7-29 12:49:23 | 显示全部楼层
#pragma anon_unions
typedef union
{
uint16_t word;
  struct 
{
uint8_t lobyte;  
uint8_t hibyte;
};
}WORD_Type;

typedef union
{
uint32_t dword;
struct 
{
uint8_t lolobyte;
uint8_t lobyte;
uint8_t hibyte;
uint8_t hihibyte;    
};         
}DWORD_Type;

typedef union
{
uint16_t all;
struct 
{
unsigned status_run_stop                 :1;
unsigned status_servo_x                  :1;             
unsigned status_servo_y                  :1; 
unsigned status_power                    :1;            
unsigned status_rec_cloth                :1;             
unsigned status_sec_cloth                :1;             
unsigned status_correct                  :1;             
unsigned status_ink                      :1;
     
  unsigned status_power_test               :1;  
    unsigned status_other                    :7;
};
struct 
{
uint8_t lobyte;  
uint8_t hibyte;
};
 
}BOARD_STATUS_Type;
//typedef struct
//{             
// uint8_t  car_ok;  
// uint8_t  guide_ok;
// uint8_t  rec_cloth_ok;
// uint8_t  sec_cloth_ok;
// uint8_t  power_ok;
// uint8_t  ink_ok;
// uint8_t  correct_ok;
// uint8_t  beam_ok;
// uint8_t  power_test_ok;
// uint8_t  ms_ok;
//}CHECK_Type;

//typedef union
//{
// uint32_t all;
// struct 
// {
//
// unsigned ld_sys_error_raster                :1;             //????????
// unsigned ld_sys_error_moto_x_limit          :1;             //MOTO X ??λ??????/????λ?? 
// unsigned ld_sys_error_moto_y_limit          :1;             //MOTO Y ??λ?????/????λ?? 
// unsigned ld_sys_error_laser_power           :1;             //???????????????????????
// unsigned ld_sys_error_comm                  :1;             //?????????????????????
// unsigned others_status                      :26;
//    unsigned ld_sys_error_unknown               :1;             //??????????
// };
//  struct 
// {
// uint8_t lolobyte;
// uint8_t lobyte;
// uint8_t hibyte;
// uint8_t hihibyte;    
// };
//}ERROR_Type;

typedef struct
{             
WORD_Type  ver_b;            
WORD_Type  ver_c;
DWORD_Type   id;             
  DWORD_Type  num;            
DWORD_Type  test_num; 
  DWORD_Type  check_num;
DWORD_Type  sn;
}SYS_Type;

//typedef struct
//{
// uint8_t  a;       
// uint8_t  b;    
// uint8_t  c; 
// uint8_t  d;
// uint8_t  e; 
// uint8_t  f;
//}LIGHT_TYPE;
//typedef struct
//{
// uint8_t x_status; 
// uint8_t y_status;
//  uint8_t x_param_status; 
// uint8_t y_param_status;
// uint8_t x_status_off; 
// uint8_t y_status_off;
//
//}MUX_TYPE;
//typedef union
//{
// uint32_t all;
// struct 
// {
//
// unsigned left_status           :1;             //??????λ       1--???λ      0--????
// unsigned right_status          :1;             //??????λ       1--???λ      0--????
// unsigned param_status          :1;             //?????????     1--???        0--???
// unsigned work_status           :1;             //????????????? 1--???        0--???
// unsigned laser_detect_status   :1;             //????λ           1--????λ      0--δ??
// unsigned last_time_status      :1;             //?????λ??       1--??λ        0--δ??
// unsigned purge_status          :1;             //???λ           1--???λ      0--δ??
//    unsigned moist_status          :1;             //???λ           1--???λ      0--δ??
//
// unsigned origin_status         :1;             //??Сλ??         1--??Сλ??    0--δ??
// unsigned print_run_status      :2;             //??????         0--??????????  1--??????      2--??
// unsigned ready_status          :1;             //????λ           1--????λ      0--δ??
// unsigned max_status            :1;             //????λ??         1--????λ??    0--δ??
// unsigned others_status         :19;
// };
//  struct 
// {
// uint8_t lolobyte;
// uint8_t lobyte;
// uint8_t hibyte;
// uint8_t hihibyte;    
// };
//}STATUS_Type;

//typedef struct
//{
//  uint8_t current_pos;                               //???浱?λ??
// uint8_t online_speed;            //??????λ
// uint8_t offline_speed;    //?????λ
// uint8_t fix_pos; //????????λ??  
// uint8_t print_mode; //?????
// WORD_Type print_th;   //???????
// WORD_Type print_dpi;   //???????
// DWORD_Type print_width; //???????
// DWORD_Type fix_pulse;   //????????λ????????
// DWORD_Type mv_pulse; //??????????????????
// DWORD_Type re_pulse; //??????????????????????
// DWORD_Type all_pulse; //?????????
// DWORD_Type set_sim;   //?????????????
// DWORD_Type loc_pulse; //??λ???
//
// STATUS_Type all_status; //????????
//
//}motorType;

//typedef struct
//{
//  DWORD_Type x_device_current;                        //?豸??λ-???λ???С????????
//  DWORD_Type x_device_min;                            //?豸??λ-??Сλ????豸???
//  DWORD_Type x_device_max;                            //?豸??λ-????λ??
//  DWORD_Type x_device_lastpos;                        //?豸??λ-???λ??
//  DWORD_Type x_device_ready;                          //?豸??λ-????λ???豸?
回复 支持 反对

使用道具 举报

22

主题

181

帖子

0

精华

高级会员

Rank: 4

积分
878
金钱
878
注册时间
2014-7-7
在线时间
311 小时
 楼主| 发表于 2015-7-29 13:27:09 | 显示全部楼层
回复【2楼】augustedward:
---------------------------------
很不错,这样一目了然,例如使用寄存器:
/* typedef ------------------------------------------------------------*/
/******************************************************************************/
/*                         eripheral registers structures                    */
/******************************************************************************/

/*------------------------ Analog to Digital Converter -----------------------*/
typedef struct
{
union
{
struct
{
volatile unsigned long AWD :1;
volatile unsigned long EOC :1;
volatile unsigned long JOC :1;
volatile unsigned long JSTRT :1;
volatile unsigned long STRT :1;
volatile unsigned long NC :27;
} B;
volatile unsigned long W;
} SR;
union
{
struct
{
volatile unsigned long AWDCH :5;
volatile unsigned long EOCIE :1;
volatile unsigned long AWDIE :1;
volatile unsigned long JEOCIE :1;
volatile unsigned long SCAN :1;
volatile unsigned long AWD_SGL :1;
volatile unsigned long JAUTO :1;
volatile unsigned long DISCEN :1;
volatile unsigned long JDISCEN :1;
volatile unsigned long DISCNUM :3;
volatile unsigned long DUALMOD :4;
volatile unsigned long NC1 :2;
volatile unsigned long JAWDEN :1;
volatile unsigned long AWDEN :1;
volatile unsigned long NC :8;
} B;
volatile unsigned long W;
} CR1;
union
{
struct
{
volatile unsigned long ADON :1;
volatile unsigned long CONT :1;
volatile unsigned long CAL :1;
volatile unsigned long RSTCAL :1;
volatile unsigned long NC3 :4;
volatile unsigned long DMA :1;
volatile unsigned long NC2 :2;
volatile unsigned long ALIGN :1;
volatile unsigned long JEXTSEL :3;
volatile unsigned long JEXTTRIG :1;
volatile unsigned long NC1 :1;
volatile unsigned long EXTSEL :3;
volatile unsigned long EXTTRIG :1;
volatile unsigned long JSWSTART :1;
volatile unsigned long SWSTART :1;
volatile unsigned long TSVREFE :1;
volatile unsigned long NC :8;
} B;
volatile unsigned long W;
} CR2;
union
{
struct
{
volatile unsigned long SMP10 :3;
volatile unsigned long SMP11 :3;
volatile unsigned long SMP12 :3;
volatile unsigned long SMP13 :3;
volatile unsigned long SMP14 :3;
volatile unsigned long SMP15 :3;
volatile unsigned long SMP16 :3;
volatile unsigned long SMP17 :3;
volatile unsigned long NC :8;
} B;
volatile unsigned long W;
} SMPR1;
union
{
struct
{

volatile unsigned long SMP0 :3;
volatile unsigned long SMP1 :3;
volatile unsigned long SMP2 :3;
volatile unsigned long SMP3 :3;
volatile unsigned long SMP4 :3;
volatile unsigned long SMP5 :3;
volatile unsigned long SMP6 :3;
volatile unsigned long SMP7 :3;
volatile unsigned long SMP8 :3;
volatile unsigned long SMP9 :3;
volatile unsigned long NC :2;
} B;
volatile unsigned long W;
} SMPR2;
union
{
struct
{
volatile unsigned long JOFFSET1 :12;
volatile unsigned long NC :20;
} B;
volatile unsigned long W;
} JOFR1;
union
{
struct
{
volatile unsigned long JOFFSET2 :12;
volatile unsigned long NC :20;
} B;
volatile unsigned long W;
} JOFR2;
union
{
struct
{
volatile unsigned long JOFFSET3 :12;
volatile unsigned long NC :20;
} B;
volatile unsigned long W;
} JOFR3;
union
{
struct
{
volatile unsigned long JOFFSET4 :12;
volatile unsigned long NC :20;
} B;
volatile unsigned long W;
} JOFR4;
union
{
struct
{
volatile unsigned long HT :12;
volatile unsigned long NC :20;
} B;
volatile unsigned long W;
} HTR;
union
{
struct
{
volatile unsigned long LT :12;
volatile unsigned long NC :20;
} B;
volatile unsigned long W;
} LTR;
union
{
struct
{
volatile unsigned long SQ13 :5;
volatile unsigned long SQ14 :5;
volatile unsigned long SQ15 :5;
volatile unsigned long SQ16 :5;
volatile unsigned long L :4;
volatile unsigned long NC :8;
} B;
volatile unsigned long W;
} SQR1;
union
{
struct
{
volatile unsigned long SQ7 :5;
volatile unsigned long SQ8 :5;
volatile unsigned long SQ9 :5;
volatile unsigned long SQ10 :5;
volatile unsigned long SQ11 :5;
volatile unsigned long SQ12 :5;
volatile unsigned long NC :2;
} B;
volatile unsigned long W;
} SQR2;
union
{
struct
{
volatile unsigned long SQ1 :5;
volatile unsigned long SQ2 :5;
volatile unsigned long SQ3 :5;
volatile unsigned long SQ4 :5;
volatile unsigned long SQ5 :5;
volatile unsigned long SQ6 :5;
volatile unsigned long NC :2;
} B;
volatile unsigned long W;
} SQR3;
union
{
struct
{
volatile unsigned long JSQ1 :5;
volatile unsigned long JSQ2 :5;
volatile unsigned long JSQ3 :5;
volatile unsigned long JSQ4 :5;
volatile unsigned long JL :2;
volatile unsigned long NC :10;
} B;
volatile unsigned long W;
} JSQR;
union
{
struct
{
volatile unsigned long JDATA :16;
volatile unsigned long NC :16;
} B;
volatile unsigned long W;
} JDR1;
union
{
struct
{
volatile unsigned long JDATA :16;
volatile unsigned long NC :16;
} B;
volatile unsigned long W;
} JDR2;
union
{
struct
{
volatile unsigned long JDATA :16;
volatile unsigned long NC :16;
} B;
volatile unsigned long W;
} JDR3;
union
{
struct
{
volatile unsigned long JDATA :16;
volatile unsigned long NC :16;
} B;
volatile unsigned long W;
} JDR4;
union
{
struct
{
volatile unsigned long DATA :16;
volatile unsigned long ADC2DATA :16;
} B;
volatile unsigned long W;
} DR;
} ADC_T;

/*------------------------ Backup Registers ----------------------------------*/
typedef struct
{
unsigned long  RESERVED0;
volatile unsigned short DR1;
unsigned short  RESERVED1;
volatile unsigned short DR2;
unsigned short  RESERVED2;
volatile unsigned short DR3;
unsigned short  RESERVED3;
volatile unsigned short DR4;
unsigned short  RESERVED4;
volatile unsigned short DR5;
unsigned short  RESERVED5;
volatile unsigned short DR6;
unsigned short  RESERVED6;
volatile unsigned short DR7;
unsigned short  RESERVED7;
volatile unsigned short DR8;
unsigned short  RESERVED8;
volatile unsigned short DR9;
unsigned short  RESERVED9;
volatile unsigned short DR10;
unsigned short  RESERVED10;
union
{
struct
{
volatile unsigned short CAL :7;
volatile unsigned short CCO :1;
volatile unsigned short ASOE :1;
volatile unsigned short ASOS :1;
volatile unsigned short NC :6;
} B;
volatile unsigned short W;
} RTCCR;
unsigned short  RESERVED11;
union
{
struct
{
volatile unsigned short TPE :1;
volatile unsigned short TPAL :1;
volatile unsigned short NC :14;
} B;
volatile unsigned short W;
} CR;
unsigned short  RESERVED12;
union
{
struct
{
volatile unsigned short CTE :1;
volatile unsigned short CTI :1;
volatile unsigned short TPIE :1;
volatile unsigned short NC1 :5;
volatile unsigned short TEF :1;
volatile unsigned short TIF :1;
volatile unsigned short NC :6;
} B;
volatile unsigned short W;
} CSR;

unsigned short  RESERVED13[5];
volatile unsigned short DR11;
unsigned short  RESERVED14;
volatile unsigned short DR12;
unsigned short  RESERVED15;
volatile unsigned short DR13;
unsigned short  RESERVED16;
volatile unsigned short DR14;
unsigned short  RESERVED17;
volatile unsigned short DR15;
unsigned short  RESERVED18;
volatile unsigned short DR16;
unsigned short  RESERVED19;
volatile unsigned short DR17;
unsigned short  RESERVED20;
volatile unsigned short DR18;
unsigned short  RESERVED21;
volatile unsigned short DR19;
unsigned short  RESERVED22;
volatile unsigned short DR20;
unsigned short  RESERVED23;
volatile unsigned short DR21;
unsigned short  RESERVED24;
volatile unsigned short DR22;
unsigned short  RESERVED25;
volatile unsigned short DR23;
unsigned short  RESERVED26;
volatile unsigned short DR24;
unsigned short  RESERVED27;
volatile unsigned short DR25;
unsigned short  RESERVED28;
volatile unsigned short DR26;
unsigned short  RESERVED29;
volatile unsigned short DR27;
unsigned short  RESERVED30;
volatile unsigned short DR28;
unsigned short  RESERVED31;
volatile unsigned short DR29;
unsigned short  RESERVED32;
volatile unsigned short DR30;
unsigned short  RESERVED33; 
volatile unsigned short DR31;
unsigned short  RESERVED34;
volatile unsigned short DR32;
unsigned short  RESERVED35;
volatile unsigned short DR33;
unsigned short  RESERVED36;
volatile unsigned short DR34;
unsigned short  RESERVED37;
volatile unsigned short DR35;
unsigned short  RESERVED38;
volatile unsigned short DR36;
unsigned short  RESERVED39;
volatile unsigned short DR37;
unsigned short  RESERVED40;
volatile unsigned short DR38;
unsigned short  RESERVED41;
volatile unsigned short DR39;
unsigned short  RESERVED42;
volatile unsigned short DR40;
unsigned short  RESERVED43;
volatile unsigned short DR41;
unsigned short  RESERVED44;
volatile unsigned short DR42;
unsigned short  RESERVED45;    
} BKP_T;

/*------------------------ Controller Area Network ---------------------------*/
typedef struct
{
union
{
struct
{
volatile unsigned long TXRQ :1;
volatile unsigned long RTR :1;
volatile unsigned long IDE :1;
volatile unsigned long EXID :29;
} BExt;
struct
{
volatile unsigned long TXRQ :1;
volatile unsigned long RTR :1;
volatile unsigned long IDE :1;
volatile unsigned long NC :18;
volatile unsigned long STID :11;
} B;
volatile unsigned long W;
} TIR;
union
{
struct
{
volatile unsigned long DLC :4;
volatile unsigned long NC1 :4;
volatile unsigned long TGT :1;
volatile unsigned long NC :7;
volatile unsigned long TIME :16;
} B;
volatile unsigned long W;
} TDTR;
union
{
struct
{
volatile unsigned long DATA0 :8;
volatile unsigned long DATA1 :8;
volatile unsigned long DATA2 :8;
volatile unsigned long DATA3 :8;
} B;
volatile unsigned long W;
} TDLR;
union
{
struct
{
volatile unsigned long DATA4 :8;
volatile unsigned long DATA5 :8;
volatile unsigned long DATA6 :8;
volatile unsigned long DATA7 :8;
} B;
volatile unsigned long W;
} TDHR;
} CAN_TxMailBox_T;

typedef struct
{
union
{
struct
{
volatile unsigned long NC :1;
volatile unsigned long RTR :1;
volatile unsigned long IDE :1;
volatile unsigned long EXID :29;
} BExt;
struct
{
volatile unsigned long NC :1;
volatile unsigned long RTR :1;
volatile unsigned long IDE :1;
volatile unsigned long NC1 :18;
volatile unsigned long STID :11;
} B;
volatile unsigned long W;
} RIR;
union
{
struct
{
volatile unsigned long DLC :4;
volatile unsigned long NC2 :4;
volatile unsigned long FMI :8;
volatile unsigned long TIME :16;
} B;
volatile unsigned long W;
} RDTR;
union
{
struct
{
volatile unsigned long DATA0 :8;
volatile unsigned long DATA1 :8;
volatile unsigned long DATA2 :8;
volatile unsigned long DATA3 :8;
} B;
volatile unsigned long W;
} RDLR;
union
{
struct
{
volatile unsigned long DATA4 :8;
volatile unsigned long DATA5 :8;
volatile unsigned long DATA6 :8;
volatile unsigned long DATA7 :8;
} B;
volatile unsigned long W;
} RDHR;
} CAN_FIFOMailBox_T;

typedef struct
{
volatile unsigned long FR1;
volatile unsigned long FR2;
} CAN_FilterRegister_T;

typedef struct
{
union
{
struct
{
volatile unsigned long INRQ :1;
volatile unsigned long SLEEP :1;
volatile unsigned long TXFP :1;
volatile unsigned long RFLM :1;
volatile unsigned long NART :1;
volatile unsigned long AWUM :1;
volatile unsigned long ABOM :1;
volatile unsigned long TTCM :1;
volatile unsigned long NC1 :7;
volatile unsigned long RESET :1;
volatile unsigned long NC :16;
} B;
volatile unsigned long W;
} MCR;
union
{
struct
{
volatile unsigned long INAK :1;
volatile unsigned long SLAK :1;
volatile unsigned long ERRI :1;
volatile unsigned long WKUI :1;
volatile unsigned long SLAKI :1;
volatile unsigned long NC1 :3;
volatile unsigned long TXM :1;
volatile unsigned long RXM :1;
volatile unsigned long SAMP :1;
volatile unsigned long RX :1;
volatile unsigned long NC :20;
} B;
volatile unsigned long W;
} MSR;
union
{
struct
{
volatile unsigned long RQCP0 :1;
volatile unsigned long TXOK0 :1;
volatile unsigned long ALST0 :1;
volatile unsigned long TERR0 :1;
volatile unsigned long NC0 :3;
volatile unsigned long ABRQ0 :1;
volatile unsigned long RQCP1 :1;
volatile unsigned long TXOK1 :1;
volatile unsigned long ALST1 :1;
volatile unsigned long TERR1 :1;
volatile unsigned long NC1 :3;
volatile unsigned long ABRQ1 :1;
volatile unsigned long RQCP2 :1;
volatile unsigned long TXOK2 :1;
volatile unsigned long ALST2 :1;
volatile unsigned long TERR2 :1;
volatile unsigned long NC2 :3;
volatile unsigned long ABRQ2 :1;
volatile unsigned long CODE :2;
volatile unsigned long TME0 :1;
volatile unsigned long TME1 :1;
volatile unsigned long TME2 :1;
volatile unsigned long LOW0 :1;
volatile unsigned long LOW1 :1;
volatile unsigned long LOW2 :1;
} B;
volatile unsigned long W;
} TSR;
union
{
struct
{
volatile unsigned long FMP0 :2;
volatile unsigned long NC1 :1;
volatile unsigned long FULL0 :1;
volatile unsigned long FOVR0 :1;
volatile unsigned long RFOM0 :1;
volatile unsigned long NC :26;
} B;
volatile unsigned long W;
} RF0R;
union
{
struct
{
volatile unsigned long FMP1 :2;
volatile unsigned long NC1 :1;
volatile unsigned long FULL1 :1;
volatile unsigned long FOVR1 :1;
volatile unsigned long RFOM1 :1;
volatile unsigned long NC :26;
} B;
volatile unsigned long W;
} RF1R;
union
{
struct
{
volatile unsigned long TMEIE :1;
volatile unsigned long FMPIE0 :1;
volatile unsigned long FFIE0 :1;
volatile unsigned long FOVIE0 :1;
volatile unsigned long FMPIE1 :1;
volatile unsigned long FFIE1 :1;
volatile unsigned long FOVIE1 :1;
volatile unsigned long NC2 :1;
volatile unsigned long EWGIE :1;
volatile unsigned long EPVIE :1;
volatile unsigned long BOFIE :1;
volatile unsigned long LECIE :1;
volatile unsigned long NC1 :3;
volatile unsigned long ERRIE :1;
volatile unsigned long WKUIE :1;
volatile unsigned long SLKIE :1;
volatile unsigned long NC :14;
} B;
volatile unsigned long W;
} IER;
union
{
struct
{
volatile unsigned long EWGF :1;
volatile unsigned long EPVF :1;
volatile unsigned long BOFF :1;
volatile unsigned long NC1 :1;
volatile unsigned long LEC :3;
volatile unsigned long NC :9;
volatile unsigned long TEC :8;
volatile unsigned long REC :8;
} B;
volatile unsigned long W;
} ESR;
union
{
struct
{
volatile unsigned long BRP :10;
volatile unsigned long NC2 :6;
volatile unsigned long TS1 :4;
volatile unsigned long TS2 :3;
volatile unsigned long NC1 :1;
volatile unsigned long SJW :2;
volatile unsigned long NC :4;
volatile unsigned long LBKM :1;
volatile unsigned long SILM :1;
} B;
volatile unsigned long W;
} BTR;
unsigned long  RESERVED0[88];
CAN_TxMailBox_T sTxMailBox[3];
CAN_FIFOMailBox_T sFIFOMailBox[2];
unsigned long  RESERVED1[12];
union
{
struct
{
volatile unsigned long FINIT :1;
volatile unsigned long NC :31;
} B;
volatile unsigned long W;
} FMR;
union
{
struct
{

volatile unsigned long FBM0 :1;
volatile unsigned long FBM1 :1;
volatile unsigned long FBM2 :1;
volatile unsigned long FBM3 :1;
volatile unsigned long FBM4 :1;
volatile unsigned long FBM5 :1;
volatile unsigned long FBM6 :1;
volatile unsigned long FBM7 :1;
volatile unsigned long FBM8 :1;
volatile unsigned long FBM9 :1;
volatile unsigned long FBM10 :1;
volatile unsigned long FBM11 :1;
volatile unsigned long FBM12 :1;
volatile unsigned long FBM13 :1;
volatile unsigned long NC :18;
} B;
volatile unsigned long W;
} FM1R;
unsigned long  RESERVED2;
union
{
struct
{

volatile unsigned long FSC0 :1;
volatile unsigned long FSC1 :1;
volatile unsigned long FSC2 :1;
volatile unsigned long FSC3 :1;
volatile unsigned long FSC4 :1;
volatile unsigned long FSC5 :1;
volatile unsigned long FSC6 :1;
volatile unsigned long FSC7 :1;
volatile unsigned long FSC8 :1;
volatile unsigned long FSC9 :1;
volatile unsigned long FSC10 :1;
volatile unsigned long FSC11 :1;
volatile unsigned long FSC12 :1;
volatile unsigned long FSC13 :1;
volatile unsigned long NC :18;
} B;
volatile unsigned long W;
} FS1R;
unsigned long  RESERVED3;
union
{
struct
{
volatile unsigned long FFA0 :1;
volatile unsigned long FFA1 :1;
volatile unsigned long FFA2 :1;
volatile unsigned long FFA3 :1;
volatile unsigned long FFA4 :1;
volatile unsigned long FFA5 :1;
volatile unsigned long FFA6 :1;
volatile unsigned long FFA7 :1;
volatile unsigned long FFA8 :1;
volatile unsigned long FFA9 :1;
volatile unsigned long FFA10 :1;
volatile unsigned long FFA11 :1;
volatile unsigned long FFA12 :1;
volatile unsigned long FFA13 :1;
volatile unsigned long NC :18;
} B;
volatile unsigned long W;
} FFA1R;
unsigned long  RESERVED4;
union
{
struct
{
volatile unsigned long FACT0 :1;
volatile unsigned long FACT1 :1;
volatile unsigned long FACT2 :1;
volatile unsigned long FACT3 :1;
volatile unsigned long FACT4 :1;
volatile unsigned long FACT5 :1;
volatile unsigned long FACT6 :1;
volatile unsigned long FACT7 :1;
volatile unsigned long FACT8 :1;
volatile unsigned long FACT9 :1;
volatile unsigned long FACT10 :1;
volatile unsigned long FACT11 :1;
volatile unsigned long FACT12 :1;
volatile unsigned long FACT13 :1;
volatile unsigned long NC :18;
} B;
volatile unsigned long W;
} FA1R;
unsigned long  RESERVED5[8];
CAN_FilterRegister_T sFilterRegister[14];
} CAN_T;
回复 支持 反对

使用道具 举报

72

主题

2711

帖子

2

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
3505
金钱
3505
注册时间
2014-8-4
在线时间
696 小时
发表于 2015-7-29 21:36:09 | 显示全部楼层
回复【3楼】our单片机:
---------------------------------
眼前一亮

楼上都是高手,我还是too young too simple
以我资质之鲁钝,当尽平心静气、循序渐进、稳扎稳打之力。
回复 支持 反对

使用道具 举报

33

主题

1628

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
6660
金钱
6660
注册时间
2015-8-25
在线时间
1034 小时
发表于 2019-12-18 13:51:22 | 显示全部楼层
位段定义寄存器是TI的DSP 28xx用的多,有个不好之处,位段操作a.b.c比直接操作速度要慢
He who fights with monsters should look to it that he himself does not become a monster, when you gaze long into the abyss, the abyss also gazes into you.
过于执着就会陷入其中,迷失自己,困住自己。
回复 支持 反对

使用道具 举报

3

主题

42

帖子

0

精华

初级会员

Rank: 2

积分
121
金钱
121
注册时间
2019-7-4
在线时间
23 小时
发表于 2019-12-18 14:36:36 | 显示全部楼层
联合体妙用,MARK
回复 支持 反对

使用道具 举报

2

主题

41

帖子

0

精华

高级会员

Rank: 4

积分
810
金钱
810
注册时间
2019-4-25
在线时间
87 小时
发表于 2020-1-7 16:38:03 | 显示全部楼层
emmm   谢谢分享
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-5-20 08:43

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表