Example #1
0
int main(int argc, char* argv[]) {
	int fd;

	unsigned char arr2dim[8][8] = {{0,1,0,1,0,1,0,1},
			{1,0,1,0,1,0,1,0},
			{0,1,0,1,0,1,0,1},
			{1,0,1,0,1,0,1,0},
			{0,1,0,1,0,1,0,1},
			{1,0,1,0,1,0,1,0},
			{0,1,0,1,0,1,0,1},
			{1,0,1,0,1,0,1,0},
	};
	unsigned char arr2dim2[8][8] = {{1,0,1,0,1,0,1,0},
			{0,1,0,1,0,1,0,1},
			{1,0,1,0,1,0,1,0},
			{0,1,0,1,0,1,0,1},
			{1,0,1,0,1,0,1,0},
			{0,1,0,1,0,1,0,1},
			{1,0,1,0,1,0,1,0},
			{0,1,0,1,0,1,0,1},
	};

	fd = initi2c(); // init communication

	while (1) {
			printArray(fd,arr2dim);
			usleep(10000);
			printArray(fd,arr2dim2);
			usleep(10000);
	}

	return 0;
}
Example #2
0
/******************************************************************************
 * Function:        void main(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Main program entry point.
 *
 * Note:            None
 *****************************************************************************/
