void UserInit(void) { //Initialize all of the LED pins mInitAllLEDs(); //Initialize the pushbuttons mInitAllSwitches(); }
/****************************************************************************** * Function: void UserInit(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This routine should take care of all of the demo code * initialization that is required. * * Note: * *****************************************************************************/ void UserInit(void) { //Initialize all of the LED pins mInitAllLEDs(); //Initialize all of the push buttons mInitAllSwitches(); old_sw2 = sw2; old_sw3 = sw3; PORTBbits.RB4 = 0; //Clear RB4 to a known value ANSELHbits.ANS10 = 1; //make RB4 an analog I/O TRISBbits.TRISB4 = 1; //set RB4 as an input //Configure ADC as follows // Use AN10 or RB4 as the variable input // clear GODONE and turn on ADC module //ADCON0=0x29; //ADCON1 = 0X00; //use VDD and VSS as references //ADCON2=0x3F; // left justified, 20Tad, Fosc/4 //initialize the variable holding the handle for the last // transmission lastTransmission = 0; }//end UserInit
void UserInit(void) { mInitAllLEDs(); mInitAllSwitches(); InitAdc(); old_sw2 = sw2; Pump1tris = 0; Pump2tris = 0; TRISVPP = 0; //output TRISVPP_RST=0; //output TRISPGD=0; TRISPGC=0; TRISVDD=0; TRISVPP_RUN=0; VPP_RUN=0; //run = off PGD_LOW=1; TRISPGD_LOW=1; //LV devices disabled, high impedance / input PGC_LOW=1; TRISPGC_LOW=1; //LV devices disabled, high impedance / input VPP = 1; //VPP is low (inverted) VPP_RST=0; //No hard reset (inverted PGD=0; PGC=0; INTCON2bits.RBPU=1; //disable Portb pullup resistors timer1Init(); timer0Init(); }//end UserInit
void UserInit(void) { mInitAllLEDs(); mInitAllSwitches(); blinkStatusValid = TRUE; //Blink the normal USB state on the LEDs. // Enable Channel 0 and Channel 1 for ADC // Disable A/D first. ADCON0bits.ADON = 0; // Select channel as per user request. But default to AD0 ADCON0 &= (0xF0); ADCON1bits.VCFG1 = 0; // Vss for Vref- ADCON1bits.VCFG0 = 0; // Vdd for Vref+ // AN0 and AN1 are analog pins ADCON1bits.PCFG0 = 1; ADCON1bits.PCFG1 = 0; ADCON1bits.PCFG2 = 1; ADCON1bits.PCFG3 = 1; // A/D is little endian ADCON2bits.ADFM = 1; // Set aquisition time of 2 cycles. ADCON2bits.ACQT0 = 1; ADCON2bits.ACQT1 = 0; ADCON2bits.ACQT2 = 0; // Set conversion time of 64 clock cycles ADCON2bits.ADCS0 = 0; ADCON2bits.ADCS1 = 1; ADCON2bits.ADCS2 = 1; // Make RA0 and RA1 as input. TRISAbits.TRISA0 = 1; TRISAbits.TRISA1 = 1; }//end UserInit
/****************************************************************************** * Function: void UserInit(void) * * Overview: This routine should take care of all of the demo code * initialization that is required. *****************************************************************************/ void UserInit(void) { unsigned char i; { unsigned char i; for (i=0; i<CDC_DATA_IN_EP_SIZE; i++) { USB_In_Buffer[i] = 0; USB_Out_Buffer[i] = 0; } } // RA8 == front/back sensor // config as input TRISAbits.TRISA8 = 1; // pull up on CNPUAbits.CNPUA8 = 1; // RB8 == shake sensor // config as input TRISBbits.TRISB8 = 1; // pull up off CNPUBbits.CNPUB8 = 0; mInitAllLEDs(); }//end UserInit
/*************************************************** * Function: InitializeDevice(void) * * OverView: Initialize Device Port, LED, Switches, ADC, PWM, TIMER, ETC.. * * Note: None ***************************************************/ void InitializeDevice(void) { //Initialize all of the LED pins mInitAllLEDs(); LED_INIT(); //Initialize all of the push buttons mInitAllSwitches(); //initialize adc for ntc sensor InitADC(); //initialize lid heater InitHeater(); //initialize fan Init_ChamberFan(); Init_SystemFan(); //initialize pwm Stop_PWM_MODE(); //initialize fan & heater control with timer0 TIMR0_init(); //pcr task tick TIMR1_init(); }
void UserInit(void) { mInitAllLEDs(); mInitSwitch(); blinkStatusValid = TRUE; //Blink the normal USB state on the LEDs. }//end UserInit
/****************************************************************************** * Function: static void InitializeSystem(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: InitializeSystem is a centralize initialization routine. * All required USB initialization routines are called from * here. * * User application initialization routine should also be * called from here. * * Note: None *****************************************************************************/ static void InitializeSystem(void) { // The USB specifications require that USB peripheral devices must never source // current onto the Vbus pin. Additionally, USB peripherals should not source // current on D+ or D- when the host/hub is not actively powering the Vbus line. // When designing a self powered (as opposed to bus powered) USB peripheral // device, the firmware should make sure not to turn on the USB module and D+ // or D- pull up resistor unless Vbus is actively powered. Therefore, the // firmware needs some means to detect when Vbus is being powered by the host. // A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and // can be used to detect when Vbus is high (host actively powering), or low // (host is shut down or otherwise not supplying power). The USB firmware // can then periodically poll this I/O pin to know when it is okay to turn on // the USB module/D+/D- pull up resistor. When designing a purely bus powered // peripheral device, it is not possible to source current on D+ or D- when the // host is not actively providing power on Vbus. Therefore, implementing this // bus sense feature is optional. This firmware can be made to use this bus // sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the // usbcfg.h file. #if defined(USE_USB_BUS_SENSE_IO) tris_usb_bus_sense = INPUT_PIN; // See io_cfg.h #endif // If the host PC sends a GetStatus (device) request, the firmware must respond // and let the host know if the USB peripheral device is currently bus powered // or self powered. See chapter 9 in the official USB specifications for details // regarding this request. If the peripheral device is capable of being both // self and bus powered, it should not return a hard coded value for this request. // Instead, firmware should check if it is currently self or bus powered, and // respond accordingly. If the hardware has been configured like demonstrated // on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the // currently selected power source. On the PICDEM FS USB Demo Board, "RA2" // is used for this purpose. If using this feature, make sure "USE_SELF_POWER_SENSE_IO" // has been defined in usbcfg.h, and that an appropriate I/O pin has been mapped // to it in io_cfg.h. #if defined(USE_SELF_POWER_SENSE_IO) tris_self_power = INPUT_PIN; #endif //Initialize oscillator settings compatible with USB operation. Note, //these may be application specific! #if defined(PIC18F4550_PICDEM_FS_USB_K50) OSCTUNE = 0x80; //3X PLL ratio mode selected OSCCON = 0x70; //Switch to 16MHz HFINTOSC OSCCON2 = 0x10; //Enable PLL, SOSC, PRI OSC drivers turned off while(OSCCON2bits.PLLRDY != 1); //Wait for PLL lock ACTCON = 0x90; //Enable active clock tuning for USB operation //*((unsigned char*)0xFB5) = 0x90; //Enable active clock tuning for USB operation #endif mInitializeUSBDriver(); // See usbdrv.h UserInit(); // See user.c & .h mInitAllLEDs(); //Init them off. }//end InitializeSystem
void FraiseInit(void) { /*FrTXin=0; FrTXout=0; FrTXfree=255;*/ FrGotLineFromUsb=0; LineFromUsbLen=0; FraiseStatus.VAL=0; FraiseState=fIDLE; FraiseMessage=fmessNONE; FrRXin=0; FrRXout=0; PollDelay=0; //OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 103); // 48 MHz/4/115200 = 104 BAUDCON = 0x08; // BRG16 = 1 OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_NINE_BIT & USART_CONT_RX & USART_BRGH_HIGH & USART_ADDEN_OFF, 47); // 48 MHz/4/250000 = 48 USART_Status.TX_NINE=1; // Initialize Timer2 // The prescaler will be at 16 T2CONbits.T2CKPS1 = 1; T2CONbits.T2CKPS0 = 1; // We want no TMR2 post scaler T2CONbits.T2OUTPS3 = 0; T2CONbits.T2OUTPS2 = 0; T2CONbits.T2OUTPS1 = 0; T2CONbits.T2OUTPS0 = 0; // Set our reload value //PR2 = kPR2_RELOAD; PR2 = 255; T2CONbits.TMR2ON = 1; // Initalize switchs and leds mInitAllLEDs(); mInitSwitch(); mInitSerDrv(); //Serial_Init_Receiver(); Serial_Init_Driver(); for(i=0;i<16;i++) { Children[i]=0; ChildrenOK[i]=0; } MaxPolledChild=4; _PolledChild=1;_bit_PolledChild =2; // Set interrupt priorities PIE1bits.TMR2IE = 0; IPR1bits.TMR2IP = 1; IPR1bits.TXIP = 1; IPR1bits.RCIP = 1; INTCONbits.GIEH = 1; }
/******************************************************************** * Arduino風: 初期化処理 ******************************************************************** */ static inline void setup() { DDPCONbits.JTAGEN=0; // PORTA is used as digital instead of JTAG io_setDigital(); // Analog から Digital I/Oに切り替えます. io_setRemap(); // RA4/RB4 をUARTに割り当てます. mInitAllLEDs(); kbd_init(); // : 初期化 NTSC_init(); // NTSC 表示初期化. // UART1 初期化 (NTSC_initのあと) SerialConfigure(UART1, UART_ENABLE, UART_RX_TX_ENABLED, BAUDRATE); Eint(); // 割り込み許可. gr_test(); // グラフィックテスト. }
/******************************************************************** * 初期化. ******************************************************************** */ void UserInit(void) { mInitAllLEDs(); timer2_interval(5); // '-d5' poll_mode = 0; poll_addr = 0; // puts_ptr = 0; ToPcRdy = 0; #if TIMER2_INT_SAMPLE // タイマー2割り込みでPORTサンプル. poll_wptr=0; poll_rptr=0; #endif }
/****************************************************************************** * Function: void UserInit(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This routine should take care of all of the demo code * initialization that is required. * * Note: * *****************************************************************************/ void UserInit(void) { unsigned char i; // Initialize the arrays for (i=0; i<sizeof(USB_Out_Buffer); i++) { USB_Out_Buffer[i] = 0; } NextUSBOut = 0; lastTransmission = 0; mInitAllLEDs(); clrtgtprg(); }//end UserInit
void UserInit(void) { mInitConversion(); // Initialise all the conversion values required for ISR maths mInitAllSwitches(); // Initislise the switches in accordance to the hardware profile mInitEEPROM(); // Read in any saved values from EEPROM mInitAllLEDs(); // Initialise the LEDs in acordance to the hardware profile mLCD_power_init(); // initialise the LCD backlight mInitDAQ(); // Initialise the Data Acquisition parameters (AN inputs etc) if (debug==FALSE) { mInitLCD(); // Must comment this out when testing as LCD will never initialise... } mInitSPI(); // Initialise the SPI interface for talking to the LED driver (must be after the LCD) mInitInterrupts(); // Initialise the interrupts/timers etc if(backlight_flag==TRUE) { LCD_ramp_up=TRUE; // turn on the LCD back light } }//end UserInit
void UserInit(void) { mInitAllLEDs(); mInitAllSwitches(); old_sw2 = sw2; old_sw3 = sw3; InitTempSensor(); mInitPOT(); ResetTempLog(); temp_mode = TEMP_REAL_TIME; #if defined(__18CXX) /* Init Timer0 for data logging interval (every 1 second) */ T0CON = 0b10010111; /* Timer0 is already enabled by default */ #elif defined(__C30__) || defined __XC16__ #endif }//end UserInit
void UserInit(void) { //usart unsigned char c; //ANSELHbits.ANS11 = 0; // Make RB5 digital so USART can use pin for Rx UART_TRISRx=1; // RX UART_TRISTx=1; // TX TXSTA = 0b00100000; // TX enable BRGH=1 RCSTA = 0b10110000;// 0x90; // Single Character RX SPBRG = 38; SPBRGH = 0; // 259 for 48MHz -> 19200 baud BAUDCON = 0; // BRG16 = 0 c = RCREG; // read mInitAllLEDs(); mInitSwitch(); blinkStatusValid = TRUE; //Blink the normal USB state on the LEDs. }//end UserInit
/****************************************************************************** * Function: void UserInit(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This routine should take care of all of the demo code * initialization that is required. * * Note: * *****************************************************************************/ void UserInit(void) { //Initialize all of the debouncing variables buttonCount = 0; buttonPressed = FALSE; stringPrinted = TRUE; //Initialize all of the LED pins mInitAllLEDs(); //Initialize the pushbuttons mInitAllSwitches(); // Initialize UART InitializeUSART(); // Disable all unused peripherals DisablePeripherals(); // Sleep until UART interrupt }//end UserInit
/****************************************************************************** * Function: void UserInit(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: This routine should take care of all of the demo code * initialization that is required. * * Note: * *****************************************************************************/ void UserInit(void) { //Initialize all of the LED pins mInitAllLEDs(); //Initialize all of the push buttons mInitAllSwitches(); old_sw2 = sw2; old_sw3 = sw3; //Initialize all of the mouse data to 0,0,0 (no movement) buffer[0]=buffer[1]=buffer[2]=0; //enable emulation mode. This means that the mouse data //will be send to the PC causing the mouse to move. If this is //set to FALSE then the demo board will send 0,0,0 resulting //in no mouse movement emulate_mode = TRUE; //initialize the variable holding the handle for the last // transmission lastTransmission = 0; }//end UserInit
void InitializeSystem(void) { ADCON1 |= 0x0F; // Default all pins to digital INTCON2 = 0; mInitAllLEDs(); mInitAllSwitches(); g_blink_status_valid = TRUE; g_usb_handle_in = 0; g_usb_handle_out = 0; // Reset TX queue and read config from the EEPROM. memset(g_tx_queue, 0, sizeof(g_tx_queue)); EEADR = 0; EECON1bits.EEPGD = 0; EECON1bits.CFGS = 0; EECON1bits.RD = 1; g_lgtm_strings_idx = EEDATA; if (g_lgtm_strings_idx >= NUM_LGTM_STRINGS) g_lgtm_strings_idx = 0; g_lgtm_ascii_ptr = LGTM_STRINGS[g_lgtm_strings_idx]; USBDeviceInit(); // usb_device.c. Initializes USB module SFRs and firmware // variables to known states. }
/****************************************************************************** * Function: static void InitializeSystem(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: InitializeSystem is a centralize initialization routine. * All required USB initialization routines are called from * here. * * User application initialization routine should also be * called from here. * * Note: None *****************************************************************************/ static void InitializeSystem(void) { OSCCON = 0x60; //Clock switch to primary clock source. May not have been running //from this if the bootloader is called from the application firmware. //On the PIC18F46J50 Family of USB microcontrollers, the PLL will not power up and be enabled //by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL). //This allows the device to power up at a lower initial operating frequency, which can be //advantageous when powered from a source which is not gauranteed to be adequate for 48MHz //operation. On these devices, user firmware needs to manually set the OSCTUNE<PLLEN> bit to //power up the PLL. #if defined(__18F24J50)||defined(__18F25J50)|| \ defined(__18F26J50)||defined(__18F44J50)|| \ defined(__18F45J50)||defined(__18F46J50)|| \ defined(__18LF24J50)||defined(__18LF44J50)|| \ defined(__18LF25J50)||defined(__18LF45J50)|| \ defined(__18LF26J50)||defined(__18LF46J50) OSCTUNEbits.PLLEN = 1; //Enable the PLL and wait 2+ms until the PLL locks before enabling USB module uint_delay_counter = 600; while(uint_delay_counter--); //Device switches over automatically to PLL output after PLL is locked and ready. #else #error Double Click this message. Please make sure the InitializeSystem() function correctly configures your hardware platform. //Also make sure the correct board is selected in usbcfg.h. If //everything is correct, comment out the above "#error ..." line //to suppress the error message. #endif // The USB specifications require that USB peripheral devices must never source // current onto the Vbus pin. Additionally, USB peripherals should not source // current on D+ or D- when the host/hub is not actively powering the Vbus line. // When designing a self powered (as opposed to bus powered) USB peripheral // device, the firmware should make sure not to turn on the USB module and D+ // or D- pull up resistor unless Vbus is actively powered. Therefore, the // firmware needs some means to detect when Vbus is being powered by the host. // A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and // can be used to detect when Vbus is high (host actively powering), or low // (host is shut down or otherwise not supplying power). The USB firmware // can then periodically poll this I/O pin to know when it is okay to turn on // the USB module/D+/D- pull up resistor. When designing a purely bus powered // peripheral device, it is not possible to source current on D+ or D- when the // host is not actively providing power on Vbus. Therefore, implementing this // bus sense feature is optional. This firmware can be made to use this bus // sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the // usbcfg.h file. #if defined(USE_USB_BUS_SENSE_IO) tris_usb_bus_sense = INPUT_PIN; // See io_cfg.h #endif // If the host PC sends a GetStatus (device) request, the firmware must respond // and let the host know if the USB peripheral device is currently bus powered // or self powered. See chapter 9 in the official USB specifications for details // regarding this request. If the peripheral device is capable of being both // self and bus powered, it should not return a hard coded value for this request. // Instead, firmware should check if it is currently self or bus powered, and // respond accordingly. If the hardware has been configured like demonstrated // on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the // currently selected power source. On the PICDEM FS USB Demo Board, "RA2" // is used for this purpose. If using this feature, make sure "USE_SELF_POWER_SENSE_IO" // has been defined in usbcfg.h, and that an appropriate I/O pin has been mapped // to it in io_cfg.h. #if defined(USE_SELF_POWER_SENSE_IO) tris_self_power = INPUT_PIN; #endif mInitializeUSBDriver(); // See usbdrv.h UserInit(); // See BootPIC[xxxx].c. Initializes the bootloader firmware state machine variables. mInitAllLEDs(); //Init them off. //Initialize I/O pins for "lowest" power. When in USB suspend mode, total +5V VBUS current consumption //should reduce to <2.5mA in order to meet USB compliance specifications. //Ordinarily, to initialize I/O pins for lowest power, any unused I/O pins would be configured //as outputs and driven either high or low. However, if this code is left unmodified, but is used in a real //application, I/O pins as outputs could cause contention with externally connected signals. Therefore //this code does not actually drive unused I/Os as outputs, but uses "softer" methods, like making //analog capable pins as analog (to disable the digital input buffer, which wastes power when left floating) //This code should be replaced with code more specific to the intended target application I/O pin usage. //The below code by itself will not achieve the lowest possible power consumption. ANCON0 = 0x00; //All analog, to disable the digital input buffers ANCON1 = 0x00; //All analog, digital input buffers off, bandgap off }//end InitializeSystem
/****************************************************************************** * Function: static void InitializeSystem(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: InitializeSystem is a centralize initialization routine. * All required USB initialization routines are called from * here. * * User application initialization routine should also be * called from here. * * Note: None *****************************************************************************/ static void InitializeSystem(void) { #if defined(PIC18F97J94_FS_USB_PIM) || defined(PIC18F87J94_FS_USB_PIM) //Make sure to select oscillator settings consistent with USB operation. //If the user application firmware entered the bootloader through the absolute //entry point, it is possible the clock source may not have already been compatible //with USB operation. In this case we need to switch as appropriate. OSCCON2bits.CLKLOCK = 0; //Deassert clock setting lock OSCCON3 = 0x01; //FRC/2 setting (4MHz) OSCCON4 = 0x00; //1:1 OSCCON = 0x01; //FRC+PLL selected //Enable INTOSC active clock tuning if full speed ACTCON = 0x90; //Enable active clock self tuning for USB operation while(OSCCON2bits.LOCK == 0) //Make sure PLL is locked/frequency is compatible { ClrWdt(); } #else #error Double Click this message. Please make sure the InitializeSystem() function correctly configures your hardware platform. //Also make sure the correct board is selected in usbcfg.h. If //everything is correct, comment out the above "#error ..." line //to suppress the error message. #endif //USB module may have already been on if the application firmware calls the bootloader //without first disabling the USB module. If this happens, need //to temporarily soft-detach from the host, wait a delay (allows cable capacitance //to discharge, and to allow host software to recognize detach), then //re-enable the USB module, so the host knows to re-enumerate the //USB device. if(UCONbits.USBEN == 1) { UCONbits.SUSPND = 0; UCON = 0; LongDelay(); } // The USB specifications require that USB peripheral devices must never source // current onto the Vbus pin. Additionally, USB peripherals should not source // current on D+ or D- when the host/hub is not actively powering the Vbus line. // When designing a self powered (as opposed to bus powered) USB peripheral // device, the firmware should make sure not to turn on the USB module and D+ // or D- pull up resistor unless Vbus is actively powered. Therefore, the // firmware needs some means to detect when Vbus is being powered by the host. // A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and // can be used to detect when Vbus is high (host actively powering), or low // (host is shut down or otherwise not supplying power). The USB firmware // can then periodically poll this I/O pin to know when it is okay to turn on // the USB module/D+/D- pull up resistor. When designing a purely bus powered // peripheral device, it is not possible to source current on D+ or D- when the // host is not actively providing power on Vbus. Therefore, implementing this // bus sense feature is optional. This firmware can be made to use this bus // sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the // usbcfg.h file. #if defined(USE_USB_BUS_SENSE_IO) tris_usb_bus_sense = INPUT_PIN; // See io_cfg.h #endif // If the host PC sends a GetStatus (device) request, the firmware must respond // and let the host know if the USB peripheral device is currently bus powered // or self powered. See chapter 9 in the official USB specifications for details // regarding this request. If the peripheral device is capable of being both // self and bus powered, it should not return a hard coded value for this request. // Instead, firmware should check if it is currently self or bus powered, and // respond accordingly. If the hardware has been configured like demonstrated // on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the // currently selected power source. On the PICDEM FS USB Demo Board, "RA2" // is used for this purpose. If using this feature, make sure "USE_SELF_POWER_SENSE_IO" // has been defined in usbcfg.h, and that an appropriate I/O pin has been mapped // to it in io_cfg.h. #if defined(USE_SELF_POWER_SENSE_IO) tris_self_power = INPUT_PIN; #endif mInitializeUSBDriver(); // See usbdrv.h UserInit(); // See user.c & .h led_count = 0; //Initialize variable used to toggle LEDs mInitAllLEDs(); //Init them off. //Turn off digital input buffers on analog pins to minimize power consumption //if the I/O pins happen to be floating in the target application. ANCON1 = 0xFF; //All analog, digital input buffers off ANCON2 = 0xFF; //All analog, digital input buffers off ANCON3 = 0xFF; //All analog, digital input buffers off }//end InitializeSystem
/****************************************************************************** * Function: static void InitializeSystem(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: InitializeSystem is a centralize initialization routine. * All required USB initialization routines are called from * here. * * User application initialization routine should also be * called from here. * * Note: None *****************************************************************************/ static void InitializeSystem(void) { OSCCON = 0x60; //Clock switch to primary clock source. May not have been running //from this if the bootloader is called from the application firmware. //On the PIC18F87J50 Family of USB microcontrollers, the PLL will not power up and be enabled //by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL). //This allows the device to power up at a lower initial operating frequency, which can be //advantageous when powered from a source which is not gauranteed to be adequate for 48MHz //operation. On these devices, user firmware needs to manually set the OSCTUNE<PLLEN> bit to //power up the PLL. #if defined(__18F87J50)||defined(__18F86J55)|| \ defined(__18F86J50)||defined(__18F85J50)|| \ defined(__18F67J50)||defined(__18F66J55)|| \ defined(__18F66J50)||defined(__18F65J50) OSCTUNEbits.PLLEN = 1; //Enable the PLL and wait 2+ms until the PLL locks before enabling USB module pll_startup_counter = 600; while(pll_startup_counter--) { ClrWdt(); } //Device switches over automatically to PLL output after PLL is locked and ready. #else #error Double Click this message. Please make sure the InitializeSystem() function correctly configures your hardware platform. //Also make sure the correct board is selected in usbcfg.h. If //everything is correct, comment out the above "#error ..." line //to suppress the error message. #endif //USB module may have already been on if the application firmware calls the bootloader //without first disabling the USB module. If this happens, need //to temporarily soft-detach from the host, wait a delay (allows cable capacitance //to discharge, and to allow host software to recognize detach), then //re-enable the USB module, so the host knows to re-enumerate the //USB device. if(UCONbits.USBEN == 1) { UCONbits.SUSPND = 0; UCON = 0; LongDelay(); } // The USB specifications require that USB peripheral devices must never source // current onto the Vbus pin. Additionally, USB peripherals should not source // current on D+ or D- when the host/hub is not actively powering the Vbus line. // When designing a self powered (as opposed to bus powered) USB peripheral // device, the firmware should make sure not to turn on the USB module and D+ // or D- pull up resistor unless Vbus is actively powered. Therefore, the // firmware needs some means to detect when Vbus is being powered by the host. // A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and // can be used to detect when Vbus is high (host actively powering), or low // (host is shut down or otherwise not supplying power). The USB firmware // can then periodically poll this I/O pin to know when it is okay to turn on // the USB module/D+/D- pull up resistor. When designing a purely bus powered // peripheral device, it is not possible to source current on D+ or D- when the // host is not actively providing power on Vbus. Therefore, implementing this // bus sense feature is optional. This firmware can be made to use this bus // sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the // usbcfg.h file. #if defined(USE_USB_BUS_SENSE_IO) tris_usb_bus_sense = INPUT_PIN; // See io_cfg.h #endif // If the host PC sends a GetStatus (device) request, the firmware must respond // and let the host know if the USB peripheral device is currently bus powered // or self powered. See chapter 9 in the official USB specifications for details // regarding this request. If the peripheral device is capable of being both // self and bus powered, it should not return a hard coded value for this request. // Instead, firmware should check if it is currently self or bus powered, and // respond accordingly. If the hardware has been configured like demonstrated // on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the // currently selected power source. On the PICDEM FS USB Demo Board, "RA2" // is used for this purpose. If using this feature, make sure "USE_SELF_POWER_SENSE_IO" // has been defined in usbcfg.h, and that an appropriate I/O pin has been mapped // to it in io_cfg.h. #if defined(USE_SELF_POWER_SENSE_IO) tris_self_power = INPUT_PIN; #endif mInitializeUSBDriver(); // See usbdrv.h UserInit(); // See user.c & .h led_count = 0; //Initialize variable used to toggle LEDs mInitAllLEDs(); //Init them off. //Turn off digital input buffers on analog pins to minimize power consumption //if the I/O pins happen to be floating in the target application. WDTCONbits.ADSHR = 1; //ANCON registers in shared address space region ANCON0 = 0x00; //All analog, to disable the digital input buffers ANCON1 = 0x00; //All analog, digital input buffers off WDTCONbits.ADSHR = 0; //Also to minimize sleep current consumption (sleep used in this bootloader //firmware during USB Suspend conditions), use REGSLP feature WDTCONbits.REGSLP = 1; }//end InitializeSystem
void BLIO_InitializeIO ( void ) { mInitAllSwitches(); mInitAllLEDs(); }
void InitApp(void) { /* Send Low Level Voltage to all ports */ LATA = 0x0000; LATB = 0x0000; LATC = 0x0000; LATD = 0x0000; LATE = 0x0000; LATF = 0x0000; LATG = 0x0000; #if defined(__dsPIC33EP512MU814__) LATH = 0x0000; LATJ = 0x0000; LATK = 0x0000; #endif /* Disable all analog inputs */ ANSELA = 0x0000; ANSELB = 0x0000; ANSELC = 0x0000; ANSELD = 0x0000; ANSELE = 0x0000; ANSELG = 0x0000; /* Configure all digital ports as outputs */ TRISA = 0x0000; TRISB = 0x0000; TRISC = 0x0000; TRISD = 0x0000; TRISE = 0x0000; TRISF = 0x0000; TRISG = 0x0000; #if defined(__dsPIC33EP512MU814__) TRISH = 0x0000; TRISJ = 0x0000; TRISK = 0x0000; #endif #if STARTKITBOARD mInitAllLEDs(); mInitAllSwitches(); #endif /* Configure Nested Interrupts */ INTCON1bits.NSTDIS = 0b0; // Interrupt nesting enabled initClock(); #if USE_UART1 serial_assign(&Serial1, 1u); Serial1.init(); Serial1.open(); XBeeInit(&Xbee1, XBEE1_ATAP, &Serial1); #endif /*USE_UART1*/ #if USE_UART2 serial_assign(&Serial2, 2u); Serial2.init(); Serial2.open(); XBeeInit(&Xbee2, XBEE2_ATAP, &Serial2); #endif /*USE_UART2*/ #if USE_UART3 serial_assign(&Serial3, 3u); Serial3.init(); Serial3.open(); XBeeInit(&Xbee3, XBEE3_ATAP, &Serial3); #endif /*USE_UART3*/ #if USE_UART4 serial_assign(&Serial4, 4u); Serial4.init(); Serial4.open(); XBeeInit(&Xbee4, XBEE4_ATAP, &Serial4); #endif /*USE_UART4*/ #if USE_ADC1 ADC1Init(); ADC1Start(); #endif #if USE_ENC EncInit(); #endif #if USE_PWM PWMxInit(); PWMxStart(); #endif #if USE_PWM && USE_ADC1 ServoInit(); asm ("repeat #640;"); Nop(); ServoStart(); #endif /* USE_PWM && USE_ADC1 */ #if USE_IMU IMUInit(); IMUStart(); #endif #if USE_SPIS SPISInit(); SPISStart(); #endif }
BOOL InitializeSystem ( void ) { #if defined(__dsPIC33EP512MU810__)||defined(__PIC24EP512GU810__) // Configure the device PLL to obtain 60 MIPS operation. The crystal // frequency is 8MHz. Divide 8MHz by 2, multiply by 60 and divide by // 2. This results in Fosc of 120MHz. The CPU clock frequency is // Fcy = Fosc/2 = 60MHz. Wait for the Primary PLL to lock and then // configure the auxilliary PLL to provide 48MHz needed for USB // Operation. PLLFBD = 38; /* M = 60 */ CLKDIVbits.PLLPOST = 0; /* N1 = 2 */ CLKDIVbits.PLLPRE = 0; /* N2 = 2 */ OSCTUN = 0; /* Initiate Clock Switch to Primary * Oscillator with PLL (NOSC= 0x3)*/ __builtin_write_OSCCONH(0x03); __builtin_write_OSCCONL(0x01); while (OSCCONbits.COSC != 0x3); // Configuring the auxiliary PLL, since the primary // oscillator provides the source clock to the auxiliary // PLL, the auxiliary oscillator is disabled. Note that // the AUX PLL is enabled. The input 8MHz clock is divided // by 2, multiplied by 24 and then divided by 2. Wait till // the AUX PLL locks. ACLKCON3 = 0x24C1; ACLKDIV3 = 0x7; ACLKCON3bits.ENAPLL = 1; while(ACLKCON3bits.APLLCK != 1); ANSELA = 0x0000; ANSELB = 0x0000; ANSELC = 0x0000; ANSELD = 0x0000; ANSELE = 0x0000; ANSELG = 0x0000; // The dsPIC33EP512MU810 features Peripheral Pin // select. The following statements map UART2 to // device pins which would connect to the the // RX232 transciever on the Explorer 16 board. RPINR19 = 0; RPINR19 = 0x64; RPOR9bits.RP101R = 0x3; #endif #if defined( __PIC24FJ256GB110__ ) // Configure U2RX - put on pin 49 (RP10) RPINR19bits.U2RXR = 10; // Configure U2TX - put on pin 50 (RP17) RPOR8bits.RP17R = 5; OSCCON = 0x3302; // Enable secondary oscillator CLKDIV = 0x0000; // Set PLL prescaler (1:1) TRISA = 0x0000; TRISD = 0x00C0; #elif defined(__PIC24FJ64GB004__) //On the PIC24FJ64GB004 Family of USB microcontrollers, the PLL will not power up and be enabled //by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL). //This allows the device to power up at a lower initial operating frequency, which can be //advantageous when powered from a source which is not gauranteed to be adequate for 32MHz //operation. On these devices, user firmware needs to manually set the CLKDIV<PLLEN> bit to //power up the PLL. { unsigned int pll_startup_counter = 600; CLKDIVbits.PLLEN = 1; while(pll_startup_counter--); } #elif defined(__PIC32MX__) { int value; value = SYSTEMConfigWaitStatesAndPB( GetSystemClock() ); // Enable the cache for the best performance CheKseg0CacheOn(); INTEnableSystemMultiVectoredInt(); value = OSCCON; while (!(value & 0x00000020)) { value = OSCCON; // Wait for PLL lock to stabilize } } #endif // Init LCD LCDInit(); // Init LEDs mInitAllLEDs(); mLED_9_Off(); mLED_10_Off(); // Init Switches //mInitAllSwitches(); SwitchState = IOPORT_BIT_6|IOPORT_BIT_7; // Init UART UART2Init(); // Set Default demo state DemoState = DEMO_INITIALIZE; return TRUE; } // InitializeSystem
void InitializeSystem() { mInitAllLEDs(); }