pic 中的 microc 任务出错
char uart_rd;
int b;
void main() {
ANSEL = 0;
ANSELH = 0;
C1ON_bit = 0;
C2ON_bit = 0;
TRISC = 0;
PORTC = 0x00;
UART1_Init(9600);
Delay_ms(10);
UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);
while (1) {
if (UART1_Data_Ready()) {
uart_rd = UART1_Read();
UART1_Write(uart_rd);
**WordtoInt(uart_rd, b)**- this line code is my error
if(b <= 20)
{
PORTC = 0x01;
}
if(b > 20)&&(b <= 40)
{
PORTC = 0x03;
}
if(b > 40)&&(b <= 60)
{
PORTC = 0x07;
}
if(b > 60)&&(b <= 80)
{
PORTC = 0x0F;
}
if(b > 80)&&(b <= 100)
{
PORTC = 0x1F;
}
}
}
}
这是我的任务。当我构建它时,它向我显示一个错误。
我读取了从 0 到 100
的数字,这些数字表示电池电量,并且根据电量,端口 C
的 0 到 5
引脚会发光。
有人可以帮助我,如何找到将 word 转换为 int 的函数吗?
char uart_rd;
int b;
void main() {
ANSEL = 0;
ANSELH = 0;
C1ON_bit = 0;
C2ON_bit = 0;
TRISC = 0;
PORTC = 0x00;
UART1_Init(9600);
Delay_ms(10);
UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);
while (1) {
if (UART1_Data_Ready()) {
uart_rd = UART1_Read();
UART1_Write(uart_rd);
**WordtoInt(uart_rd, b)**- this line code is my error
if(b <= 20)
{
PORTC = 0x01;
}
if(b > 20)&&(b <= 40)
{
PORTC = 0x03;
}
if(b > 40)&&(b <= 60)
{
PORTC = 0x07;
}
if(b > 60)&&(b <= 80)
{
PORTC = 0x0F;
}
if(b > 80)&&(b <= 100)
{
PORTC = 0x1F;
}
}
}
}
This is my task. When I build it, it shows me an error.
I read numbers from 0 to 100
, which indicate the battery charge and depending on the charge, 0 to 5
pins of port C
will glow.
Could someone help me, how to find function which convert word to int?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
uart_rd 是一个单字节字符变量。 b 是整型变量。要将 uart_rd 转换为 b 只需执行以下操作:
uart_rd is a one byte char variable. b is in integer variable. To convert uart_rd to b just do this:
简单地
b = uart_rd;
或b = (unsigned char)uart_rd;
怎么样?How about simply
b = uart_rd;
orb = (unsigned char)uart_rd;
?