[求助] 一个位操作问题
单片机程序,定义一个数组 char SEGS[32] 其中前180个位(bit)为有效位,最后4个无效。在这180个位中随机7个位组成一个7段式的led数字8。共有14个led数字,请教高手有什么好办法对这些数字赋值,谢谢!笨办法是:
// a ,b ,c ,d ,e ,f ,g
char number1[6] = {xx,xx,xx,xx,xx,xx,xx} //xx 是在SEGS[]里的bit的位数
void set_seg(unsigned char seg_number)
{
unsigned char seg_byte = 0,seg_bit = 0,data = 0;
seg_byte = seg_number/8;
seg_bit = seg_number%8;
data |= 1<<seg_bit;
SEGS[byte] = data;
}
void clear_seg(unsigned char seg_number)
{
unsigned char seg_byte = 0,seg_bit = 0,data = 0;
seg_byte = seg_number/8;
seg_bit = seg_number%8;
data &= ~(1<<seg_bit);
SEGS[byte] = data;
}
void set_number1(unsigned char number)
{
switch (number)
{
case 0:
{
set_seg(number1[0]);
clear_seg(number1[1]);
.
.
.
.
.
set_seg(number1[6]);
}break;
case 1:
.
.
.
case 9
}
}
思路:有没有一个办法可以把任意的几个位组成一个数组,就像内存映射那样打乱顺序,再按要求组合??