コード例 #1
0
ファイル: main.c プロジェクト: butterl/rk86-maximite
int main(void) {
    // Initialize LED, sound and the program button pins.
    maximite_init();

    // Initial setup of the I/O ports.
    AD1PCFG = 0xFFFF;               // Default all pins to digital.
    mJTAGPortEnable(0);             // Turn off JTAG.

    // Setup the CPU.
    // System config performance.
    SYSTEMConfigPerformance(CLOCKFREQ);
    // Fix the peripheral bus to the main clock speed.
    mOSCSetPBDIV(OSC_PB_DIV_1);

    INTEnableSystemMultiVectoredInt();  // Allow vectored interrupts.

    usb_init();
    keyboard_init();       // Initialise and startup the keyboard routines.

    rk86_video_init();     // Start the video state machine.

    delay_us(1000);
    while (keyboard_inkey() != -1);

    i8080_pic32_run();

    panic(PANIC_EMULATION_TERMINATED);

    return 0;
}
コード例 #2
0
ファイル: MainDemo.c プロジェクト: ftapparo/Arduino
/****************************************************************************
  Function:
    static void InitializeBoard(void)

  Description:
    This routine initializes the hardware.  It is a generic initialization
    routine for many of the Microchip development boards, using definitions
    in HardwareProfile.h to determine specific initialization.

  Precondition:
    None

  Parameters:
    None - None

  Returns:
    None

  Remarks:
    None
  ***************************************************************************/
static void InitializeBoard(void)
{	
	// LEDs
	LED0_TRIS = 0;
	LED1_TRIS = 0;
	LED2_TRIS = 0;
	LED3_TRIS = 0;
	LED4_TRIS = 0;
	LED5_TRIS = 0;
	LED6_TRIS = 0;
	LED_PUT(0x00);

	// Enable multi-vectored interrupts
	//INTEnableSystemMultiVectoredInt();
		
	// Enable optimal performance
	SYSTEMConfigPerformance(GetSystemClock());
	mOSCSetPBDIV(OSC_PB_DIV_1);				// Use 1:1 CPU Core:Peripheral clocks
		
	// Disable JTAG port so we get our I/O pins back, but first
	// wait 50ms so if you want to reprogram the part with 
	// JTAG, you'll still have a tiny window before JTAG goes away
	DelayMs(50);
	DDPCONbits.JTAGEN = 0;
	LED_PUT(0x00);				// Turn the LEDs off
	
	AD1PCFGbits.PCFG2 = 0;		// Disable digital input on AN2 (potentiometer)
		
	// ADC
	AD1CON1 = 0x84E4;			// Turn on, auto sample start, auto-convert, 12 bit mode (on parts with a 12bit A/D)
	AD1CON2 = 0x0404;			// AVdd, AVss, int every 2 conversions, MUXA only, scan
	AD1CON3 = 0x1003;			// 16 Tad auto-sample, Tad = 3*Tcy
	// PIC32MX460F512L PIM has different pinout to accomodate USB module
	AD1CSSL = 1<<2;				// Scan pot
}
コード例 #3
0
ファイル: main.c プロジェクト: robopanda333/RTOS
/*-----------------------------------------------------------*/
static void prvSetupHardware(void)
{
    /* Setup the CPU clocks, and configure the interrupt controller. */
    SYSTEMConfigPerformance(configCPU_CLOCK_HZ);
    mOSCSetPBDIV(OSC_PB_DIV_2);
    INTEnableSystemMultiVectoredInt();

    /* LEDs off. */
    mPORTDClearBits(BIT_0 | BIT_1 | BIT_2);

    /* LEDs are outputs. */
    mPORTDSetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2);
}
コード例 #4
0
ファイル: main.c プロジェクト: niesteszeck/FreeRTOS
static void prvSetupHardware( void )
{
	/* Set the system and peripheral bus speeds and enable the program cache*/
	SYSTEMConfigPerformance( configCPU_CLOCK_HZ - 1 );
	mOSCSetPBDIV( OSC_PB_DIV_2 );

	/* Setup to use the external interrupt controller. */
    INTEnableSystemMultiVectoredInt();

	portDISABLE_INTERRUPTS();

	/* Setup the digital IO for the LED's. */
	vParTestInitialise();
}
コード例 #5
0
ファイル: app.c プロジェクト: sidwarkd/waterworx-device
void InitializeSystem()
{
	SYSTEMConfigWaitStatesAndPB(CLOCK_FREQ);
	mOSCSetPBDIV(OSC_PB_DIV_4);  // Set to get 20MHz PB clock
  //mOSCSetPBDIV(OSC_PB_DIV_2);
	CheKseg0CacheOn();
	mJTAGPortEnable(0);

	// Initialize the pins to all digital output and driven to ground.
	// Exception is RE7 and RE6 which are switch inputs
	PORTSetPinsDigitalIn(IOPORT_E, BIT_6);
	PORTSetPinsDigitalIn(IOPORT_E, BIT_7);

	mPORTASetPinsDigitalOut(0xFFFF);
	mPORTBSetPinsDigitalOut(0xFFFF);
	mPORTCSetPinsDigitalOut(0xFFFF);
	mPORTDSetPinsDigitalOut(0xFFFF);
	mPORTESetPinsDigitalOut(0xFF3F);
	mPORTFSetPinsDigitalOut(0xFFFF);
	mPORTGSetPinsDigitalOut(0xFFFF);

	mPORTAClearBits(0xFFFF);
	mPORTBClearBits(0xFFFF);
	mPORTCClearBits(0xFFFF);
	mPORTDClearBits(0xFFFF);
	mPORTEClearBits(0xFF3F);
	mPORTESetBits(0x000F);		// LED latches need to be set high for off
	mPORTFClearBits(0xFFFF);
	mPORTGClearBits(0xFFFF);

	INTEnableSystemMultiVectoredInt();

  #ifdef SANITY_CHECK
  mLED_Green_On();
  #endif
	
	//LCD_Initialize();
	//WIFI_Initialize();
	//SPRINKLER_Initialize();
	//RTCC_Initialize(); 
  //SERIALUSB_Initialize();
	SDCARD_Initialize();

  TCPIP_Initialize();
}
コード例 #6
0
ファイル: bsp.c プロジェクト: Vanganesha/oufffteam
void  BSP_InitIO (void)    
{
                                                                        /* Enable optimal performance                       */
    SYSTEMConfigPerformance(BSP_CLK_FREQ);
    mOSCSetPBDIV(0);                                                    /* Use 1:1 CPU Core:Peripheral clocks               */

#if JTAG_ENABLE	
	DDPCONbits.JTAGEN = 1;                                              /* Maintain the port pins for JTAG use              */
#else
    DDPCONbits.JTAGEN = 0;                                              /* Free the JTAG port pins for use as GPIO          */
#endif

    BSP_InitIntCtrl();                                                  /* Initialize the interrupt controller              */
    BSP_IO_Init();                                                      /* Initialize the board's I/Os                      */
    Tmr_Init();                                                         /* Initialize the timers                            */
    LED_Init();                                                         /* Initialize LEDs                                  */
    LCD_Init();                                                         /* Initialize the LCD                               */
    PB_Init();                                                          /* Initialize the push buttons                      */
    ADC_Init();
}
コード例 #7
0
ファイル: main.c プロジェクト: denrusio/vak-opensource
int main(void) {
    // Initial setup of the I/O ports.
    AD1PCFG = 0xFFFF;               // Default all pins to digital.
    mJTAGPortEnable(0);             // Turn off JTAG.

    // Setup the CPU.
    // System config performance.
    SYSTEMConfigPerformance(CLOCKFREQ);
#if defined(MAXIMITE) || (defined(UBW32) && defined(__DEBUG)) || \
    defined(DUINOMITE)
    // Fix the peripheral bus to the main clock speed.
    mOSCSetPBDIV(OSC_PB_DIV_1);
#endif

    INTEnableSystemMultiVectoredInt();  // Allow vectored interrupts.

    keyboard_init();       // Initialise and startup the keyboard routines.
    video_init();          // Start the video state machine.
    video_clear_screen();  // Clear the video buffer.

    DelayUs(1*1000*1000);
    while (keyboard_inkey() != -1);

    video_display_string("MAXIMITE console\r\n");

    while (1) {
      int ch = input_key();
      video_put_char(ch);
      {
          static char buf[10];
          sprintf(buf, "<%02X>", ch);
          video_display_string(buf);
      }
      if (ch == '\n') video_put_char('\r');
    }
}
コード例 #8
0
ファイル: MainDemo.c プロジェクト: Athuli7/Microchip
/****************************************************************************
  Function:
    static void InitializeBoard(void)

  Description:
    This routine initializes the hardware.  It is a generic initialization
    routine for many of the Microchip development boards, using definitions
    in HardwareProfile.h to determine specific initialization.

  Precondition:
    None

  Parameters:
    None - None

  Returns:
    None

  Remarks:
    None
 ***************************************************************************/
