#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,NOPBADEN
#use delay (clock=48000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#DEFINE USB_HID_DEVICE true
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 8 //allocate 8 bytes in the hardware for transmission
//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
// and allocate buffer space on the peripheral
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 8 //allocate 8 bytes in the hardware for reception
#include <pic18_usb.h>
#include <USB.H>
#include <usb_desc_hid.h>
#include <usb.c>
#define USB_CON_SENSE_PIN PIN_B2
#define usb_attached() input(USB_CON_SENSE_PIN)
#use fast_io(d)
int8 x;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
// TODO: USER CODE!!
set_tris_d(0x00);
output_d(0x00);
usb_init();
x=0;
while(1)
{
usb_task();
if(usb_attached() && usb_enumerated())
{
output_d(0x01);
}
else if(usb_attached() && !usb_enumerated())
{
output_d(0x04);
}
else if(!usb_attached())
{
output_d(0x02);
}
}
}