PIC C - USB_CDC_GETC() 和检索字符串
我正在使用 PIC C 对 PIC18F4455 微控制器进行编程。我正在使用 USB_CDC.h 头文件。我的计算机上有一个程序发送一个字符串,例如“W250025”。但是,当我使用 usb_cdc_getc() 获取第一个字符时,它会冻结。有时程序只发送“T”,所以我真的只想获取第一个字符。
为什么我的代码永远不会执行过去的 receive=usb_cdc_getc();当我发送“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);}
}
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);}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道 PIC 微控制器的具体情况,但是,假设
usb_cdc_getc
的行为类似于正常的getc
,最可能的原因是您的字符没有到达函数,通常会阻塞。您要发送换行符吗?也可能是硬件问题,字符首先无法到达您的 uC。如果是前者,而不是所需的行为,则可能存在等效的非阻塞
getch
。I don't know the specifics of the PIC microcontroller, but, assuming that
usb_cdc_getc
behaves like the normalgetc
, the most likely cause is that your characters aren't reaching the function, which normally blocks. Are you sending a newline? It could also be a hardware problem where the characters aren't reaching your uC in the first place.If it is the former, and not the desired behavior there likely is a nonblocking
getch
equivalent.也许这有帮助:
来自 https://github.com/tkrworks/PICnome-Firmware/blob/master/usb_cdc.h
Maybe this helps:
from https://github.com/tkrworks/PICnome-Firmware/blob/master/usb_cdc.h