void BoardInit( void )
{
    uint8_t i;

    /* Setup SysTick Timer for 1 us interrupts ( not too often to save power ) */
    if( SysTick_Config( SystemCoreClock / 1000 ) )
    { 
        /* Capture error */ 
        while (1);
    }

    // Initialize unused GPIO to optimize power consumption
    InitUnusedGPIO( );

    // Initialize Selector
    SelectorInit( );

    // Initialize SPI
    SpiInit( );
    
    // Initialize LED
    for( i = 0; i < LED_NB; i++ )
    {
        LedInit( ( tLed )i );
    }

    LedOn( LED1 );
    LedOn( LED2 );
    LedOn( LED3 );
    LongDelay( 1 );
    LedOff( LED1 );
    LedOff( LED2 );
    LedOff( LED3 );
}
Example #2
0
void LCDInit()
{
#ifdef P_S
LCD_PS=P_S;
#endif
LCD_CS=0;
ShortDelay(10);
LCD_CS=1;
ShortDelay(10);

     SendCMD(LCD12864_CMD_NORMAL);//功能设置,基本指令集
	 LongDelay(DELAY4MS);
#ifdef __USE_PARALLEL_MODE__ 
LongDelay(DELAY4MS);
#endif
	 SendCMD(LCD12864_CMD_DISP(1,0,0));//0000,1100  整体显示,游标off,游标位置off
     SendCMD(LCD12864_CMD_RSTDDRAM);//0000,0010 DDRAM地址归位
     LongDelay(DELAY4MS);
#ifdef __USE_PARALLEL_MODE__ 
LongDelay(DELAY4MS);
#endif
	 SendCMD(LCD12864_CMD_CLEAR);//0000,0001 清DDRAM
     LongDelay(DELAY4MS);
	 SendCMD(LCD12864_CMD_SETCUR(1,0));//点设定,显示字符/光标从左到右移位,DDRAM地址AC加1//   
#ifdef __USE_PARALLEL_MODE__ 
LongDelay(DELAY4MS);
LongDelay(DELAY4MS);
#endif
}
Example #3
0
/**********************************************************************//**
 * @brief  Startup LED sequence
 * 
 * @param  none 
 *  
 * @return none
 *************************************************************************/
void StartUpSequence(void) 
{
  unsigned char flag=4,up=1,counter = 0; 
  unsigned char LED_ArrayPJ[] = {0x01,0x02,0x04,0x08};
  unsigned char LED_ArrayP3[] = {0x80,0x40,0x20,0x10};

  while (counter <10) 
    {    
      counter++;
      PJOUT &= ~(BIT0 +BIT1+BIT2+BIT3);
      P3OUT &= ~(BIT4 +BIT5+BIT6+BIT7);    
      if(up)// from the outside - in
        {
          while(flag)
            {
              P3OUT = LED_ArrayP3[flag-1];
              PJOUT = LED_ArrayPJ[flag-1];
              LongDelay();               
              flag--;
            }
            up=0;
        }
      else
        {
          while(flag<4)
            {
              P3OUT = LED_ArrayP3[flag];
              PJOUT = LED_ArrayPJ[flag];
              LongDelay();        
              flag++;
            }
            up = 1;
          }
    } 
  
  // Exit Loop, Clear LEDs
  PJOUT &= ~(BIT0 +BIT1+BIT2+BIT3);
  P3OUT &= ~(BIT4 +BIT5+BIT6+BIT7);    
}
Example #4
0
void startUpSequence() {
	for (int i = 0; i < 8; i++) {
		blueleds.Set(i, 1);
		LongDelay();
		LongDelay();
		LongDelay();
	}
	for (int i = 0; i < 8; i++) {
		blueleds.Set(i, 0);
		LongDelay();
		LongDelay();
		LongDelay();
	}
}
Example #5
0
void ClearRAM()
{
	SendCMD(LCD12864_CMD_RSTDDRAM);
	LongDelay(100*DELAY4MS);
}
Example #6
0
/*****************************
发送字符串
*****************************/
void ClearLCD()  //在当前模式下清屏幕
{
	SendCMD(LCD12864_CMD_CLEAR);
	LongDelay(100*DELAY4MS);
}
Example #7
0
void SendData(uchar Data)
{
SPIWR(Data,1);
LongDelay(DELAY8US/2);
}
Example #8
0
void SendCMD(uchar CMD)
{
SPIWR(CMD,0);
LongDelay(DELAY8US);//命令后延时,延时不够可能会出现乱码,适当调节此值	
}
Example #9
0
/******************************************************************************
 * 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
Example #10
0
/******************************************************************************
 * 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