CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

about ex_usb_hid

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
macaby
Guest







about ex_usb_hid
PostPosted: Mon Jan 03, 2005 3:01 pm     Reply with quote

I tried ex_usb_hid.c in pic16C765 to communicate to PC program (builder CPP3) : 0->1% CPU at 800 bytes /s (multi-thread) : i'm glad. I work with "USB complete" and WinDDK.
But as soon i want to optimize the ex_usb_hid.c , delete line with "printf() .." and other i don't want , the controller freeze in "usb_wait_for_enumeration();"

what's append , i don't understand : i have just delete the serial instruction
If i reactive the lines , the program well run.

/////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS ////
//// C compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, ////
//// reproduction or distribution is permitted without written ////
//// permission. Derivative programs created using this software ////
//// in object code form are not restricted in any way. ////
/////////////////////////////////////////////////////////////////////////

#define USB_PIC16C765 1 //set to 1 to use a PIC16c765 USB Peripheral
//set to 0 to use a National USBN960x peripheral

#include <16C765.h>
#device *=16
#fuses H4,NOWDT,NOPROTECT,PUT
#use delay(clock=24000000)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#DEFINE LED_1 PIN_B5
#DEFINE LED_2 PIN_B4
#DEFINE LED_3 PIN_B3
#DEFINE BUTTON PIN_A4

//Tells the CCS PIC USB firmware to include HID handling code.
#DEFINE USB_HID_DEVICE TRUE

//Set this to FALSE if you only want to test enumeration. Some USB test programs,
//such as USBCHECK, crash if you are trying to test enumeration and the device
//starts sending data once configured.
#DEFINE USB_RUN_WHEN_CONFIGURED TRUE

//the following defines needed for the CCS USB PIC driver to enable the TX endpoint 1
#define USB_EP1_TX_ENABLE 1 //turn on EP1 for IN bulk/interrupt transfers
#define USB_EP1_TX_SIZE 2 //if you change this, be sure to change the hid descriptor

//the following defines needed for the CCS USB PIC driver to enable the RX endpoint 1
#define USB_EP1_RX_ENABLE 1 //turn on EP1 for OUT bulk/interrupt transfers
#define USB_EP1_RX_SIZE 2 //if you change this, be sure to change the hid descriptor

#include "pic_usb.h" //Microchip PIC16C765 hardware layer for usb.c

#include "usb.c" //handles usb setup tokens and get descriptor reports

void main() {
int8 out_data[USB_EP1_TX_SIZE];
int8 in_data[USB_EP1_RX_SIZE];


/*
#ifdef __PCH__
printf("\r\n\r\nPCH: v");
printf(__PCH__);
#else
printf("\r\n\r\nPCM: v");
printf(__PCM__);
#endif
*/

/*
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(RA0_RA1_RA3_ANALOG);
set_adc_channel(1);
*/

usb_init();

/*
#if !(USB_PIC16C765)
printf("\r\nUSBN: 0x%X\r\n", usbn_get_version());
output_low(LED_1);
output_low(LED_2);
output_low(LED_3);
delay_ms(1000);
output_high(LED_1);
output_high(LED_2);
#else
printf("\r\n");
#ENDIF
*/

// printf("\r\n\r\nWaiting for enumeration...");


output_low(LED_1);
output_low(LED_2);

while (TRUE) {
output_high(LED_1);
usb_wait_for_enumeration();
output_high(LED_2);
// printf("\r\n\r\n***Enumerated***\r\n");
while(usb_enumerated()) {
#IF USB_RUN_WHEN_CONFIGURED
if (usb_kbhit(1)) {
usb_gets(1, in_data, USB_EP1_RX_SIZE);
// printf("\r\n--> Received 2 bytes: 0x%X 0x%X",in_data[0],in_data[1]);
if (in_data[0]) {output_low(LED_1);} else {output_high(LED_1);}
if (in_data[1]) {output_low(LED_2);} else {output_high(LED_2);}
}
// out_data[0]=read_adc();
out_data[1]=!input(BUTTON);
if (usb_put_packet(1, out_data, USB_EP1_TX_SIZE, TOGGLE)) {
// printf("\r\n<-- Sending 2 bytes: 0x%X 0x%X", out_data[0], out_data[1]);
}
output_low(LED_2);
delay_ms(500);
output_high(LED_2);

#ENDIF
}
// printf("\r\n\r\nDevice Un-configured.r\n");
}
}
macby
Guest







it's ok
PostPosted: Tue Jan 04, 2005 8:23 am     Reply with quote

If i append one delay 5ms or less , the sie have time to terminate init and all work fine.
In the example the delay come from the serial I/O
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jan 04, 2005 9:11 am     Reply with quote

/////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2003 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS ////
//// C compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, ////
//// reproduction or distribution is permitted without written ////
//// permission. Derivative programs created using this software ////
//// in object code form are not restricted in any way. ////
/////////////////////////////////////////////////////////////////////////
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group