The following document details some of the functions and procedures to make a connection by CDC (serial port emulation) with a 18F family microcontroller with USB support and LabView. We welcome comments, corrections and / or corrections suggestions for this document.
Connection CDC PIC \u0026lt;-> LabView
The hardware used for this example has 5 Pushbuttons connected on port A (A1.. A5) and 8 leds on port B (B0.. B7).
<18f2550.h>
# include # fuses HSPLL, NOWDT, NOPROTECT, NOLVP, NODEBUG, USBDIV, PLL4, CPUDIV1 , VREG, NOPBADEN
# use delay (clock = 48000000) # define LED1
PIN_B0
# define LED2 LED3 PIN_B1
PIN_B2
# define # define # define LED4 PIN_B3
LED5 PIN_B4
#define LED6 PIN_B5
#define LED7 PIN_B6
#define LED8 PIN_B7
#define LED_ON output_low
#define LED_OFF output_high
#include
#include
void main(void) {
char c;
usb_init();
while (TRUE) {
if (usb_enumerated()) {
if (usb_cdc_kbhit()) {
c=usb_cdc_getc();
if (c=='1') output_toggle(LED1);
if (c=='2') output_toggle(LED2);
if (c=='3') output_toggle(LED3);
if (c=='4') output_toggle(LED4);
if (c=='5') output_toggle(LED5);
if (c=='6') output_toggle(LED6);
if (c=='7') output_toggle(LED7);
if (c=='8') output_toggle(LED8);
}
if (input_STATE(PIN_A5)==0){
delay_ms(800);
printf(usb_cdc_putc,"5\r");
}
if (input_state(PIN_A4)==0){
delay_ms(800);
printf(usb_cdc_putc,"4\r");
}
if (input_state(PIN_A3)==0){
delay_ms(800);
printf(usb_cdc_putc,"3\r");
}
if (input_state(PIN_A2)==0){
delay_ms(800);
printf(usb_cdc_putc,"2\r");
}
if (input_state (PIN_A1) == 0) {
delay_ms (800);
printf (usb_cdc_putc, "1 \\ r");}
}}}
Here's a video to complement the document ...
.
0 comments:
Post a Comment