Re: Problem in interface of USB with PIC18f4550/PIC18f4455..
thanks Kurenai_ryu
i have got another problm that the computer could not recognize my device. the crystal on the board could not send a stable signel, the simulation seem to be perfect but in real hardware it could not work,the computer have detected my device more then 5 time yesterday but could not recognize and does not response
i have attach the schematic
the code is below
#include"C:\Program Files\Mikroelektronika\mikroC\Examples\EasyPic4\extra_examples\HID-library\USBdsc_1.c"
unsigned char Read_buffer[64];
unsigned char Write_buffer[64];
unsigned char num;
void SEND_MDM(unsigned char*);
//
// Timer interrupt service routine
//
void interrupt()
{
HID_InterruptProc(); // Keep alive
TMR0L = 100; // Re-load TMR0L
INTCON.TMR0IF = 0; // Re-enable TMR0 interrupts
}
//
// Start of MAIN program
//
void main()
{
unsigned char data;
ADCON1 = 0xFF; // Set PORTB to digital I/O
TRISB = 0; // Set PORTB to outputs
PORTB = 0; // Clear all outputs
//
// Set interrupt registers to power-on defaults
// Disable all interrupts
//
INTCON=0;
INTCON2=0xF5;
INTCON3=0xC0;
RCON.IPEN=0;
PIE1=0;
PIE2=0;
PIR1=0;
PIR2=0;
//
// Configure TIMER 0 for 3.3ms interrupts. Set prescaler to 256
// and load TMR0L to 100 so that the time interval for timer
// interrupts at 48MHz is 256*(256-100)*0.083 = 3.3ms
//
// The timer is in 8-bit mode by default
//
T0CON = 0x47; // Prescaler = 256
TMR0L = 100; // Timer count is 256-156 = 100
INTCON.TMR0IE = 1; // Enable T0IE
T0CON.TMR0ON = 1; // Turn Timer 0 ON
INTCON = 0xE0; // Enable interrupts
//
// Enable USB port
//
Hid_Enable(&Read_buffer, &Write_buffer);
Delay_ms(100);
num=0;
Delay_ms(100);
while(1)
{
Write_buffer[0]='A';
Write_buffer[1]='B';
Write_buffer[2]='C';
Write_buffer[3]='D';
// Send the number via USB
Hid_Write(&Write_buffer,4);
Delay_ms(100);
num++;
PORTB = 0xff;
}
Hid_Disable();
}
i am using MickroC and a crystal of 8 MHZ
the setting of the MickroC is attched also