static void InitializeBoard(void) {
    // WiFi Module hardware Initialization handled by Library

    // Enable multi-vectored interrupts
    INTEnableSystemMultiVectoredInt();

    // Enable optimal performance
    SYSTEMConfigPerformance(GetSystemClock());
    mOSCSetPBDIV(OSC_PB_DIV_1); // Use 1:1 CPU Core:Peripheral clocks

    // Disable JTAG port so we get our I/O pins back, but first
    // wait 50ms so if you want to reprogram the part with
    // JTAG, you'll still have a tiny window before JTAG goes away.
    // The PIC32 Starter Kit debuggers use JTAG and therefore must not
    // disable JTAG.
    DelayMs(50);
    DDPCONbits.JTAGEN = 0;

    // LEDs
    LEDS_OFF();
    mPORTESetPinsDigitalOut(BIT_5 | BIT_6 | BIT_7);

    // Switches
    mPORTDSetPinsDigitalIn(BIT_4 | BIT_5 | BIT_6);
    ConfigCNPullups(CN13_PULLUP_ENABLE | CN14_PULLUP_ENABLE | CN15_PULLUP_ENABLE);

    // LCD
    mPORTESetPinsDigitalOut(BIT_0 | BIT_1 | BIT_2 | BIT_3);
    //Configure LCD SPI pins
    mPORTFSetPinsDigitalOut(BIT_8);
    mPORTDSetPinsDigitalOut(BIT_15);

    //SPI Flash
    mPORTDSetPinsDigitalOut(BIT_14);


    //UART
    mPORTFSetPinsDigitalOut(BIT_5);
    mPORTFSetPinsDigitalIn(BIT_4);

    //MiWi
#if defined(MRF24J40) || defined(MRF49XA)
    PHY_CS = 1;
    mPORTDSetPinsDigitalOut(BIT_9);

    PHY_RESETn = 1;
    mPORTDSetPinsDigitalOut(BIT_11);
#endif

#if defined(MRF49XA)
    nFSEL_TRIS = 0;
    FINT_TRIS = 1;

    nFSEL = 1;
#elif defined(MRF24J40)
    PHY_WAKE = 1;
    mPORTBSetPinsDigitalOut(BIT_9);
#else
    Data_nCS_TRIS = 0;
    Config_nCS_TRIS = 0;
    Data_nCS = 1;
    Config_nCS = 1;
    IRQ1_INT_TRIS = 1;
    IRQ0_INT_TRIS = 1;

#endif

    /* Set the Port Directions of SDO, SDI, Clock & Slave Select Signal */
    /* Set SCK port pin to output */
    mPORTDSetPinsDigitalOut(BIT_10);
    /* Set SDO port pin to output */
    mPORTDSetPinsDigitalOut(BIT_0);
    /* Set SDI port pin to input */
    mPORTCSetPinsDigitalIn(BIT_4);
    /* Set INT1, INT2 port pins to input */
    mPORTESetPinsDigitalIn(BIT_8 | BIT_9);

    /* Clear SPI1CON register */
    SPI1CONCLR = 0xFFFFFFFF;

#ifdef HARDWARE_SPI
    unsigned int pbFreq;

    /* Enable SPI1, Set to Master Mode & Set CKE bit : Serial output data changes on transition
      from active clock state to Idle clock state */
    SPI1CON = 0x00008120;
    /* Peripheral Bus Frequency = System Clock / PB Divider */
    pbFreq = (DWORD) CLOCK_FREQ / (1 << mOSCGetPBDIV());

    /* PB Frequency can be maximum 40 MHz */
    if (pbFreq > (2 * MAX_SPI_CLK_FREQ_FOR_P2P)) {
        {
            unsigned int SPI_Clk_Freq;

            unsigned char SPI_Brg1 = 1;

            //For the SPI1
            /* Continue the loop till you find SPI Baud Rate Register Value */
            while (1) {
                /* SPI Clock Calculation as per PIC32 Manual */
                SPI_Clk_Freq = pbFreq / (2 * (SPI_Brg1 + 1));

                if (SPI_Clk_Freq <= MAX_SPI_CLK_FREQ_FOR_P2P) {
                    break;
                }

                SPI_Brg1++;
            }



            mSpiChnSetBrg(1, SPI_Brg1);

        }
    } else {
        /* Set SPI1 Baud Rate */
        mSpiChnSetBrg(1, 0);

    }

#endif

    /* Set the Interrupt Priority */
    mINT2SetIntPriority(4);

#if defined(MRF89XA)
    mINT1SetIntPriority(4);
#endif

    /* Set Interrupt Subpriority Bits for INT2 */
    mINT2SetIntSubPriority(2);

#if defined(MRF89XA)
    mINT2SetIntSubPriority(1);
#endif

    /* Set INT2 to falling edge */
    mINT2SetEdgeMode(0);

#if defined(MRF89XA)
    mINT1SetEdgeMode(1);
    mINT2SetEdgeMode(1);
#endif

    /* Enable INT2 */
    mINT2IntEnable(1);

#if defined(MRF89XA)
    mINT2IntEnable(1);
#endif

    /* Enable Multi Vectored Interrupts */
    //    INTEnableSystemMultiVectoredInt();

#if defined(MRF89XA)
    PHY_IRQ1 = 0;
    PHY_IRQ0 = 0;
    PHY_RESETn_TRIS = 1;
#else
    RFIF = 0;
    if (RF_INT_PIN == 0) {
        RFIF = 1;
    }
#endif

    // Initialize the EEPROM
    XEEInit();

    // UART Initialization
#if defined(STACK_USE_UART)
    UARTTX_TRIS = 0;
    UARTRX_TRIS = 1;
    UMODE = 0x8000; // Set UARTEN.  Note: this must be done before setting UTXEN
    USTA = 0x00001400; // RXEN set, TXEN set
#define CLOSEST_UBRG_VALUE ((GetPeripheralClock()+8ul*BAUD_RATE)/16/BAUD_RATE-1)
#define BAUD_ACTUAL (GetPeripheralClock()/16/(CLOSEST_UBRG_VALUE+1))

#define BAUD_ERROR ((BAUD_ACTUAL > BAUD_RATE) ? BAUD_ACTUAL-BAUD_RATE : BAUD_RATE-BAUD_ACTUAL)
#define BAUD_ERROR_PRECENT	((BAUD_ERROR*100+BAUD_RATE/2)/BAUD_RATE)
#if (BAUD_ERROR_PRECENT > 3)
#warning UART frequency error is worse than 3%
#elif (BAUD_ERROR_PRECENT > 2)
#warning UART frequency error is worse than 2%
#endif

    UBRG = CLOSEST_UBRG_VALUE;
#endif


}
コード例 #9
0
//********************************
//********************************
//********** INITIALISE **********
//********************************
//********************************
void initialise (void)
{
	BYTE data;
	
	//##### GENERAL NOTE ABOUT PIC32'S #####
	//Try and use the peripheral libraries instead of special function registers for everything (literally everything!) to avoid
	//bugs that can be caused by the pipeline and interrupts.
	

	//---------------------------------
	//----- CONFIGURE PERFORMANCE -----
	//---------------------------------
	
	//----- SETUP EVERYTHING FOR OPTIMUM PERFORMANCE -----
	SYSTEMConfigPerformance(80000000ul);		//Note this sets peripheral bus to '1' max speed (regardless of configuration bit setting)
												//Use PBCLK divider of 1:1 to calculate UART baud, timer tick etc


	//----- SET PERIPHERAL BUS DIVISOR -----
	//To minimize dynamic power the PB divisor should be chosen to run the peripherals at the lowest frequency that provides acceptable system performance
	mOSCSetPBDIV(OSC_PB_DIV_2);			//OSC_PB_DIV_1, OSC_PB_DIV_2, OSC_PB_DIV_4, OSC_PB_DIV_8, 

	//----- SETUP INTERRUPTS -----
	INTEnableSystemMultiVectoredInt();

	//-------------------------
	//----- SETUP IO PINS -----
	//-------------------------
	//(Device will powerup with all IO pins as inputs)

	//----- TURN OFF THE JTAG PORT -----
	//(JTAG is on by default)
	//mJTAGPortEnable(0);		//Must be on for Microchip Multimedia Development board

	#define	PORTA_IO	0xc2ff				//Setup the IO pin type (0 = output, 1 = input)
	mPORTAWrite(0xc033);					//Set initial ouput pin states
	mPORTASetPinsDigitalIn(PORTA_IO);		//(Sets high bits as input)
	mPORTASetPinsDigitalOut(~PORTA_IO);		//(Sets high bits as output)
	
	#define	PORTB_IO	0xfbff				//Setup the IO pin type (0 = output, 1 = input)
	mPORTBWrite(0x6d13);					//Set initial ouput pin states
	mPORTBSetPinsDigitalIn(PORTB_IO);		//(Sets high bits as input)
	mPORTBSetPinsDigitalOut(~PORTB_IO);		//(Sets high bits as output)

	mPORTBSetPinsDigitalIn(BIT_0 | BIT_1 | BIT_3 | BIT_4 | BIT_15);			//Joystick inputs

	#define	PORTC_IO	0xf01e				//Setup the IO pin type (0 = output, 1 = input)
	mPORTCWrite(0x3018);					//Set initial ouput pin states
	mPORTCSetPinsDigitalIn(PORTC_IO);		//(Sets high bits as input)
	mPORTCSetPinsDigitalOut(~PORTC_IO);		//(Sets high bits as output)

	#define	PORTD_IO	0x7bfe				//Setup the IO pin type (0 = output, 1 = input)
	mPORTDWrite(0xbdaf);					//Set initial ouput pin states
	mPORTDSetPinsDigitalIn(PORTD_IO);		//(Sets high bits as input)
	mPORTDSetPinsDigitalOut(~PORTD_IO);		//(Sets high bits as output)

	mPORTDSetPinsDigitalOut(BIT_2 | BIT_1);		//LED's 2 and 3
	mPORTDSetPinsDigitalIn(BIT_9);

	#define	PORTE_IO	0x03ff				//Setup the IO pin type (0 = output, 1 = input)
	mPORTEWrite(0x02a2);					//Set initial ouput pin states
	mPORTESetPinsDigitalIn(PORTE_IO);		//(Sets high bits as input)
	mPORTESetPinsDigitalOut(~PORTE_IO);		//(Sets high bits as output)

	#define	PORTF_IO	0x111f				//Setup the IO pin type (0 = output, 1 = input)
	mPORTFWrite(0x0039);					//Set initial ouput pin states
	mPORTFSetPinsDigitalIn(PORTF_IO);		//(Sets high bits as input)
	mPORTFSetPinsDigitalOut(~PORTF_IO);		//(Sets high bits as output)

	#define	PORTG_IO	0xd3cf				//Setup the IO pin type (0 = output, 1 = input)
	mPORTGWrite(0xf203);					//Set initial ouput pin states
	mPORTGSetPinsDigitalIn(PORTG_IO);		//(Sets high bits as input)
	mPORTGSetPinsDigitalOut(~PORTG_IO);		//(Sets high bits as output)



	//Read pins using:
	// mPORTAReadBits(BIT_0);
	//Write pins using:
	// mPORTAClearBits(BIT_0);
	// mPORTASetBits(BIT_0);
	// mPORTAToggleBits(BIT_0);



	//----- INPUT CHANGE NOTIFICATION CONFIGURATION -----
	//EnableCN0();
	ConfigCNPullups(CN2_PULLUP_ENABLE | CN3_PULLUP_ENABLE | CN5_PULLUP_ENABLE | CN6_PULLUP_ENABLE | CN12_PULLUP_ENABLE);		//Joystick pins



	//----- SETUP THE A TO D PINS -----
	ENABLE_ALL_DIG;


	//---------------------
	//----- SETUP USB -----
	//---------------------
	//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
	//HardwareProfile.h file.    
    //	#if defined(USE_USB_BUS_SENSE_IO)
    //	tris_usb_bus_sense = INPUT_PIN; // See HardwareProfile.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 HardwareProfile.h, and that an appropriate I/O pin has been mapped to it in HardwareProfile.h.
    //	#if defined(USE_SELF_POWER_SENSE_IO)
    //	tris_self_power = INPUT_PIN;	// See HardwareProfile.h
    //	#endif
    
    
    //Enable the USB port now - we will check to see if Vbus is  powered at the end of init and disable it if not.
    //USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware variables to known states.

	

	//------------------------
	//----- SETUP TIMERS -----
	//------------------------
	//(INCLUDE THE USAGE OF ALL TIMERS HERE EVEN IF NOT SETUP HERE SO THIS IS THE ONE POINT OF
	//REFERENCE TO KNOW WHICH TIMERS ARE IN USE AND FOR WHAT).

	//----- SETUP TIMER 1 -----
	//Used for: Available
	//OpenTimer1((T1_ON | T1_IDLE_CON | T1_GATE_OFF | T1_PS_1_4 | T1_SOURCE_INT), 20000);

	//----- SETUP TIMER 2 -----
	//Used for: 
	//OpenTimer2((T2_ON | T2_IDLE_CON | T2_GATE_OFF | T2_PS_1_1 | T2_SOURCE_INT), 0xffff);		//0xffff = 305Hz

	//----- SETUP TIMER 3 -----
	//Used for: 
	//OpenTimer3((T3_ON | T3_IDLE_CON | T3_GATE_OFF | T3_PS_1_1 | T3_SOURCE_INT), PIEZO_TIMER_PERIOD);

	//----- SETUP TIMER 4 -----
	//Used for: 
	//OpenTimer4((T4_ON | T4_IDLE_CON | T4_GATE_OFF | T4_PS_1_1 | T4_SOURCE_INT), 20000);

	//----- SETUP TIMER 5 -----
	//Used for: Heartbeat
	OpenTimer5((T5_ON | T5_IDLE_CON | T5_GATE_OFF | T5_PS_1_1 | T5_SOURCE_INT), 40000);		//1mS with 80MHz osc and PB_DIV_2
	ConfigIntTimer5(T5_INT_ON | T5_INT_PRIOR_7);											//1=lowest priority to 7=highest priority.  ISR function must specify same value



	//---------------------------------
	//----- SETUP EVAL BOARD CPLD -----
	//---------------------------------
	//Graphics bus width = 16
	mPORTGSetPinsDigitalOut(BIT_14);
	mPORTGSetBits(BIT_14);

	//SPI source select = SPI3 (not used)
	mPORTGSetPinsDigitalOut(BIT_12);
	mPORTGClearBits(BIT_12);
	
	//SPI peripheral destination select = Expansion Slot (not used)
	mPORTASetPinsDigitalOut(BIT_7 | BIT_6);
	mPORTASetBits(BIT_7);
	mPORTAClearBits(BIT_6);


	//--------------------------------------
    //----- PARALLEL MASTER PORT SETUP -----
	//--------------------------------------
    PMMODE = 0;
    PMAEN = 0;
    PMCON = 0;
    PMMODE = 0x0610;
    PMCONbits.PTRDEN = 1;                   //Enable RD line
    PMCONbits.PTWREN = 1;                   //Enable WR line
    PMCONbits.PMPEN = 1;                    //Enable PMP


	//------------------------------
	//----- INITIALISE DISPLAY -----
	//------------------------------
	display_initialise();


	display_test();

	//LOAD OUR GLOBAL HTML STYLES FILE READY FOR DISPLAY HTML PAGES
	BYTE dummy_styles_count;
	DWORD file_size;
	if (display_html_setup_read_file(global_css, 0, &file_size))
	{
		dummy_styles_count = 0;
		display_html_read_styles(&file_size, &dummy_styles_count, 1);			//1 = this is global styles file
	}

}
コード例 #10
0
ファイル: MainDemo.c プロジェクト: OptecInc/FocusLynx_FW
/****************************************************************************
  Function:
    static void InitializeBoard(void)

  Description:
    This routine initializes the hardware.  It is a generic initialization
    routine for many of the Microchip development boards, using definitions
    in HardwareProfile.h to determine specific initialization.

  Precondition:
    None

  Parameters:
    None - None

  Returns:
    None

  Remarks:
    None
  ***************************************************************************/
