Ejemplo n.º 1
0
int main(void)
{
	BYTE i; 
    GOL_MSG msg;                    // GOL message structure to interact with GOL
    
    InitializeBoard();
    
	TRISGbits.TRISG3 = 1;
	TRISGbits.TRISG2 = 0;
	Nop();
	PORTGbits.RG2 = 1;
	Nop();
	
	//RADIO SETUP
	// Function MiApp_ProtocolInit initialize the protocol stack.//
 	MiApp_ProtocolInit(FALSE);
	
	//setting the frequency at whick this wx will transmit over comes back as false if the set channel fails 
	if( MiApp_SetChannel(myChannel) == FALSE )
	{
            return 0;
    }

	//Enables all connection types
 	MiApp_ConnectionMode(ENABLE_ALL_CONN);

	//try to establish connection with peer device: p1=0xff=establish connection with any device, p2=direct connection
	//returns 0xFF if it false 
	i = MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT);

	if( i == 0xFF )
   	{
		//starting a connecton: direct connect, duration of scan, channel to start connection on	
		MiApp_StartConnection(START_CONN_DIRECT, 10, 24);
	}
	//END RADIO SETUP
	
    LED = 1;
//	i2cRec(2);
	
    while(1)
    {	//i2cSend(3,2);
        if(GOLDraw())               // Draw GOL object
        {
            TouchGetMsg(&msg);      // Get message from touch screen
            GOLMsg(&msg);           // Process message
        }
        
        /* MiApp_MessageAvailable returns a bool*/
		if( MiApp_MessageAvailable() )
        {
			Incoming=*rxMessage.Payload;
			/* Function MiApp_DiscardMessage is used to release the current received packet.*/
           	MiApp_DiscardMessage();
		}
	}//end while
}
Ejemplo n.º 2
0
int main( void )
{
    GOL_MSG msg;                                    // GOL message structure to interact with GOL

    RGBMapColorPins();

    TRISBbits.TRISB1 = 0; // Debug
    LATBbits.LATB1   = 0;

    #ifdef USE_FRC
        OSCCON = 0x1102;    // Enable secondary oscillator, use FRC oscillator
        CLKDIV = 0x0000;    // FRC post-scaler (1:1), USB postscaler (1:1), CPU postscaler (1:1)
    #else
        #ifdef GO_SLOW
            OSCCON = 0x3302;    // Enable secondary oscillator, use HS oscillator
            CLKDIV = 0x0080;    // (not needed - FRC post-scaler (1:1)), USB postscaler (4:1), CPU postscaler (1:1)
        #else
            OSCCON = 0x3302;    // Enable secondary oscillator, use HS oscillator
            CLKDIV = 0x0000;    // (not needed - FRC post-scaler (1:1)), USB postscaler (1:1), CPU postscaler (1:1)
        #endif
    #endif
    RCON = 0;

    // Initialize USB Embedded Host
    USBInitialize( 0 );

    // Initialize the RTCC
    RTCCInit();

    // Initialize the graphics library
    GOLInit();

    // Initialize the touch pads.
    CTMUInit();

    // Initialize the reference timer.
    TickInit();


    while (1)
    {
        if (GOLDraw())                          // Draw the screen
        {
            TouchSenseButtonsMsg( &msg );       // Get a raw touchpad message
            if ((msg.uiEvent != EVENT_INVALID) && ((tick - displayChangeTime) > MESSAGE_DEAD_TIME))
            {
                TranslateTouchpad( &msg );      // Translate the raw message
                GOLMsg( &msg );                 // Process the message
            }
        }
    }
}
Ejemplo n.º 3
0
/************************************************************************
 Main																
 ************************************************************************/
int main( void )
{
	GOL_MSG msg;                                // Instance of GOL message structure 
												// to interact with Graphics Object layer
	    
	// Configure the Device Clock
	// Configure FRC to operate the device at 40MIPS
	// Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
	// Fosc= 7.37M*43/(2*2)=79.2275Mhz for 40MIPS input clock
	PLLFBD = 41;								// M=43
	CLKDIVbits.PLLPOST = 0;						// N1=2
	CLKDIVbits.PLLPRE = 0;						// N2=2
	OSCTUN = 0;									// Tune FRC oscillator, if FRC is used
	RCONbits.SWDTEN = 0;						// Disable Watch Dog Timer

	// Clock switch to incorporate PLL
	__builtin_write_OSCCONH(0x01);				// Initiate Clock Switch to
												// FRC with PLL (NOSC=0b001)
	__builtin_write_OSCCONL(0x01);				// Start clock switching
	while(OSCCONbits.COSC != 0b001);			// Wait for Clock switch to occur
	while(OSCCONbits.LOCK!=1);					// Wait for PLL to lock
	
	// Starter Kit initialization delay
	Delay(2000);
	
	// Initialize Speaker and Switches
	PIC24HSKInit();
       		
    // Initialize the OLED module and Microchip Graphics Library
    GOLInit();     	
	picture = &introDevice;

    while (1)
    {
        if (GOLDraw())                          // Draw the screen
        {
            AccelerometerMsg(&msg); 	      	// Get the raw accelerometer message
            if ((msg.uiEvent != EVENT_INVALID) && ((tick - displayChangeTime) > MESSAGE_DEAD_TIME))
            {
                TranslateAccelerometer(&msg);   // Translate the raw accelerometer message
                GOLMsg(&msg);                   // Process the message through to Graphics Object layer 
            }
        }
    }
}
Ejemplo n.º 4
0
void AN1227ProcessKeyBoard(void)
{
            
    // Keyboard driver
    if(GOLGetFocus() != NULL)   // if there’s a widget in focus send a message
    {

        // check if the button has changed its state
        if(GetHWButtonCR() != previousKey1State)
        {
            if(previousKey1State)
            {

                // if GetHWButtonCR equals zero it means the button is pressed
                AN1227msg.type = TYPE_KEYBOARD;
                AN1227msg.uiEvent = EVENT_KEYSCAN;

                // the focused button will receive the message
                AN1227msg.param1 = GetObjID(GOLGetFocus());
                AN1227msg.param2 = SCAN_CR_PRESSED;

            }
            else
            {

                // if GetHWButtonCR equals one it means the button is released
                AN1227msg.type = TYPE_KEYBOARD;
                AN1227msg.uiEvent = EVENT_KEYSCAN;

                // the focused button will receive the message
                AN1227msg.param1 = GetObjID(GOLGetFocus());
                AN1227msg.param2 = SCAN_CR_RELEASED;
            }                   // end of else

            // state of the button was changed
            previousKey1State = !previousKey1State;

            // pass the message to the graphics library
            GOLMsg(&AN1227msg);
        }                       // end of if
    }                           // end of if

    // check if the button has changed its state
    if(GetHWButtonFocus() != previousKey2State)
    {
        if(previousKey2State)
        {

            // if GetHWButtonFocus() equals zero it means the button is pressed
            // get the object can be focused next
            pFocusedObj = GOLGetFocusNext();

            // move focus
            GOLSetFocus(pFocusedObj);
        }
        else
        {

            // if GetHWButtonFocus()equals one it means the button is released
        }   // end of else

        // state of the button was changed
        previousKey2State = !previousKey2State;

        // pass the message to the graphics library
        GOLMsg(&AN1227msg);
    } // end of if
}         
Ejemplo n.º 5
0
int main(void)
{
    GOL_MSG msg;                    // GOL message structure to interact with GOL
    
    Nop();
    
    #if defined(PIC24FJ256DA210_DEV_BOARD)
    
    _ANSG8 = 0; /* S1 */
    _ANSE9 = 0; /* S2 */
    _ANSB5 = 0; /* S3 */
        
    #else
    /////////////////////////////////////////////////////////////////////////////
    // ADC Explorer 16 Development Board Errata (work around 2)
    // RB15 should be output
    /////////////////////////////////////////////////////////////////////////////
	#ifndef MULTI_MEDIA_BOARD_DM00123
    LATBbits.LATB15 = 0;
    TRISBbits.TRISB15 = 0;
    #endif
	#endif
    /////////////////////////////////////////////////////////////////////////////
    #if defined(__dsPIC33F__) || defined(__PIC24H__)

    // Configure Oscillator to operate the device at 40Mhz
    // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
    // Fosc= 8M*40(2*2)=80Mhz for 8M input clock
    PLLFBD = 38;                    // M=40
    CLKDIVbits.PLLPOST = 0;         // N1=2
    CLKDIVbits.PLLPRE = 0;          // N2=2
    OSCTUN = 0;                     // Tune FRC oscillator, if FRC is used

    // Disable Watch Dog Timer
    RCONbits.SWDTEN = 0;

    // Clock switching to incorporate PLL
    __builtin_write_OSCCONH(0x03);  // Initiate Clock Switch to Primary

    // Oscillator with PLL (NOSC=0b011)
    __builtin_write_OSCCONL(0x01);  // Start clock switching
    while(OSCCONbits.COSC != 0b011);

    // Wait for Clock switch to occur	
    // Wait for PLL to lock
    while(OSCCONbits.LOCK != 1)
    { };
    
    // Set PMD0 pin functionality to digital
    AD1PCFGL = AD1PCFGL | 0x1000;
    
    #elif defined(__PIC32MX__)
    INTEnableSystemMultiVectoredInt();
    SYSTEMConfigPerformance(GetSystemClock());
    #ifdef MULTI_MEDIA_BOARD_DM00123
    CPLDInitialize();
    CPLDSetGraphicsConfiguration(GRAPHICS_HW_CONFIG);
    CPLDSetSPIFlashConfiguration(SPI_FLASH_CHANNEL);
    #endif // #ifdef MULTI_MEDIA_BOARD_DM00123
    #endif // #if defined(__dsPIC33F__) || defined(__PIC24H__)

    GOLInit();                      // initialize graphics library &
                                    // create default style scheme for GOL

    #if defined (GFX_PICTAIL_V1) || defined (GFX_PICTAIL_V2)
    EEPROMInit();                   // initialize Exp.16 EEPROM SPI
    BeepInit();
    #else
	    #if defined (USE_SST25VF016)
            SST25Init();            // initialize GFX3 SST25 flash SPI
        #endif
    #endif
    
    TouchInit();                    // initialize touch screen
    HardwareButtonInit();           // Initialize the hardware buttons

    // create default style scheme for GOL
    TickInit();                     // initialize tick counter (for random number generation)

    // create default style scheme for GOL
    #if defined(__dsPIC33FJ128GP804__) || defined(__PIC24HJ128GP504__)

    // If S3 button on Explorer 16 board is pressed calibrate touch screen
    TRISAbits.TRISA9 = 1;
    if(PORTAbits.RA9 == 0)
    {
        TRISAbits.TRISA9 = 0;
        TouchCalibration();
        TouchStoreCalibration();
    }

    TRISAbits.TRISA9 = 0;
	#else

	    /**
	     * Force a touchscreen calibration by pressing the switch
	     * Explorer 16 + GFX PICTail    - S3 (8 bit PMP)
	     * Explorer 16 + GFX PICTail    - S5 (16 bit PMP)
	     * Starter Kit + GFX PICTail    - S0 (8 bit PMP)
	     * Multimedia Expansion Board   - Fire Button
	     * DA210 Developement Board     - S1
	     * NOTE:    Starter Kit + GFX PICTail will switches are shared
	     *          with the 16 bit PMP data bus.
	     **/
	    if(GetHWButtonTouchCal() == HW_BUTTON_PRESS)
	    {
	        TouchCalibration();
	        TouchStoreCalibration();
	    }
    #endif

    // If it's a new board (EEPROM_VERSION byte is not programed) calibrate touch screen
    #if defined (GFX_PICTAIL_V1) || defined (GFX_PICTAIL_V2)
    if(GRAPHICS_LIBRARY_VERSION != EEPROMReadWord(ADDRESS_VERSION))
    {
        TouchCalibration();
        TouchStoreCalibration();
    }

    #else
        #if defined (USE_SST25VF016)
        if(GRAPHICS_LIBRARY_VERSION != SST25ReadWord(ADDRESS_VERSION))
        {
            TouchCalibration();
            TouchStoreCalibration();
        }
        #elif defined (USE_SST39LF400)
        WORD tempArray[12], tempWord = 0x1234;

        SST39LF400Init(tempArray);
        tempWord = SST39LF400ReadWord(ADDRESS_VERSION);
        SST39LF400DeInit(tempArray);

        if(GRAPHICS_LIBRARY_VERSION != tempWord)
        {
            TouchCalibration();
            TouchStoreCalibration();
        }
        #endif
    #endif

    // Load touch screen calibration parameters from memory
    TouchLoadCalibration();

    GDDDemoCreateFirstScreen();

    while(1)
    {
        if(GOLDraw())               // Draw GOL object
        {
            TouchGetMsg(&msg);      // Get message from touch screen
			
            #if (NUM_GDD_SCREENS > 1)
			// GDD Readme:
			// The following line of code allows a GDD user to touch the touchscreen
			// to cycle through different static screens for viewing. This is useful as a
			// quick way to view how each screen looks on the physical target hardware.
			// This line of code should eventually be commented out for actual development.
			// Also note that widget/object names can be found in GDD_Screens.h
			if(msg.uiEvent == EVENT_RELEASE) GDDDemoNextScreen();
			#endif
			
            GOLMsg(&msg);           // Process message
        }
    }//end while
}