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

Wanted : A simple USB example

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







Wanted : A simple USB example
PostPosted: Tue May 27, 2003 3:51 pm     Reply with quote

Hello there,

Does anyone have a simple PIC to PC USB example (written in CCS C obviously)?

If so, I would be very greatful if you would let me have the code.

Admittadly, I do not understand USB fully - however all I would like to be able to do is have the PC communicate with a PIC (say send strings back and forth) in a simple no-brainer mannor!.

Am I right in thinking that one has to have a Vendor ID in order to use USB?

I think the earlier I get into this the better, as USB is obviously taking off "big style" - as they say.

Any help appreciated. Cheers!

Regards,
Darren
___________________________
This message was ported from CCS's old forum
Original Post ID: 144514797
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Thu Oct 14, 2004 5:23 am     Reply with quote

I would like to have it as well Razz
_________________
Alex
Mark



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

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

PostPosted: Thu Oct 14, 2004 5:56 am     Reply with quote

Look in your examples & drivers directories. There are several there.
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Oct 14, 2004 7:09 am     Reply with quote

Code for the FTDI245....

Code:

#include .... // include CPU specific header and port definitions

#define   TxCQsize   64   // Console Tx buffer size
#define   RxCQsize   64   // Console Tx buffer size


   //; Console Rx Ring Buffer control
byte   Rx_HeadC;
byte   Rx_TailC;

   //; Console Tx Ring Buffer control
byte   Tx_HeadC;
byte   Tx_TailC;

   // Console Tx buffer
byte   Tx_BaseC[TxCQsize];

   // Console Rx buffer
byte   Rx_BaseC[RxCQsize];



void console_putc(char TxChar)
/************************************************************************************************
;
; Subroutine console_putc
;
;   Stdout routine (BLOCKING) for putting characters to the console interface.
;
; On Exit:
;
; ***********************************************************************************************/
   {
   long counter = 65535;   // setup counter to prevent lockup on failure of USB

   //; test to determine if the USB device is active
   if (!bit_test(USB_PwrEn))
      {
      while ((counter!=0) && bit_test(USB_WRF))
         {
         counter--;
         }
      if (Counter)
         {
         DBus = TxChar;      //; write the character to the data bus
         bit_set(USB_WR);
         DBusDir = 0;      //; set data bus to output
         bit_clear(USB_WR);
         DBusDir = 0xff;      //; set data bus to input
         }
      else
         {
         // timeout waiting on USB
         // .. do something else here such as write to serial port
         putc(TxChar);
         }
      }
   else
      {
      //; USB port not active, do something else like pass control to the async port code
      putc(TxChar);
      }
   }


bit console_kbhit(void)
   {
   // test to determine if the USB device is active
   return ((!bit_test(USB_PwrEn)) && (!bit_test(USB_RDF)));      
   }

char console_getc(void)   
   {
   char Rx_Char = 0x00;
      
   // test to determine if the USB device is active
   // if not active pass exit
   if ((!bit_test(USB_PwrEn)) && (!bit_test(USB_RDF)))
      {
      //  here we have a character in the USB controller
      DBusDir = 0xFF;      // set the data bus to input
      bit_clear(USB_RD);
      Rx_Char = DBus;            
      bit_set(USB_RD);            
      }
   return (Rx_Char);   
   }   


void main()
   {
   init_pic();

   //; initialise the I/O lines to the USB controller
   bit_set(USB_FLUSH);   //; initialise the flush FIFO pin
   bit_clear(USB_WR);     //; set default WR level
   bit_set(USB_RD);      //; set default RD level

   //; initialise Console receive buffer pointers
   Rx_HeadC = 0;
   Rx_TailC = 0;

   //; initialise Console transmit buffer pointers
   Tx_HeadC = 0;
   Tx_TailC = 0;

   printf(console_putc,"Hello, world\r\n");
      
   //ExecLoop
   while (1)
      {
      // do something
      // don't forget to scan the USB device
      // note that the FTDI245 has a large input buffer
      // there is not need to do a buffer to buffer copy
      //
      }
   }



Have fun....
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Thu Oct 14, 2004 7:28 am     Reply with quote

Has anybode got a code for the USBN9603
_________________
Alex
Mark



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

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

PostPosted: Thu Oct 14, 2004 8:16 am     Reply with quote

Like I said, CCS gives it to you:
Code:

/////////////////////////////////////////////////////////////////////////
////                      usbn960x.c                                 ////
////                                                                 ////
////    National USBN960x Hardware layer for CCS's PIC USB driver.   ////
////                                                                 ////
//// This file is part of CCS's PIC USB driver code, which includes: ////
////   usb_desc_*.h - an example set of config and device descriptor ////
////   usb.c - USB token and request handler code                    ////
////   usb.h - definitions, prototypes and global variables          ////
////                                                                 ////
//// usbn960x.c is the hardware layer level driver for the CCS PIC   ////
//// USB driver.  You can replace usbn960x.c with another hardware   ////
//// layer level and still use the other parts of the PIC USB        ////
//// driver.                                                         ////
////                                                                 ////
//// Three examples are given using CCS's PIC USB driver.            ////
//// ex_usb_scope.c is a bulk device that sends 512 bytes to the     ////
//// host and uses the USBN960x.  ex_usb_hid.c is a HID device and   ////
//// uses the PIC16C7x5 or USBN960x.  ex_usb_mouse.c is a HID mouse  ////
//// and uses the PIC16C7x5 or USBN960x.                             ////
////                                                                 ////
//// This example USB peripheral layer was written and tested with   ////
//// CCS's USB Full Speed demo board.  When using your own design,   ////
//// either wire your USB960x the same as our demo board or change   ////
//// the port and pin definitions below.                             ////
////                                                                 ////
////   *************************  NOTE  **************************   ////
//// This driver uses INT_EXT.  It requires INT_EXT to interrupt the ////
//// PIC when an event has happened on the USBN960x.  Because of     ////
//// this code enables interrupts.  A user modification can be made  ////
//// to poll the USBN960x device instead of relying on an interrupt. ////
////                                                                 ////
alexz



Joined: 17 Sep 2004
Posts: 133
Location: UK

View user's profile Send private message

PostPosted: Thu Oct 14, 2004 8:21 am     Reply with quote

Yeah, I ve found it now, thanks
_________________
Alex
Guest








PostPosted: Mon Oct 18, 2004 8:31 am     Reply with quote

http://www.beyondlogic.org/usbnutshell/usb1.htm
http://www.beyondlogic.org/usbnutshell/usb7.htm#PIC16F876Example
Maybe some useful extra information.
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