📄 picusb.c
字号:
/////////////////////////////////////////////////////////////////////////
//// PicUSB.c ////
//// ////
//// Le Cong Cuong - 1/12/2008 lecongcuong@hotmail.com ////
//// ////
//// http://lecongcuong.blogspot.com ////
/////////////////////////////////////////////////////////////////////////
#include <18F4550.h>
#device *=16 adc =10
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
/////////////////////////////////////////////////////////////////////////////
//
// CCS Library dynamic defines. For dynamic configuration of the CCS Library
// for your application several defines need to be made. See the comments
// at usb.h for more information
//
/////////////////////////////////////////////////////////////////////////////
#define USB_HID_DEVICE FALSE //
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 2 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE 3 //size to allocate for the rx endpoint 1 buffer
/////////////////////////////////////////////////////////////////////////////
//
// If you are using a USB connection sense pin, define it here. If you are
// not using connection sense, comment out this line. Without connection
// sense you will not know if the device gets disconnected.
// (connection sense should look like this:
// 100k
// VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
// |
// +----/\/\/\/\/\-----GND
// 100k
// (where VBUS is pin1 of the USB connector)
//
/////////////////////////////////////////////////////////////////////////////
//#define USB_CON_SENSE_PIN PIN_B2 //CCS 18F4550 development kit has optional conection sense pin
/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries. See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////
#include <pic18_usb.h> //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <PicUSB.h> //Configuraci髇 del USB y los descriptores para este dispositivo
#include <usb.c> //handles usb setup tokens and get descriptor reports
#include <lcd.c>
#define LED0 PIN_A5
#define LED1 PIN_B5
#define LED2 PIN_B4
#define LED3 PIN_B3
#define LED4 PIN_B2
#define LED_ON output_high
#define LED_OFF output_low
#define statusLED LEDptr[0]
#define mode receive[0]
#define LCDlegth receive[1]
void main(void) {
int8 receive[33];
int8 LEDptr[1];
int8 ADCptr[2];
int16 adc;
int8 i =0;
set_tris_b(0x00);
output_b(0x00);
set_tris_a(0x00);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0_ANALOG);
set_adc_channel(0);
lcd_init();
lcd_putc("\fLe Cong Cuong 3I\nPIC USB example!");
usb_init(); //initialize the USB
usb_task(); //enables USB peripherals and interrupts
usb_wait_for_enumeration(); //wait until the PicUSB be configured by the host
LED_ON(LED0);
while (TRUE)
{
if(usb_enumerated())
{
if (usb_kbhit(1))
{
usb_gets(1,receive,34,USB_DTS_TOGGLE);
if (mode == 2)
{
output_b(receive[1]);
statusLED = receive[1];
usb_put_packet(1, LEDptr, 1, USB_DTS_TOGGLE);
}
if (mode == 3)
{
lcd_putc("\f");
for (i=2;i<LCDlegth+2;i++)
{
if (i == 18)
{
lcd_gotoxy(1,2);
lcd_putc(receive[18]);
}
else lcd_putc(receive[i]);
}
}
if (mode == 4)
{
adc = read_adc();
ADCptr[1] = (int8)(adc & 0xFF);
ADCptr[0] = (int8)((adc >>8)&0xFF);
usb_put_packet(1,ADCptr,2,USB_DTS_TOGGLE);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -