#define __USB_PIC_PERIF__ 1
#if !defined(__PCH__)
#error USB CDC Library requires PIC18
#endif
#if __USB_PIC_PERIF__
#DEFINE LED1 PIN_A1
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
//#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,CPUDIV1,VREGEN
#use delay(clock=48000000)
#else
#DEFINE LED1 PIN_a1
#include <18F452.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#endif //endif check to see which peripheral to use
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#if __USB_PIC_PERIF__ && defined(__PCH__)
#define USB_CON_SENSE_PIN PIN_c2
#endif
#include <usb_cdc.h>
char d0,d1,d2,d3,d4,d5,d6,d7,e0,e1,e2;
void usb_debug_task(void) {
static int8 last_connected;
static int8 last_enumerated;
int8 new_connected;
int8 new_enumerated;
static int8 last_cdc;
int8 new_cdc;
new_connected=usb_attached();
new_enumerated=usb_enumerated();
new_cdc=usb_cdc_connected();
if (new_connected && !last_connected)
printf("USB connected, waiting for enumaration...\r\n\n");
if (!new_connected && last_connected)
printf("USB disconnected, waiting for connection...\r\n\n");
if (new_enumerated && !last_enumerated)
printf("USB enumerated by PC/HOST\r\n\n");
if (!new_enumerated && last_enumerated)
printf("USB unenumerated by PC/HOST, waiting for enumeration...\r\n\n");
if (new_cdc && !last_cdc) {
printf("Serial program initiated on USB<->UART COM Port\r\n\n");
printf(usb_cdc_putc, "\r\n\n USB connected....\r\n\n");
}
last_connected=new_connected;
last_enumerated=new_enumerated;
last_cdc=new_cdc;
}
void main(void) {
d0=0;
d1=0;
d2=0;
d3=0;
d4=0;
d5=0;
d6=0;
d7=0;
e0=0;
e1=0;
e2=0;
#ifdef __PCH__
printf("PCH: v");
printf(__PCH__);
#else
printf("PCM: v");l,l
printf(__PCM__);
#endif
printf("\r\n");
usb_init_cs();
#if !(__USB_PIC_PERIF__)
printf("USBN: 0x%X", usbn_get_version());
printf("\r\n\n");
#endif
while (TRUE) {
usb_task();
usb_debug_task();
if (input(PIN_D0))
{
d0=1;
}
else
{
d0=0;
}
if (input(PIN_D1))
{
d1=1;
}
else
{
d1=0;
}
if (input(PIN_D2))
{
d2=1;
}
else
{
d2=0;
}
if (input(PIN_D3))
{
d3=1;
}
else
{
d3=0;
}
if (input(PIN_D4))
{
d4=1;
}
else
{
d4=0;
}
if (input(PIN_D5))
{
d5=1;
}
else
{
d5=0;
}
if (input(PIN_D6))
{
d6=1;
}
else
{
d6=0;
}
if (input(PIN_D7))
{
d7=1;
}
else
{
d7=0;
}
if (input(PIN_E0))
{
e0=1;
}
else
{
e0=0;
}
if (input(PIN_E1))
{
e1=1;
}
else
{
e1=0;
}
if (input(PIN_E2))
{
e2=1;
}
else
{
e2=0;
}
}
printf(usb_cdc_putc,"%c %c %c %c %c %c %c %c %c %c %c\n\r",d0,d1,d2,d3,d4,d5,d6,d7,e0,e1,e2);
}