gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:43:49 24 4
gpt4 key购买 nike

我获取位的函数是:

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);
}

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

我该如何解决这个问题?

最佳答案

试试这个代码:

#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("%d\n",get_bit(ch, 4)); // If you try on a PC
printf("%d\n",get_bit2(ch, 4)); // If you try on a PC

ch &= (~(1<<4)); // To reset bit 4
printf("%d\n",get_bit(ch, 4)); // If you try on a PC
printf("%d\n",get_bit2(ch, 4)); // If you try on a PC


return 0;
}

关于c - 我想在 MPLAB XC8 上获取一些字符,但不能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44953716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com