void main(void)
{
 
//do some startup tasks...

		InitializeSystem();


//small delay for things to cook up


	for (b=0;b<1026;b++)
			{
				Delay1KTCYx(1);
			}



//start I2C system at 100 Khz speed
	initi2c();


//board default configuration registers are changed here
//make changed to loafconfigfriendly for a more friendly version
 loadconfig();


//
//setup your IO configuration
//
// NOTE: you should change this 1st before anything else
// this allows you to change ports to input, output, or analog
// this function is in user.c
//
loadconfigfriendly();


for (c=0;c<10;c++)
{

//small delay for things to cook up
	for (b=0;b<1036;b++)
			{
				Delay1KTCYx(10);
			}
}

//start the USART module at 57600 buad rate
	startUsart(200000);  


//small delay for things to cook up
	for (b=0;b<1026;b++)
			{
				Delay1KTCYx(10);
			}



//test xbee module at given baudrate of 57600
	if (testxbee())
	{

		//57600 baud failed so lets test to see if its a new module
		//start the USART module at 9600 buad rate
		startUsart(9600);  

		//small delay for things to cook up
		for (b=0;b<1060;b++)
		{
			Delay1KTCYx(1);
		}
		//testing xbee at 9600 baudrate
		if (testxbee())
		{

		//LOOP FOR NO XBEE MODULE FOUND (FAILED AT BOTH BAUDRATES)
		//xbee module failed at 9600 baud so no module present at either baudrate
		//new modules come with a 9600 baud rate by default.
		//
		//this is the no module operating code in here, put what you want when no module present
		//can use as a regular controller or PLC.
			//
			//	NO XBEE MODULE FOUND MAIN LOOP STARTS HERE
			//

			mInitializeUSBDriver(); 


			for(c=0;c<60;c++)
			{
				for (b=0;b<1060;b++)
				{
					Delay1KTCYx(1);
					USBTasks(); 
					ProcessIO(); 
				}
			}



			while(1)
			{
				//small delay so dont roast the USB system too much 
				Delay1KTCYx(10);

				//USB polling tasks optional

				for (b=0;b<1060;b++)
				{
					Delay1KTCYx(1);
					USBTasks(); 
					ProcessIO(); 
				}


		
			//
			//  NO XBEE MODULE FOUND MAIN LOOP ENDS HERE
			//
			} //end no xbee found main loop
//END LOOP
		}
		//found module at 9600 baud rate
        //
        //now we will change the baud rate to 57600 in the module to speed things up
		else
		{
				//small delay for things to cook up
				for (b=0;b<1060;b++)
				{
					Delay1KTCYx(20);
				}


			//change xbee module to 57600 baud rate
			changebaudrate();

			//start the USART module at 57600 buad rate
			startUsart(200000);

			for (c=0;c<30;c++)
			{

				//small delay for things to cook up
				for (b=0;b<3000;b++)
				{
					Delay1KTCYx(1);
				}
			}

	   	

			//initialize xbee module to the paramters specified in the following function
			//
			// NOTE: you need to edit this function to tailor this node's network parameters and such
			// this function is found in user.c
      		//			

			initxbee();

		}

	}
	//found xbee module at 57600 baud rate
	else
	{
		//initialize xbee module to the paramters specified in the following function
		//
		// NOTE: you need to edit this function to tailor this node's network parameters and such
		// this function is found in user.c
        //

		//small delay for things to cook up
		for (b=0;b<1026;b++)
			{
				Delay1KTCYx(10);
			
			}


		initxbee();
	}
	


	


	//configure xbee sleep mode here but it is not written to non volatile memory
 	//since may have problems re-entering command mode later on!!
    //sleep_config_xbee();





//put xbee to not pin sleep 
	xbee_sleep=0; //put module to not sleep!! (edge triggeered wakeup)





//shutoff USB module to save 8 mA current
//...uncomment to turn module off

//		UCONbits.USBEN=0;
//		UCONbits.SUSPND=1;	


//uncomment to turn USB on
   		mInitializeUSBDriver(); 
//end usb turn on



	for(c=0;c<40;c++)
	{
		for (b=0;b<1060;b++)
		{
				Delay1KTCYx(1);
				USBTasks(); 
				ProcessIO(); 
		}
	}



// set processor primary idle mode (not sleep!!)
//	  	OSCCONbits.IDLEN=1;


//start timer 1 to time periodic functions
  		starttimer();


//start USART receive interrupt
		PIE1bits.RCIE=1;



//MAIN LOOP FOR XBEE MODULE NORMAL
	//
	//	START MAIN LOOP FOR XBEE MODULE FOUND AT 200 K BAUD AND INTIALIZED TO YOUR PARAMETERS
	//



    while(1)
    {

	
		//loop to service USB requests (polling)
		for (b=0;b<1060;b++)
		{
				Delay1KTCYx(1);

		//service USB tasks
				USBTasks(); 
				ProcessIO(); 
		}

	}//end while

	//
	//  END MAIN LOOP FOR XBEE MODULE FOUND AT 57600 BAUD AND INITIALIZED TO YOUR PARAMETERS
	//
//END LOOP


}//end main
Example #3
0
// main
int main(void)
{
    // stop watchdog timer
    WDTCTL = WDTPW + WDTHOLD;

    //Initialize clock and peripherals
    halBoardInit();
    halBoardStartXT1();
    halBoardSetSystemClock(SYSCLK_16MHZ);

    // init debug UART
    halUsbInit();

    // init LEDs
    P1OUT |= LED_1 | LED_2;
    P1DIR |= LED_1 | LED_2;

    /*//init linkLED
    P1OUT &= ~BIT0;
    P1DIR |= BIT0;*/

    //Setup Input Port 2
    initSwitch(2, BIT0);
    initSwitch(2, BIT1);
    initSwitch(2, BIT2);
    initSwitch(2, BIT3);

    //tie port3 and unused pins of port 2
    /*P3OUT = 0;
    P3DIR = 0xFF;
    P3SEL = 0;
    P2OUT &= 0x0F;
    P2DIR |= 0xF0;
    P2SEL &= 0x0F;*/


	/// GET STARTED with BTstack ///
	btstack_memory_init();
    run_loop_init(RUN_LOOP_EMBEDDED);

    // add gpio port 2 to run loop
    // default values
    port2_status = P2IN & 0x0F;

    data_source_t data_src_port2;
    data_src_port2.process = port2_poll;
    data_src_port2.fd = 0;
    run_loop_add_data_source(&data_src_port2);


    // init HCI
	hci_transport_t    * transport = hci_transport_h4_dma_instance();
	bt_control_t       * control   = bt_control_cc256x_instance();
    hci_uart_config_t  * config    = hci_uart_config_cc256x_instance();
    remote_device_db_t * remote_db = (remote_device_db_t *) &remote_device_db_memory;
	hci_init(transport, config, control, remote_db);

    // use eHCILL
    bt_control_cc256x_enable_ehcill(1);

    // init L2CAP
    l2cap_init();
    l2cap_register_packet_handler(bt_packet_handler);
    l2cap_register_service_internal(NULL, l2cap_packet_handler, 0x1001, L2CAP_MINIMAL_MTU);

    // ready - enable irq used in h4 task
    __enable_interrupt();

 	// turn on!
	if(hci_power_control(HCI_POWER_ON))
		printf("power on failed");

	//init i2c
	initi2c();

    // go!
    run_loop_execute();

    // happy compiler!
    return 0;
}