还是给你看看是行径 回事,如下:
#include <stdio.h>
//下面是你要整合的I/O口
/*
#define SEG1 p1.0
#define SEG2 p2.4
#define SEG2 p3.3
#define SEG2 p3.6
.................
*/
#define uint unsigned int
union test{
uint reg;
struct {
uint SEG1:1;
uint SEG2:1;
uint SEG3:1;
uint SEG4:1;
uint SEG5:1;
uint SEG6:1;
uint SEG7:1;
uint SEG8:1;
}bits;
};
int main(void)
{
union test mytest;
mytest.reg = 0x3a;//这里是你要放的数据,可以在C编译器上改变数据看执行结果
printf("SEG1=%x\n", mytest.bits.SEG1);
printf("SEG2=%x\n", mytest.bits.SEG2);
printf("SEG3=%x\n", mytest.bits.SEG3);
printf("SEG4=%x\n", mytest.bits.SEG4);
printf("SEG5=%x\n", mytest.bits.SEG5);
printf("SEG6=%x\n", mytest.bits.SEG6);
printf("SEG7=%x\n", mytest.bits.SEG7);
printf("SEG8=%x\n", mytest.bits.SEG8);
return 0;
}
|