View previous topic :: View next topic |
Author |
Message |
keivan
Joined: 09 Feb 2010 Posts: 2
|
Need Help (usb + 18f67J50) |
Posted: Sun Oct 17, 2010 2:02 pm |
|
|
I'm using 18f67j50 and compiler ver. 4.104
I use this pin configuration for usb connection
http://www.unitone.com.br/arquivos/esqusb01.jpg
and crystal is 20Mhz
my code is
Code: |
#define __USB_PIC_PERIF__ 1
//!#define USB_CONFIG_PID 0x0001
//!#define USB_CONFIG_VID 0x1234
//!
#include <18F67J50.h>
#fuses HS
#fuses PLL2
//#fuses CPUDIV2
#fuses NOWDT
#fuses NOIESO
#fuses NOXINST
#fuses NOSTVREN
#fuses NOFCMEN
#fuses NOPROTECT
#fuses NODEBUG
#use delay(clock=24000000)
//Tells the CCS PIC USB firmware to include HID handling code.
#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
#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
#define USB_CON_SENSE_PIN PIN_D7
#include <pic18_usb.h> //Microchip 18Fxx5x hardware layer for usb.c
#include <usb_desc_hid.h> //USB Configuration and Device descriptors for this UBS device
#include <usb.c> //handles usb setup tokens and get descriptor reports
#define LED1 PIN_F2
#define LED_ON output_high
#define LED_OFF output_low
#bit PLLEN = 0xf9b.6
void main()
{
PLLEN = 1;
int8 out_data[20];
int8 in_data[2];
int8 send_timer=0;
LED_ON(LED1);
delay_ms(1000);
usb_init_cs();
while (TRUE)
{
//! delay_ms(500);
//! LED_OFF(LED1);
//!
//! delay_ms(500);
//! LED_ON(LED1);
usb_task();
if (usb_enumerated()) {
if (!send_timer) {
send_timer=250;
out_data[0]=0x21;
out_data[1]=0x22;
usb_put_packet(1, out_data, 2, USB_DTS_TOGGLE);
}
if (usb_kbhit(1)) {
usb_get_packet(1, in_data, 2);
}
send_timer--;
delay_ms(1);
}
}
} |
But when connecting to pc says USB DEVICE NOT Recognized.
I don't know where I made mistake. I really appreciate if anyone help me. |
|
|
keivan
Joined: 09 Feb 2010 Posts: 2
|
|
Posted: Wed Oct 20, 2010 12:08 am |
|
|
No one knows about this problem ??? |
|
|
Andrés Hoyos
Joined: 20 Nov 2010 Posts: 1
|
|
Posted: Thu Dec 09, 2010 12:28 am |
|
|
You must use the next schematic connection:
http://www.unitone.com.br/arquivos/esqusb02.jpg
If you are using 20MHz crystal, the fuses configurations have to change...
#fuses HS
#fuses PLL5
#fuses NOCPUDIV
#use delay(clock=48000000)
This is all I know, but I have some problems and the computer don´t recognize it...
Suerte
Exitos
Puntería |
|
|
|