pic 中的 microc 任务出错

发布于 2024-12-20 05:25:28 字数 1132 浏览 3 评论 0原文

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 的数字,这些数字表示电池电量,并且根据电量,端口 C0 到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深海夜未眠 2024-12-27 05:25:28

uart_rd 是一个单字节字符变量。 b 是整型变量。要将 uart_rd 转换为 b 只需执行以下操作:

b = (int) uart_rd;

uart_rd is a one byte char variable. b is in integer variable. To convert uart_rd to b just do this:

b = (int) uart_rd;
若无相欠,怎会相见 2024-12-27 05:25:28

简单地 b = uart_rd;b = (unsigned char)uart_rd; 怎么样?

How about simply b = uart_rd; or b = (unsigned char)uart_rd;?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文