static void InitializeBoard(void)
{	
	// LEDs
	LED0_TRIS = 0;
	LED1_TRIS = 0;
	LED2_TRIS = 0;
	LED3_TRIS = 0;
	LED4_TRIS = 0;
	LED5_TRIS = 0;
	LED6_TRIS = 0;
	LED7_TRIS = 0;
//	LED_PUT(0x00);

#if defined(__18CXX)
	// Enable 4x/5x/96MHz PLL on PIC18F87J10, PIC18F97J60, PIC18F87J50, etc.
    OSCTUNE = 0x40;

	// Set up analog features of PORTA

	// PICDEM.net 2 board has POT on AN2, Temp Sensor on AN3
	#if defined(PICDEMNET2)
		ADCON0 = 0x09;		// ADON, Channel 2
		ADCON1 = 0x0B;		// Vdd/Vss is +/-REF, AN0, AN1, AN2, AN3 are analog
	#elif defined(PICDEMZ)
		ADCON0 = 0x81;		// ADON, Channel 0, Fosc/32
		ADCON1 = 0x0F;		// Vdd/Vss is +/-REF, AN0, AN1, AN2, AN3 are all digital
	#elif defined(__18F87J11) || defined(_18F87J11) || defined(__18F87J50) || defined(_18F87J50)
		ADCON0 = 0x01;		// ADON, Channel 0, Vdd/Vss is +/-REF
		WDTCONbits.ADSHR = 1;
		ANCON0 = 0xFC;		// AN0 (POT) and AN1 (temp sensor) are anlog
		ANCON1 = 0xFF;
		WDTCONbits.ADSHR = 0;		
	#else
		ADCON0 = 0x01;		// ADON, Channel 0
		ADCON1 = 0x0E;		// Vdd/Vss is +/-REF, AN0 is analog
	#endif
	ADCON2 = 0xBE;		// Right justify, 20TAD ACQ time, Fosc/64 (~21.0kHz)


    // Enable internal PORTB pull-ups
    INTCON2bits.RBPU = 0;

	// Configure USART
    TXSTA = 0x20;
    RCSTA = 0x90;

	// See if we can use the high baud rate setting
	#if ((GetPeripheralClock()+2*BAUD_RATE)/BAUD_RATE/4 - 1) <= 255
		SPBRG = (GetPeripheralClock()+2*BAUD_RATE)/BAUD_RATE/4 - 1;
		TXSTAbits.BRGH = 1;
	#else	// Use the low baud rate setting
		SPBRG = (GetPeripheralClock()+8*BAUD_RATE)/BAUD_RATE/16 - 1;
	#endif


	// Enable Interrupts
	RCONbits.IPEN = 1;		// Enable interrupt priorities
    INTCONbits.GIEH = 1;
    INTCONbits.GIEL = 1;

    // Do a calibration A/D conversion
	#if defined(__18F87J10) || defined(__18F86J15) || defined(__18F86J10) || defined(__18F85J15) || defined(__18F85J10) || defined(__18F67J10) || defined(__18F66J15) || defined(__18F66J10) || defined(__18F65J15) || defined(__18F65J10) || defined(__18F97J60) || defined(__18F96J65) || defined(__18F96J60) || defined(__18F87J60) || defined(__18F86J65) || defined(__18F86J60) || defined(__18F67J60) || defined(__18F66J65) || defined(__18F66J60) || \
	     defined(_18F87J10) ||  defined(_18F86J15) || defined(_18F86J10)  ||  defined(_18F85J15) ||  defined(_18F85J10) ||  defined(_18F67J10) ||  defined(_18F66J15) ||  defined(_18F66J10) ||  defined(_18F65J15) ||  defined(_18F65J10) ||  defined(_18F97J60) ||  defined(_18F96J65) ||  defined(_18F96J60) ||  defined(_18F87J60) ||  defined(_18F86J65) ||  defined(_18F86J60) ||  defined(_18F67J60) ||  defined(_18F66J65) ||  defined(_18F66J60)
		ADCON0bits.ADCAL = 1;
	    ADCON0bits.GO = 1;
		while(ADCON0bits.GO);
		ADCON0bits.ADCAL = 0;
	#elif defined(__18F87J11) || defined(__18F86J16) || defined(__18F86J11) || defined(__18F67J11) || defined(__18F66J16) || defined(__18F66J11) || \
		   defined(_18F87J11) ||  defined(_18F86J16) ||  defined(_18F86J11) ||  defined(_18F67J11) ||  defined(_18F66J16) ||  defined(_18F66J11) || \
		  defined(__18F87J50) || defined(__18F86J55) || defined(__18F86J50) || defined(__18F67J50) || defined(__18F66J55) || defined(__18F66J50) || \
		   defined(_18F87J50) ||  defined(_18F86J55) ||  defined(_18F86J50) ||  defined(_18F67J50) ||  defined(_18F66J55) ||  defined(_18F66J50)
		ADCON1bits.ADCAL = 1;
	    ADCON0bits.GO = 1;
		while(ADCON0bits.GO);
		ADCON1bits.ADCAL = 0;
	#endif

#else	// 16-bit C30 and and 32-bit C32
	#if defined(__PIC32MX__)
	{
		// Enable multi-vectored interrupts
		INTEnableSystemMultiVectoredInt();
		
		// Enable optimal performance
		SYSTEMConfigPerformance(GetSystemClock());
		mOSCSetPBDIV(OSC_PB_DIV_1);				// Use 1:1 CPU Core:Peripheral clocks
		
		// Disable JTAG port so we get our I/O pins back, but first
		// wait 50ms so if you want to reprogram the part with 
		// JTAG, you'll still have a tiny window before JTAG goes away.
		// The PIC32 Starter Kit debuggers use JTAG and therefore must not 
		// disable JTAG.
		DelayMs(50);
		#if !defined(__MPLAB_DEBUGGER_PIC32MXSK) && !defined(__MPLAB_DEBUGGER_FS2)
			DDPCONbits.JTAGEN = 0;
		#endif
		LED_PUT(0x00);				// Turn the LEDs off
		
		CNPUESET = 0x00098000;		// Turn on weak pull ups on CN15, CN16, CN19 (RD5, RD7, RD13), which is connected to buttons on PIC32 Starter Kit boards
	}
	#endif

	#if defined(__dsPIC33F__) || defined(__PIC24H__)
		// Crank up the core frequency
		PLLFBD = 38;				// Multiply by 40 for 160MHz VCO output (8MHz XT oscillator)
		CLKDIV = 0x0000;			// FRC: divide by 2, PLLPOST: divide by 2, PLLPRE: divide by 2
	
		// Port I/O
		#if defined (WIFI_BOARD_FOC_HUB)
			AD1PCFGL = 0xFFFF; 	// All pins digital
		#else
			AD1PCFGHbits.PCFG23 = 1;	// Make RA7 (BUTTON1) a digital input
			AD1PCFGHbits.PCFG20 = 1;	// Make RA12 (INT1) a digital input for MRF24WB0M PICtail Plus interrupt
			
			// ADC
	    	AD1CHS0 = 0;				// Input to AN0 (potentiometer)
			AD1PCFGLbits.PCFG5 = 0;		// Disable digital input on AN5 (potentiometer)
			AD1PCFGLbits.PCFG4 = 0;		// Disable digital input on AN4 (TC1047A temp sensor)
		#endif
	#else	//defined(__PIC24F__) || defined(__PIC32MX__)
		#if defined(__PIC24F__)
			CLKDIVbits.RCDIV = 0;		// Set 1:1 8MHz FRC postscalar
		#endif
		
		// ADC
	    #if defined(__PIC24FJ256DA210__) || defined(__PIC24FJ256GB210__)
	    	// Disable analog on all pins
	    	ANSA = 0x0000;
	    	ANSB = 0x0000;
	    	ANSC = 0x0000;
	    	ANSD = 0x0000;
	    	ANSE = 0x0000;
	    	ANSF = 0x0000;
	    	ANSG = 0x0000;
		#else
		    AD1CHS = 0;					// Input to AN0 (potentiometer)
			AD1PCFGbits.PCFG4 = 0;		// Disable digital input on AN4 (TC1047A temp sensor)
			#if defined(__32MX460F512L__) || defined(__32MX795F512L__)	// PIC32MX460F512L and PIC32MX795F512L PIMs has different pinout to accomodate USB module
				AD1PCFGbits.PCFG2 = 0;		// Disable digital input on AN2 (potentiometer)
			#else
				AD1PCFGbits.PCFG5 = 0;		// Disable digital input on AN5 (potentiometer)
			#endif
		#endif
	#endif

	// ADC
	#if defined (WIFI_BOARD_FOC_HUB)
		// Don't need to do the stuff below
	#else 
		AD1CON1 = 0x84E4;			// Turn on, auto sample start, auto-convert, 12 bit mode (on parts with a 12bit A/D)
		AD1CON2 = 0x0404;			// AVdd, AVss, int every 2 conversions, MUXA only, scan
		AD1CON3 = 0x1003;			// 16 Tad auto-sample, Tad = 3*Tcy
		#if defined(__32MX460F512L__) || defined(__32MX795F512L__)	// PIC32MX460F512L and PIC32MX795F512L PIMs has different pinout to accomodate USB module
			AD1CSSL = 1<<2;				// Scan pot
		#else
			AD1CSSL = 1<<5;				// Scan pot
		#endif
	#endif

	// UART
	#if defined(STACK_USE_UART)
		UARTTX_TRIS = 0;
		UARTRX_TRIS = 1;
		UMODE = 0x8000;			// Set UARTEN.  Note: this must be done before setting UTXEN

		#if defined(__C30__)
			USTA = 0x0400;		// UTXEN set
			#define CLOSEST_UBRG_VALUE ((GetPeripheralClock()+8ul*BAUD_RATE)/16/BAUD_RATE-1)
			#define BAUD_ACTUAL (GetPeripheralClock()/16/(CLOSEST_UBRG_VALUE+1))
		#else	//defined(__C32__)
			USTA = 0x00001400;		// RXEN set, TXEN set
			#define CLOSEST_UBRG_VALUE ((GetPeripheralClock()+8ul*BAUD_RATE)/16/BAUD_RATE-1)
			#define BAUD_ACTUAL (GetPeripheralClock()/16/(CLOSEST_UBRG_VALUE+1))
		#endif
	
		#define BAUD_ERROR ((BAUD_ACTUAL > BAUD_RATE) ? BAUD_ACTUAL-BAUD_RATE : BAUD_RATE-BAUD_ACTUAL)
		#define BAUD_ERROR_PRECENT	((BAUD_ERROR*100+BAUD_RATE/2)/BAUD_RATE)
		#if (BAUD_ERROR_PRECENT > 3)
			#warning UART frequency error is worse than 3%
		#elif (BAUD_ERROR_PRECENT > 2)
			#warning UART frequency error is worse than 2%
		#endif
	
		UBRG = CLOSEST_UBRG_VALUE;
	#endif

#endif

// Deassert all chip select lines so there isn't any problem with 
// initialization order.  Ex: When ENC28J60 is on SPI2 with Explorer 16, 
// MAX3232 ROUT2 pin will drive RF12/U2CTS ENC28J60 CS line asserted, 
// preventing proper 25LC256 EEPROM operation.
#if defined(ENC_CS_TRIS)
	ENC_CS_IO = 1;
	ENC_CS_TRIS = 0;
#endif
#if defined(ENC100_CS_TRIS)
	ENC100_CS_IO = (ENC100_INTERFACE_MODE == 0);
	ENC100_CS_TRIS = 0;
#endif
#if defined(EEPROM_CS_TRIS)
	EEPROM_CS_IO = 1;
	EEPROM_CS_TRIS = 0;
#endif
#if defined(SPIRAM_CS_TRIS)
	SPIRAM_CS_IO = 1;
	SPIRAM_CS_TRIS = 0;
#endif
#if defined(SPIFLASH_CS_TRIS)
	SPIFLASH_CS_IO = 1;
	SPIFLASH_CS_TRIS = 0;
#endif
#if defined(WF_CS_TRIS)
	WF_CS_IO = 1;
	WF_CS_TRIS = 0;
#endif

#if defined (WIFI_BOARD_FOC_HUB)
	// Inputs (WIFI/EE) on SPI1
	_SDI1R = 8;	// SDI1 = RP8
	_INT1R = 7;	// Assign RB7/RP7 to INT1 (input) for MRF24WB0M Wi-Fi PICtail Plus interrupt
	
	// Inputs (MOTHER) on SPI2
	_SDI2R = 12;	// SDI2 = RP12
	_SCK2R = 11;	// SCK2 = RP11 - clock is input because this is the slave
	_SS2R = 13;		// SS2 = RP13  - set slave select pin.		
	
	// Outputs (WIFI/EEP) on SPI1
	_RP6R = 8; 		// RP6 = SCK1
	_RP5R = 7;		// RP5 = SDO1
	
	// Outputs (MOTHER) on SPI2
	_RP10R = 10;	// RP10 = SDO2
	
#endif

#if defined(PIC24FJ64GA004_PIM)
	__builtin_write_OSCCONL(OSCCON & 0xBF);  // Unlock PPS

	// Remove some LED outputs to regain other functions
	LED1_TRIS = 1;		// Multiplexed with BUTTON0
	LED5_TRIS = 1;		// Multiplexed with EEPROM CS
	LED7_TRIS = 1;		// Multiplexed with BUTTON1
	
	// Inputs
	RPINR19bits.U2RXR = 19;			//U2RX = RP19
	RPINR22bits.SDI2R = 20;			//SDI2 = RP20
	RPINR20bits.SDI1R = 17;			//SDI1 = RP17
	
	// Outputs
	RPOR12bits.RP25R = U2TX_IO;		//RP25 = U2TX  
	RPOR12bits.RP24R = SCK2OUT_IO; 	//RP24 = SCK2
	RPOR10bits.RP21R = SDO2_IO;		//RP21 = SDO2
	RPOR7bits.RP15R = SCK1OUT_IO; 	//RP15 = SCK1
	RPOR8bits.RP16R = SDO1_IO;		//RP16 = SDO1
	
	AD1PCFG = 0xFFFF;				//All digital inputs - POT and Temp are on same pin as SDO1/SDI1, which is needed for ENC28J60 commnications

	__builtin_write_OSCCONL(OSCCON | 0x40); // Lock PPS
#endif

#if defined(__PIC24FJ256DA210__)
	__builtin_write_OSCCONL(OSCCON & 0xBF);  // Unlock PPS

	// Inputs
	RPINR19bits.U2RXR = 11;	// U2RX = RP11
	RPINR20bits.SDI1R = 0;	// SDI1 = RP0
	RPINR0bits.INT1R = 34;	// Assign RE9/RPI34 to INT1 (input) for MRF24WB0M Wi-Fi PICtail Plus interrupt
	
	// Outputs
	RPOR8bits.RP16R = 5;	// RP16 = U2TX
	RPOR1bits.RP2R = 8; 	// RP2 = SCK1
	RPOR0bits.RP1R = 7;		// RP1 = SDO1

	__builtin_write_OSCCONL(OSCCON | 0x40); // Lock PPS
#endif

#if defined(__PIC24FJ256GB110__) || defined(__PIC24FJ256GB210__)
	__builtin_write_OSCCONL(OSCCON & 0xBF);  // Unlock PPS
	
	// Configure SPI1 PPS pins (ENC28J60/ENCX24J600/MRF24WB0M or other PICtail Plus cards)
	RPOR0bits.RP0R = 8;		// Assign RP0 to SCK1 (output)
	RPOR7bits.RP15R = 7;	// Assign RP15 to SDO1 (output)
	RPINR20bits.SDI1R = 23;	// Assign RP23 to SDI1 (input)

	// Configure SPI2 PPS pins (25LC256 EEPROM on Explorer 16)
	RPOR10bits.RP21R = 11;	// Assign RG6/RP21 to SCK2 (output)
	RPOR9bits.RP19R = 10;	// Assign RG8/RP19 to SDO2 (output)
	RPINR22bits.SDI2R = 26;	// Assign RG7/RP26 to SDI2 (input)
	
	// Configure UART2 PPS pins (MAX3232 on Explorer 16)
	#if !defined(ENC100_INTERFACE_MODE) || (ENC100_INTERFACE_MODE == 0) || defined(ENC100_PSP_USE_INDIRECT_RAM_ADDRESSING)
	RPINR19bits.U2RXR = 10;	// Assign RF4/RP10 to U2RX (input)
	RPOR8bits.RP17R = 5;	// Assign RF5/RP17 to U2TX (output)
	#endif
	
	// Configure INT1 PPS pin (MRF24WB0M Wi-Fi PICtail Plus interrupt signal when in SPI slot 1)
	RPINR0bits.INT1R = 33;	// Assign RE8/RPI33 to INT1 (input)

	// Configure INT3 PPS pin (MRF24WB0M Wi-Fi PICtail Plus interrupt signal when in SPI slot 2)
	RPINR1bits.INT3R = 40;	// Assign RC3/RPI40 to INT3 (input)

	__builtin_write_OSCCONL(OSCCON | 0x40); // Lock PPS
#endif

#if defined(__PIC24FJ256GA110__)
	__builtin_write_OSCCONL(OSCCON & 0xBF);  // Unlock PPS
	
	// Configure SPI2 PPS pins (25LC256 EEPROM on Explorer 16 and ENC28J60/ENCX24J600/MRF24WB0M or other PICtail Plus cards)
	// Note that the ENC28J60/ENCX24J600/MRF24WB0M PICtails SPI PICtails must be inserted into the middle SPI2 socket, not the topmost SPI1 slot as normal.  This is because PIC24FJ256GA110 A3 silicon has an input-only RPI PPS pin in the ordinary SCK1 location.  Silicon rev A5 has this fixed, but for simplicity all demos will assume we are using SPI2.
	RPOR10bits.RP21R = 11;	// Assign RG6/RP21 to SCK2 (output)
	RPOR9bits.RP19R = 10;	// Assign RG8/RP19 to SDO2 (output)
	RPINR22bits.SDI2R = 26;	// Assign RG7/RP26 to SDI2 (input)
	
	// Configure UART2 PPS pins (MAX3232 on Explorer 16)
	RPINR19bits.U2RXR = 10;	// Assign RF4/RP10 to U2RX (input)
	RPOR8bits.RP17R = 5;	// Assign RF5/RP17 to U2TX (output)
	
	// Configure INT3 PPS pin (MRF24WB0M PICtail Plus interrupt signal)
	RPINR1bits.INT3R = 36;	// Assign RA14/RPI36 to INT3 (input)

	__builtin_write_OSCCONL(OSCCON | 0x40); // Lock PPS
#endif


#if defined(DSPICDEM11)
	// Deselect the LCD controller (PIC18F252 onboard) to ensure there is no SPI2 contention
	LCDCTRL_CS_TRIS = 0;
	LCDCTRL_CS_IO = 1;

	// Hold the codec in reset to ensure there is no SPI2 contention
	CODEC_RST_TRIS = 0;
	CODEC_RST_IO = 0;
#endif

#if defined(SPIRAM_CS_TRIS)
	SPIRAMInit();
#endif
#if defined(EEPROM_CS_TRIS)
	XEEInit();
#endif
#if defined(SPIFLASH_CS_TRIS)
	SPIFlashInit();
#endif
}
コード例 #11
0
/****************************************************************************
  Function:
    static void InitializeBoard(void)

  Description:
    This routine initializes the hardware.  It is a generic initialization
    routine for many of the Microchip development boards, using definitions
    in HardwareProfile.h to determine specific initialization.

  Precondition:
    None

  Parameters:
    None - None

  Returns:
    None

  Remarks:
    None
  ***************************************************************************/
