00001 /********************************************************************* 00002 * 00003 * Microchip USB C18 Firmware Version 1.0 00004 * 00005 ********************************************************************* 00006 * FileName: main.c 00007 * Dependencies: See INCLUDES section below 00008 * Processor: PIC18 00009 * Compiler: C18 2.30.01+ 00010 * Company: Microchip Technology, Inc. 00011 * 00012 * Software License Agreement 00013 * 00014 * The software supplied herewith by Microchip Technology Incorporated 00015 * (the “Company”) for its PICmicro® Microcontroller is intended and 00016 * supplied to you, the Company’s customer, for use solely and 00017 * exclusively on Microchip PICmicro Microcontroller products. The 00018 * software is owned by the Company and/or its supplier, and is 00019 * protected under applicable copyright laws. All rights are reserved. 00020 * Any use in violation of the foregoing restrictions may subject the 00021 * user to criminal sanctions under applicable laws, as well as to 00022 * civil liability for the breach of the terms and conditions of this 00023 * license. 00024 * 00025 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES, 00026 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED 00027 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00028 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, 00029 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR 00030 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. 00031 * 00032 * Author Date Comment 00033 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00034 * Rawin Rojvanit 11/19/04 Original. 00035 ********************************************************************/ 00036 00037 /** I N C L U D E S **********************************************************/ 00038 #include <p18cxxx.h> 00039 #include "system\typedefs.h" // Required 00040 #include "system\usb\usb.h" // Required 00041 #include "io_cfg.h" // Required 00042 00043 #include "system\usb\usb_compile_time_validation.h" // Optional 00044 #include "user\user.h" // Modifiable 00045 00046 /** V A R I A B L E S ********************************************************/ 00047 #pragma udata 00048 00049 /** P R I V A T E P R O T O T Y P E S ***************************************/ 00050 static void InitializeSystem(void); 00051 void USBTasks(void); 00052 00053 /** V E C T O R R E M A P P I N G *******************************************/ 00054 00055 //extern void _startup (void); // See c018i.c in your C18 compiler dir 00056 //#pragma code _RESET_INTERRUPT_VECTOR = 0x000800 00057 //void _reset (void) 00058 //{ 00059 // _asm goto _startup _endasm 00060 //} 00061 //#pragma code 00062 00063 /** D E C L A R A T I O N S **************************************************/ 00064 #pragma code 00065 /****************************************************************************** 00066 * Function: void main(void) 00067 * 00068 * PreCondition: None 00069 * 00070 * Input: None 00071 * 00072 * Output: None 00073 * 00074 * Side Effects: None 00075 * 00076 * Overview: Main program entry point. 00077 * 00078 * Note: None 00079 *****************************************************************************/ 00080 void main(void) 00081 { 00082 InitializeSystem(); 00083 while(1) 00084 { 00085 USBTasks(); // USB Tasks 00086 ProcessIO(); // See user\user.c & .h 00087 }//end while 00088 }//end main 00089 00090 /****************************************************************************** 00091 * Function: static void InitializeSystem(void) 00092 * 00093 * PreCondition: None 00094 * 00095 * Input: None 00096 * 00097 * Output: None 00098 * 00099 * Side Effects: None 00100 * 00101 * Overview: InitializeSystem is a centralize initialization routine. 00102 * All required USB initialization routines are called from 00103 * here. 00104 * 00105 * User application initialization routine should also be 00106 * called from here. 00107 * 00108 * Note: None 00109 *****************************************************************************/ 00110 static void InitializeSystem(void) 00111 { 00112 ADCON1 |= 0x0F; // Default all pins to digital 00113 00114 #if defined(USE_USB_BUS_SENSE_IO) 00115 tris_usb_bus_sense = INPUT_PIN; // See io_cfg.h 00116 #endif 00117 00118 #if defined(USE_SELF_POWER_SENSE_IO) 00119 tris_self_power = INPUT_PIN; 00120 #endif 00121 00122 mInitializeUSBDriver(); // See usbdrv.h 00123 00124 UserInit(); // See user.c & .h 00125 00126 }//end InitializeSystem 00127 00128 /****************************************************************************** 00129 * Function: void USBTasks(void) 00130 * 00131 * PreCondition: InitializeSystem has been called. 00132 * 00133 * Input: None 00134 * 00135 * Output: None 00136 * 00137 * Side Effects: None 00138 * 00139 * Overview: Service loop for USB tasks. 00140 * 00141 * Note: None 00142 *****************************************************************************/ 00143 void USBTasks(void) 00144 { 00145 /* 00146 * Servicing Hardware 00147 */ 00148 USBCheckBusStatus(); // Must use polling method 00149 if(UCFGbits.UTEYE!=1) 00150 USBDriverService(); // Interrupt or polling method 00151 00152 #if defined(USB_USE_CDC) 00153 CDCTxService(); 00154 #endif 00155 00156 }// end USBTasks 00157 00158 /** EOF main.c ***************************************************************/