PDA

View Full Version : 18F4550 USB takes over



milosch
- 27th March 2011, 14:42
Firstly, let me introduce myself. I've been lurking on the board for a couple of months while working on my new project. I've worked with only a couple of PICs, previously in ASM and now with Picbasic Pro.

My project includes LCD, asm keypad routines, and serial data IO using the built-in EUSART handled pretty much with the MElabs asm interrupt routine. I have working configuration menus for the device using the keypad.

To add USB, I was finally able to get just the sample routine for CDC serial port communication to work - basically their Hello World demo app. The device shows up as a com port and responds to any keypress on the PC with Hello World.

The problem is that when USB is enabled, USB seems to take over priority so that I can no longer use the keypad, the LCD is stuck at the point right before USBINIT, etc. If I configure the app to start without usb (usben = 0 in eprom default), things return to normal but of course USB does not work.

I'm not sure where to start to figure this out since it seems that the mystery is within the routines inserted by Picbasic for USB.

EDIT: Could be that it's just looping around inside the demo program section and never returning. I'll investigate, but thanks for reading...

milosch
- 27th March 2011, 15:17
Yes, that was it. Now instead of looping on the USBIN part, my way out is clear. It finally responds to a specific key and prints the result.

USBDATA:
cnt = 16

USB_IN:
LCDOUT $FE,$C0+15,"*"
' Must service USB regularly
USBSERVICE

USBIN 3,usb_buffer,cnt,NOUSB

usb_buffer[13] = 0
select case usb_buffer[0]
case 97
usb_buffer[13] = "A"
end select
USB_OUT:
USBSERVICE

usb_buffer[0] = "H"
usb_buffer[1] = "e"
usb_buffer[2] = "l"
usb_buffer[3] = "l"
usb_buffer[4] = "o"
usb_buffer[5] = "W"
usb_buffer[6] = "o"
usb_buffer[7] = "r"
usb_buffer[8] = "l"
usb_buffer[9] = "d"
usb_buffer[10] = 13
usb_buffer[11] = 10
usb_buffer[12] = 0

USBOut 3,usb_buffer,14,USB_OUT
NOUSB:
LCDOUT $FE,$C0+15," "
Return