2

I'm programming a PIC18F4455 Microcontroller using PIC C. I'm using the USB_CDC.h header file. I have a program on the computer sending a string such as "W250025". However, when I use usb_cdc_getc() to get the first char, it freezes. Sometimes the program sends only 'T', so I really want to just get the first character.

Why does my code never execute past received=usb_cdc_getc(); when I send "W250025"?

if (usb_cdc_kbhit())
      {
         //printf(lcd_putc, "Check 3"); delay_ms(3000); printf(lcd_putc, "\f");
         received = usb_cdc_getc();
         printf(lcd_putc, "Received "); lcd_putc(received); delay_ms(3000); printf(lcd_putc, "\f");
         if (received == 'W'){   //waveform
            disable_interrupts(INT_TIMER1);
            set_adc_channel(0);
            load_and_print_array(read_into_int(), read_into_int());}
         else if (received == 'T'){ //temperature
            set_adc_channel(1);
            enable_interrupts(INT_TIMER1);}
      }
4

2 回答 2

1

我不知道 PIC 微控制器的细节,但是,假设它的usb_cdc_getc行为像 normal getc,最可能的原因是你的角色没有达到通常会阻塞的功能。您要发送换行符吗?这也可能是一个硬件问题,其中角色首先没有到达您的 uC。

如果是前者,而不是所需的行为,则可能存在非阻塞getch等效项。

于 2010-03-31T03:10:37.477 回答
0

也许这有帮助:

usb_cdc_getc()- 从接收缓冲区中获取一个字符。如果接收缓冲区中没有数据,它将一直等到接收缓冲区中有数据。如果您不想在无限循环中等待,usb_cdc_kbhit()请在调用之前先检查是否有数据usb_cdc_getc()。”

来自https://github.com/tkrworks/PICnome-Firmware/blob/master/usb_cdc.h

于 2017-05-25T19:31:56.450 回答