|
|
View previous topic :: View next topic |
Author |
Message |
vtrx
Joined: 11 Oct 2017 Posts: 142
|
PIC16F1455 USB HID |
Posted: Sun Feb 05, 2023 6:05 am |
|
|
Where could I find a USB HID example (Keyborad or Joystick) using the 16F1455?
I tried to convert my programs made to 18F but i just couldn't. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Feb 05, 2023 6:11 am |
|
|
Haven't looked in years( I have a old version of the compiler ..) but doesn't CCS have them in the 'examples' folder ? Thought they had a 'generic' version.16 or 18s ? |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Sun Feb 05, 2023 7:20 am |
|
|
I don't have the actual hardware, but I think the initial header is this:
Code: | #fuses INTRC_IO, WDT_SW, PUT, NOMCLR, PROTECT, BROWNOUT, NOIESO, NOFCMEN, WRT, NOCPUDIV, LS48MHZ, PLL3X, PLLEN, STVREN, LPBOR, NODEBUG, NOLVP
#use delay(clock=48000000)
...
#include <pic16f_usb.h>
#include <usb_desc_hid 8_byte.h> //USB Configuration and Device descriptors for this UBS device
#include "usb.c" //handles usb setup tokens and get descriptor reports |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Sun Feb 05, 2023 7:44 am |
|
|
I don't have ' pic16f_usb.h' in the 'drivers' folder...though the pic_usb.h does comment on 16F device.
One possible problem is that pic16f_usb could be a renamed CCS header file or modified /custom coded version by the programmer who wrote the program you're trying to run
sadly there's no //comment as to WHERE that file came from. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Feb 05, 2023 8:09 am |
|
|
temtronic, you need to upgrade your compiler if you want to answer
questions like this. The compiler does have pic16f_usb.h in the Drivers folder. |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Sun Feb 05, 2023 8:11 am |
|
|
Code: | /////////////////////////////////////////////////////////////////////////
//// pic16f_usb.h ////
//// ////
//// Hardware layer for CCS's USB library. This hardware layer ////
//// supports the USB peripheral on the enhanced PIC family chips. ////
//// Current supported families are: ////
//// PIC16F1454/1455/1459 ////
//// ////
//// This file is part of CCS's PIC USB driver code. See USB.H ////
//// for more documentation and a list of examples. ////
//// ////
//// See the section labeled EXTRA USER FUNCTIONS for functions ////
//// that are specific to only this HW peripheral that you may ////
//// find useful to use in your application. ////
//// ////
//// This driver lets you use endpoints 0 thru 15. Endpoint 0 is ////
//// the setup/control endpoint and is always anabled. ////
//// You can use any endpoint, but to save RAM it is recommended ////
//// that you use lower number endpoints and in order. For example, ////
//// use endpoints 1, 2 and 3 INSTEAD OF using endpoints 1, 8 ////
//// and 15. ////
//// ////
//// USB_MAX_EP0_PACKET_LENGTH will be set to 8 regardless ////
//// of USB speed, to save RAM. ////
//// ////
//// ************** NOTE ABOUT HW REQUIREMENTS **************** ////
//// If you are not using internal pullups, you will need to put ////
//// an internal pullup resistor on D+ or D+ depending on if you ////
//// want to use slow speed or full speed. This code configures ////
//// the device to use internal pullups, see usb_init() if you ////
//// want to change that. ////
//// ////
//// You need approximately 470nF cap on Vusb, even if you are ////
//// using the internal 3.3V USB regulator. ////
//// ////
//// To run at full speed, you must use the oscillator ////
//// configuration (PLLx) to set the PLL divide to 4MHz. You can ////
//// configure the MCU clock to any speed (up to 48MHz) but the ////
//// PLL must run at 4Mhz to provide the USB peripheral with a ////
//// 96MHz clock. See the datasheet for details. ////
//// ////
//// To run at slow speed you must configure your MCU to run at ////
//// 24Mhz. See the datasheet for details. ////
//// ////
//// **************** NOTE ABOUT INTERRUPTS ****************** ////
//// This driver uses INT_USB. It requires INT_USB to interrupt the ////
//// PIC when an event has happened on the USB Bus. Therfore ////
//// this code enables interrupts. A user modification can be made ////
//// to poll the USB interrupt flag instead of relying on an ////
//// interrupt. ////
//// ////
/////////////////////////////////////////////////////////////////////////
//// ////
//// Version History: ////
//// ////
//// Feb 15, 2013: ////
//// Enhanced PIC16 support added. ////
//// ////
/////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,2013 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. ////
/////////////////////////////////////////////////////////////////////////
#IFNDEF __PIC16F_USB_H__
#DEFINE __PIC16F_USB_H__
#DEFINE __USB_HARDWARE__
//let the USB Stack know that we are using a PIC with internal USB peripheral
#DEFINE __PIC__ 1
#ifndef USB_USE_FULL_SPEED
#define USB_USE_FULL_SPEED 1
#endif
#ifndef USB_MAX_EP0_PACKET_LENGTH
#define USB_MAX_EP0_PACKET_LENGTH 8
#endif
#if (!USB_USE_FULL_SPEED && (USB_MAX_EP0_PACKET_LENGTH!=8))
#error Slow speed devices must use a max packet size of 8 for endpoint 0!
#endif
#if USB_MAX_EP0_PACKET_LENGTH < 8
#error Max Endpoint 0 length can't be less than 8!
#endif
#if USB_MAX_EP0_PACKET_LENGTH > 64
#error Max Endpoint 0 length can't be greater than 64!
#endif
#include <usb_hw_layer.h>
//////////////////////// EXTRA USER FUNCTIONS /////////////////////////////////
/**************************************************************
/* usb_flush_in()
/*
/* Input: endpoint - which endpoint to mark for transfer
/* len - length of data that is being tramsferred
/* tgl - Data toggle synchronization for this packet
/*
/* Output: TRUE if success, FALSE if error (we don't control the endpoint)
/*
/* Summary: Marks the endpoint ready for transmission. You must
/* have already loaded the endpoint buffer with data.
/* (IN is PIC -> PC).
/* This routine is useful if you want to setup an endpoint by
/* writing to the buffer directly.
/* This routine is not necessary if you use usb_put_packet().
/***************************************************************/
int1 usb_flush_in(int8 endpoint, int16 len, USB_DTS_BIT tgl);
/**************************************************************
/* usb_flush_out()
/*
/* Input: endpoint - which endpoint to mark for release
/* tgl - Data toggle synchronization to expect in the next packet
/*
/* Output: NONE
/*
/* Summary: Clears the previously received packet, and then marks this
/* endpoint's receive buffer as ready for more data.
/* (OUT is PC -> PIC). This routine is useful if you do not
/* want to use usb_get_packet(), instead you want to handle with
/* the endpoint buffer directly. Also see usb_rx_packet_size().
/* This routine is not necessary if you use usb_get_packet().
/***************************************************************/
void usb_flush_out(int8 endpoint, USB_DTS_BIT tgl);
/**************************************************************
/* usb_rx_packet_size()
/*
/* Input: endpoint - which endpoint to mark to check
/*
/* Output: Returns the number of bytes in the endpoint's receive buffer.
/*
/* Summary: Read the number of data stored in the receive buffer. When you
/* have handled the data, use usb_flush_out() to clear the buffer. The
/* result may be invalid if usb_kbhit() returns false for this endpoint.
/* This routine is not necessary if you use usb_get_packet().
/***************************************************************/
int16 usb_rx_packet_size(int8 endpoint);
#ENDIF |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Sun Feb 05, 2023 8:29 am |
|
|
The USB example supports the PIC16 as well now, and shows this.
usb.c, now loads pic16f_usb.c once you have loaded the .h file:
Code: |
#if defined(__PIC16F_USB_H__)
#include <pic16f_usb.c>
#endif
|
This was all added in the very early V5 compilers (5.009 I think).
The clock statement shown by vtrx is wrong, you need:
Code: |
#use delay(int=8MHz, clock=48MHz, USB_FULL, act=USB)
#fuses NOMCLR,PUT,WDT_SW,NOPROTECT,NOBROWNOUT,NOWRT,STVREN
NOLPBOR,NOLVP
...
#include <pic16f_usb.h>
#include <usb_desc_hid 8_byte.h> //USB Configuration and Device descriptors for this UBS device
#include "usb.c" //handles usb setup tokens and get descriptor reports
|
(Also don't enable protect fuses during development - doing so wastes
flash memory lives). I've changed this.
The key point is that if running off the internal oscillator, the clock has to be
told to use it's sync to the USB clock mode, otherwise it won't be accurate
enough for USB to work correctly.
Understand the example uses the 1459, not the 55, but the USB is
identical. The 55, just has less pins. Change all references to 59 to 55
in the example, and it'll run 'as is'. |
|
|
djsb
Joined: 29 Jan 2011 Posts: 41
|
|
Posted: Tue Feb 07, 2023 4:08 am |
|
|
What driver is needed on the PC end to be able to use the PIC16F1459 for example? Is the driver required a Microchip supplied version or a driver included in Windows software? Any enumeration or licensing issues to be aware of?
I'd like to experiment with this chip, as I would not have to buy the CCS PCH compiler for the 18F series. Also, the PIC16F1459 is closely related to the MCP2221A? I wonder if the same microchip provided utilities software can be used on both chips?
Has anyone come across any practical limits regarding code space in particular, or any other caveats? Thanks. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Tue Feb 07, 2023 4:11 am |
|
|
The driver for CDC is in the examples folder of the compiler.
Sub directory 'USB CDC Drivers'.
HID, can normally use the internal Windows HID driver (assuming this is
a 'standard' HID device - keyboard, mouse etc.). |
|
|
vtrx
Joined: 11 Oct 2017 Posts: 142
|
|
Posted: Tue Feb 07, 2023 3:48 pm |
|
|
I've been programming in Delphi for many years to use native USB (HID).
A simple .exe controls the microcontroller and exchanges data between the PC and the microcontroller.
The 16F1455 microcontroller is small enough to be used as an infrared receiver connected to a USB port where I intend to control a wireless Joystick. |
|
|
|
|
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
|