user-0 提问: 更好的方法定义故障bit位

回复:
user: user-1
content: 仅供参考： #include <stdio.h>  #define WIRTE_UINT(des ,x ,pos ,len)  (                                   \     (des)                                                                 \     &                                                                     \        ~(                                /* 除要修改的位为0，其余都为1 */ \             (                                                             \                 (1<<(len))-1             /* 长度为len位的1             */ \             )                                                             \             <<(32-(pos)-(len))           /* 左移32-(pos)-(len)位       */ \         )                                                                 \     |                                                                     \         (                                                                 \             (x)                                                           \             <<(32-(pos)-(len))                                            \         )                                                                 \ ) #define READ_UINT(src ,pos ,len)      (                                   \     (                                                                     \         (                                                                 \             (unsigned)(src)                                               \         )                                                                 \         >>(32-(pos)-(len))               /* 逻辑右移32-(pos)-(len)位   */ \     )                                                                     \     &                                                                     \     (                                                                     \         (1<<(len))-1                     /* 长度为len位的1             */ \     )                                                                     \ )  int main()                              //                1111111111222222222233 {                                       //bit   01234567890123456789012345678901     unsigned int des = 0x661;           //      00000000000000000000011001100001     unsigned int r;      des = WIRTE_UINT(des ,3 ,28 ,2);    //      00000000000000000000011001101101     printf("des==0x%08X\n",des);     r = READ_UINT(des ,28 ,2);     printf("r==%d\n",r);     return 0; } //des==0x0000066D //r==3

user: user-1
content: 参考C:\Program Files (x86)\Windows Kits\8.1\Include\um\WinUser.h /*  * Extended Window Styles  */ #define WS_EX_DLGMODALFRAME     0x00000001L #define WS_EX_NOPARENTNOTIFY    0x00000004L #define WS_EX_TOPMOST           0x00000008L #define WS_EX_ACCEPTFILES       0x00000010L #define WS_EX_TRANSPARENT       0x00000020L #if(WINVER >= 0x0400) #define WS_EX_MDICHILD          0x00000040L #define WS_EX_TOOLWINDOW        0x00000080L #define WS_EX_WINDOWEDGE        0x00000100L #define WS_EX_CLIENTEDGE        0x00000200L #define WS_EX_CONTEXTHELP       0x00000400L  #endif /* WINVER >= 0x0400 */ #if(WINVER >= 0x0400)  #define WS_EX_RIGHT             0x00001000L #define WS_EX_LEFT              0x00000000L #define WS_EX_RTLREADING        0x00002000L #define WS_EX_LTRREADING        0x00000000L #define WS_EX_LEFTSCROLLBAR     0x00004000L #define WS_EX_RIGHTSCROLLBAR    0x00000000L  #define WS_EX_CONTROLPARENT     0x00010000L #define WS_EX_STATICEDGE        0x00020000L #define WS_EX_APPWINDOW         0x00040000L   #define WS_EX_OVERLAPPEDWINDOW  (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE) #define WS_EX_PALETTEWINDOW     (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST)  #endif /* WINVER >= 0x0400 */  #if(_WIN32_WINNT >= 0x0500) #define WS_EX_LAYERED           0x00080000  #endif /* _WIN32_WINNT >= 0x0500 */   #if(WINVER >= 0x0500) #define WS_EX_NOINHERITLAYOUT   0x00100000L // Disable inheritence of mirroring by children #endif /* WINVER >= 0x0500 */  #if(WINVER >= 0x0602) #define WS_EX_NOREDIRECTIONBITMAP 0x00200000L #endif /* WINVER >= 0x0602 */  #if(WINVER >= 0x0500) #define WS_EX_LAYOUTRTL         0x00400000L // Right to left mirroring #endif /* WINVER >= 0x0500 */  #if(_WIN32_WINNT >= 0x0501) #define WS_EX_COMPOSITED        0x02000000L #endif /* _WIN32_WINNT >= 0x0501 */ #if(_WIN32_WINNT >= 0x0500) #define WS_EX_NOACTIVATE        0x08000000L #endif /* _WIN32_WINNT >= 0x0500 */

user: user-0
content: 故障bit需要是变量，需要set和reset

user: user-2
content: 既然是单片机，为什么不外置编码器来直接提供故障号呢？有了号，再来个函数指针数组直接搞定。

user: user-0
content: 硬件不做改动

user: user-0
content: 单从软件角度有没有更好的定义方法？

user: user-2
content: 既然是软的那为什么不用故障号变量，却一定要用比特表达呢？ 所以您得说清楚什么需求什么约束，否则问题没啥意义呀。