c语言 - 我想在 MPLAB XC8 上获得一些字符,但我不能?



我获取位的函数是:

extern volatile unsigned char Temp       @ 0x036;
extern volatile __bit W       @ (((unsigned) &Temp)*8) + 4;
void get_bit(volatile unsigned char *reg, unsigned num) {
W = (*reg & (1 << num));
}

主要功能是:

int main() {
volatile unsigned char ch = 0b00001000;
get_bit(&ch, 4);
}

当我编译此块代码时,出现错误(错误:表达式语法(。

我该怎么做才能解决这个问题?

试试这段代码:

#include <stdio.h>
unsigned char get_bit(unsigned char reg, unsigned num) 
{
return (reg & (1 << num));
}
unsigned char get_bit2(unsigned char reg, unsigned num) 
{
return (reg & (1 << num))?1:0;
}
int main() 
{
volatile unsigned char ch = 0b00001000;
ch |= (1<<4);   // To set bit 4
printf("%dn",get_bit(ch, 4)); // If you try on a PC
printf("%dn",get_bit2(ch, 4)); // If you try on a PC
ch &= (~(1<<4));   // To reset bit 4
printf("%dn",get_bit(ch, 4)); // If you try on a PC
printf("%dn",get_bit2(ch, 4)); // If you try on a PC

return 0;
}

相关内容

  • 没有找到相关文章

最新更新