[B]device [/B]= 18F4550
[B]clock [/B]= 48
// 20Mhz crystal, 48Mhz internal (FS USB)
[B]config[/B]
PLLDIV = 5,
CPUDIV = OSC1_PLL2,
USBDIV = 2,
FOSC = HSPLL_HS,
VREGEN = ON
// import modules...
[B]include [/B]"usbhid.bas"
// TX report...
[B]structure [/B]TTXReport
Time [B]as word[/B]
Message [B]as string[/B]
[B]end structure[/B]
[B]dim [/B]TXReport [B]as[/B] TTXReport [B]absolute [/B]TXReportRAM
// RX report...
[B]structure [/B]TRXReport
LED0 [B]as bit[/B]
LED1 [B]as bit[/B]
[B]end structure[/B]
[B]dim [/B]RXReport [B]as [/B]TRXReport [B]absolute [/B]RXReportRAM
// alias port pins to LEDs...
[B]dim [/B]
LED0 [B]as [/B]PORTB.0,
LED1 [B]as [/B]PORTB.1
// initialise...
TXReport.Time = 0
[B]low[/B](LED0)
[B]low[/B](LED1)
// connect to USB...
[B]repeat[/B]
[B]until [/B]HID.Connected
// main program loop...
[B]while true[/B]
// if we have data, set port values, update message
// and then reset time counter...
[B]if [/B]DataAvailable [B]then[/B]
ReadReport
LED0 = RXReport.LED0
LED1 = RXReport.LED1
TXReport.Message = "PORT CHANGED"
[B]WriteReport[/B]
TXReport.Time = 0
[B]delayms[/B](100)
// no data, set waiting message...
[B]else[/B]
TXReport.Message = "WAITING..."
[B]WriteReport[/B]
[B]inc[/B](TXReport.Time)
[B]endif[/B]
[B]wend[/B]