static void InitializeBoard(void)
{
    // Note: WiFi Module hardware Initialization handled by StackInit() Library Routine

    // Enable multi-vectored interrupts
    INTEnableSystemMultiVectoredInt();

    // Enable optimal performance
    SYSTEMConfigPerformance(GetSystemClock());

    // Use 1:1 CPU Core:Peripheral clocks
    mOSCSetPBDIV(OSC_PB_DIV_1);     

    // Disable JTAG port so we get our I/O pins back, but first
    // wait 50ms so if you want to reprogram the part with
    // JTAG, you'll still have a tiny window before JTAG goes away.
    // The PIC32 Starter Kit debuggers use JTAG and therefore must not
    // disable JTAG.
    DelayMs(50);
    DDPCONbits.JTAGEN = 0;

    // UART line configuration

    UARTConfigure(SENSOR_UART, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(SENSOR_UART, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(SENSOR_UART, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(SENSOR_UART, GetPeripheralClock(), 9600);
    UARTEnable(SENSOR_UART, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));


    UARTConfigure(SENSOR_UART2, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(SENSOR_UART2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(SENSOR_UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(SENSOR_UART2, GetPeripheralClock(), 9600);
    UARTEnable(SENSOR_UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));

    // ADC configuration

    // Define setup parameters for OpenADC10 function
    // Attention, the sample number need to be changed for multi sensor use, not 1
// Turn module on | Ouput in integer format | Trigger mode auto | Disable autosample    , manually controlled
#define config1     ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON | ADC_MODULE_ON | ADC_IDLE_STOP
// ADC ref external | Disable offset test | Disable scan mode | Perform 1 samples | Use dual buffers | Use alternate mode
#define config2     ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_ON | ADC_SAMPLES_PER_INT_2 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF
// Use ADC internal clock | Set sample time
#define config3     ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_31
// Do not assign channels to scan
#define configscan  ~(ENABLE_AN2_ANA | ENABLE_AN3_ANA)
  // Define the port for ADC, need to be modified for practical prox sensors
 #define configport  ENABLE_AN2_ANA | ENABLE_AN3_ANA

    CloseADC10();
    // here use on-board potentiometer for testing, change pin configuration when for actually prox sensor use
    SetChanADC10( ADC_CH0_NEG_SAMPLEA_NVREF);
    // Configure ADC using the parameters defined above
    OpenADC10( config1, config2, config3, configport, configscan );

    EnableADC10(); // Enable the ADC

    // LEDs
    LEDS_OFF();
    LED0_TRIS = 0;
    LED1_TRIS = 0;
    LED2_TRIS = 0;

    // Push Button
    SW0_TRIS = 1;

        // MPU 9150 I2C Init and chip init
      Mpu_I2c_Init(I2C_NUM);      // config the I2C module on PIC32
        // wait at least 100 ms for sensor chip warm up, based on 40Mhz sysclk 4M times
     DelayMs(100);
    if (Mpu_Init(I2C_NUM)==I2C_ERROR)         // Initialize the 9150 chip
       // UARTTxBuffer("Sensor is not connected",strlen("Sensor is not connected"));
     LEDS_ON();
}
コード例 #12
0
ファイル: MainDemo.c プロジェクト: asayler/SmartWallv1
/****************************************************************************
  Function:
    static void InitializeBoard(void)

  Description:
    This routine initializes the hardware.  It is a generic initialization
    routine for many of the Microchip development boards, using definitions
    in HardwareProfile.h to determine specific initialization.

  Precondition:
    None

  Parameters:
    None - None

  Returns:
    None

  Remarks:
    None
  ***************************************************************************/
static void InitializeBoard(void)
{	
	// LEDs
	LED0_TRIS = 0;
	LED1_TRIS = 0;
	LED2_TRIS = 0;
	LED3_TRIS = 0;
	LED4_TRIS = 0;
	LED5_TRIS = 0;
	LED6_TRIS = 0;
	LED7_TRIS = 0;
	LED_PUT(0x00);


#if defined(__PIC32MX__)
{
	// Enable multi-vectored interrupts
	INTEnableSystemMultiVectoredInt();
	
	// Enable optimal performance
	SYSTEMConfigPerformance(GetSystemClock());
	mOSCSetPBDIV(OSC_PB_DIV_1);				// Use 1:1 CPU Core:Peripheral clocks
	
	// Disable JTAG port so we get our I/O pins back, but first
	// wait 50ms so if you want to reprogram the part with 
	// JTAG, you'll still have a tiny window before JTAG goes away.
	// The PIC32 Starter Kit debuggers use JTAG and therefore must not 
	// disable JTAG.
	DelayMs(50);
	#if !defined(__MPLAB_DEBUGGER_PIC32MXSK) && !defined(__MPLAB_DEBUGGER_FS2)
		DDPCONbits.JTAGEN = 0;
	#endif
	LED_PUT(0x00);				// Turn the LEDs off
	
	CNPUESET = 0x00098000;		// Turn on weak pull ups on CN15, CN16, CN19 (RD5, RD7, RD13), which is connected to buttons on PIC32 Starter Kit boards
}
#endif

AD1CHS = 0;					// Input to AN0 (potentiometer)
AD1PCFGbits.PCFG4 = 0;		// Disable digital input on AN4 (TC1047A temp sensor)
#if defined(__32MX460F512L__) || defined(__32MX795F512L__)	// PIC32MX460F512L and PIC32MX795F512L PIMs has different pinout to accomodate USB module
	AD1PCFGbits.PCFG2 = 0;		// Disable digital input on AN2 (potentiometer)
#else
	AD1PCFGbits.PCFG5 = 0;		// Disable digital input on AN5 (potentiometer)
#endif

// ADC
AD1CON1 = 0x84E4;			// Turn on, auto sample start, auto-convert, 12 bit mode (on parts with a 12bit A/D)
AD1CON2 = 0x0404;			// AVdd, AVss, int every 2 conversions, MUXA only, scan
AD1CON3 = 0x1003;			// 16 Tad auto-sample, Tad = 3*Tcy
#if defined(__32MX460F512L__) || defined(__32MX795F512L__)	// PIC32MX460F512L and PIC32MX795F512L PIMs has different pinout to accomodate USB module
	AD1CSSL = 1<<2;				// Scan pot
#else
	AD1CSSL = 1<<5;				// Scan pot
#endif

// Deassert all chip select lines so there isn't any problem with 
// initialization order.
#if defined(ENC_CS_TRIS)
	ENC_CS_IO = 1;
	ENC_CS_TRIS = 0;
#endif
#if defined(ENC100_CS_TRIS)
	ENC100_CS_IO = (ENC100_INTERFACE_MODE == 0);
	ENC100_CS_TRIS = 0;
#endif
#if defined(EEPROM_CS_TRIS)
	EEPROM_CS_IO = 1;
	EEPROM_CS_TRIS = 0;
#endif
#if defined(SPIRAM_CS_TRIS)
	SPIRAM_CS_IO = 1;
	SPIRAM_CS_TRIS = 0;
#endif
#if defined(SPIFLASH_CS_TRIS)
	SPIFLASH_CS_IO = 1;
	SPIFLASH_CS_TRIS = 0;
#endif

#if defined(SPIRAM_CS_TRIS)
	SPIRAMInit();
#endif
#if defined(EEPROM_CS_TRIS)
	XEEInit();
#endif
#if defined(SPIFLASH_CS_TRIS)
	SPIFlashInit();
#endif
}
コード例 #13
0
ファイル: main.cpp プロジェクト: jorticus/hexlight-firmware
void InitializeSystem() {

#ifdef BOARD_UBW32
    // Disable ADC port (allows PORTB to be used for digital I/O)
    AD1PCFG = 0xFFFF;

    TRISE = 0x0000;
    TRISB = 0x0000;
    TRISC = 0x0000;
    TRISD = 0x0000;
    LATE = 0x0000;
    LATB = 0x0000;
    LATC = 0x0000;
    LATD = 0x0000;
#endif
#ifdef BOARD_HEXLIGHT
    ANSELA = 0x0000;
    ANSELB = 0x0000;
#endif
    LATA = 0x0000;
    LATB = 0x0000;

    // Ensure LED drivers are driven low as soon as possible
//    _TRIS(PIO_OC1) = 0;
//    _TRIS(PIO_OC2) = 0;
//    _TRIS(PIO_OC3) = 0;
//    _TRIS(PIO_OC4) = 0;
//    _LAT(PIO_OC1) = OUTPUT;
//    _LAT(PIO_OC2) = OUTPUT;
//    _LAT(PIO_OC3) = OUTPUT;
//    _LAT(PIO_OC4) = OUTPUT;

    // Force disconnect of USB bootloader
    U1CON = 0x00000000;
    U1PWRC = 0x00000000;

    // LEDs
//    _TRIS(PIO_LED1) = OUTPUT;
//    _TRIS(PIO_LED2) = OUTPUT;
#ifdef BOARD_UBW32
    _TRIS(PIO_LED3) = OUTPUT;
    _TRIS(PIO_LED_USB) = OUTPUT;
    _TRIS(PIO_BTN_PGM) = 1;
    _TRIS(PIO_BTN_USR) = 1;
#elif BOARD_HEXLIGHT
    _TRIS(PIO_BTN1) = INPUT;
    _TRIS(PIO_BTN2) = INPUT;
#endif

//    _TRIS(PIO_USBP) = INPUT;
//    _TRIS(PIO_USBN) = INPUT;

//    _LAT(PIO_LED1) = LOW;
//    _LAT(PIO_LED2) = LOW;
#ifdef BOARD_UBW32
    _LAT(PIO_LED3) = HIGH;
    _LAT(PIO_LED_USB) = LOW;
#endif

    mJTAGPortEnable(0);

    // Initializethe PIC32 core
    //OSCConfig(OSC_POSC_PLL, OSC_PLL_MULT_20, OSC_PLL_POST_2, OSC_FRC_POST_2);
    sys_clock = F_SYSCLK;
    mOSCSetPBDIV(OSC_PB_DIV_1);
    pb_clock = SYSTEMConfig(sys_clock, SYS_CFG_ALL);


    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    INTEnableInterrupts();

    // Initialize core time base
    SystickInit();
}
コード例 #14
0
int main(int argc, char *argv[]) {
    register char *s, *p;
    register char *pn = argv[0];

    // configure the I/O ports
    AD1PCFG = 0xFFFF; // Default all pins to digital
    mJTAGPortEnable(0); // turn off jtag

    // setup the CPU
    SYSTEMConfigPerformance(CLOCKFREQ); // System config performance
    mOSCSetPBDIV(OSC_PB_DIV_1); // fix the peripheral bus to half main clock speed
    INTEnableSystemMultiVectoredInt();

    TRISBbits.TRISB15 = 0;
 //   TRISDbits.TRISD11 = 0;
 //   ODCDbits.ODCD11 = 1;
 //   LATDbits.LATD11=0;

    TRISBbits.TRISB13 = 0;
    ODCBbits.ODCB13 = 1;
    PORTBbits.RB13=0;
#ifdef UARTConsole
    UARTInit();
#endif
    initKeyboard();

#ifdef UseVideo
    initVideo();
#endif



#ifdef CPU_SPEED
    f_flag = CPU_SPEED;
    tmax = CPU_SPEED * 10000;
#endif
    argc = 0;
    while (--argc > 0 && (*++argv)[0] == '-')
        for (s = argv[0] + 1; *s != '\0'; s++)
            switch (*s) {
                case 's': /* save core and CPU on exit */
                    s_flag = 1;
                    break;
                case 'l': /* load core and CPU from file */
                    l_flag = 1;
                    break;
#ifdef Z80_UNDOC
                case 'z': /* trap undocumented Z80 ops */
                    z_flag = 1;
                    break;
#endif
                case 'i': /* trap I/O on unused ports */
                    i_flag = 1;
                    break;
                case 'm': /* initialize Z80 memory */
                    m_flag = exatoi(s + 1);
                    s += strlen(s + 1);
                    break;
                case 'f': /* set emulation speed */
                    f_flag = atoi(s + 1);
                    s += strlen(s + 1);
                    tmax = f_flag * 10000;
                    break;
                case 'x': /* get filename with Z80 executable */
                    x_flag = 1;
                    s++;
                    p = xfn;
                    while (*s)
                        *p++ = *s++;
                    *p = '\0';
                    s--;
                    break;
                case '?':
                    goto usage;
                default:
                    printf("illegal option %c\n", *s);
#ifndef Z80_UNDOC
usage:
                    printf("usage:\t%s -s -l -i -mn -fn -xfilename\n", pn);
#else
usage:
                    printf("usage:\t%s -s -l -i -z -mn -fn -xfilename\n", pn);
#endif
                    puts("\ts = save core and cpu");
                    puts("\tl = load core and cpu");
                    puts("\ti = trap on I/O to unused ports");
#ifdef Z80_UNDOC
                    puts("\tz = trap on undocumented Z80 ops");
#endif
                    puts("\tm = init memory with n");
                    puts("\tf = CPU frequenzy n in MHz");
                    puts("\tx = load and execute filename");
                    exit(1);
            }

    putchar('\n');
    puts("#######  #####    ###            #####    ###   #     #");
    puts("     #  #     #  #   #          #     #    #    ##   ##");
    puts("    #   #     # #     #         #          #    # # # #");
    puts("   #     #####  #     #  #####   #####     #    #  #  #");
    puts("  #     #     # #     #               #    #    #     #");
    puts(" #      #     #  #   #          #     #    #    #     #");
    puts("#######  #####    ###            #####    ###   #     #");
    printf("\nRelease %s, %s\n", RELEASE, COPYR);
    printf("\nPort to PIC32 By kenseglerdesigns.com\n");
    if (f_flag > 0)
        printf("\nCPU speed is %d MHz\n", f_flag);
    else
        printf("\nCPU speed is unlimited\n");
#ifdef	USR_COM
    printf("\n%s Release %s, %s\n", USR_COM, USR_REL, USR_CPR);
#endif
    fflush(stdout);

    wrk_ram = PC = ram;
    STACK = ram +0xffff;
    memset((char *) ram, m_flag, 65536);
    if (l_flag)
        if (load_core())
            return (1);
    int_on();
    init_io();
    mon();
    if (s_flag)
        save_core();
    exit_io();
    int_off();
    return (0);
}