Esempio n. 1
0
int main(void)
{
	int i = 0;
    //Initialise the FRDM-KL26Z Board
	hardware_init();
	adc0_config(SW_TRIGGER,BIT16,ADC_INTERRUPT_DISABLED);
	PIT_Configure_interrupt_mode(2);// 2 second interrupt
	PRINTF("~~~Starting ADC read~~~\r\n");
    while(1) {

    }
    /* Never leave main */
    return 0;

}
Esempio n. 2
0
int main(void)
{

    //Initialise the FRDM-KL26Z Board
	hardware_init();
	FRDM_KL26Z_LEDs_Configure();
	PIT_Configure_interrupt_mode(2);
	PRINTF("ADC  new TESTING\r\n");
	adc_config_with_software_trigger();

    while(1) {
    	//enable adc clock SIM_SCGC6 bit 27 for ADC0
    	//configure adc trigger in SIM_OPT7 if using h/w triggers
    	//configure ADC1_CFG1 to configure clock and # of conversion bits
    	//configure ADC1_SC2 for h/w s/w trigger
    	//write to ADC1_SCA register to configure interrupt, channel and source type
    }
    /* Never leave main */
    return 0;
}
Esempio n. 3
0
int main()
{
	char * AT = "AT\r\n";//Setting up a char variable AT for the a long string
	char response[20]; //A character buffer called response that can hold 20 characters
	int result = 0;	//int result to check the value of the response sent back
	int transmit_send = 0;
	volatile int CurrentTick;	//Volitile interger to hold the current tick count of the current time
	char * ptr;	//Character
	char * stat;
	enum STATES {INIT};
	enum STATES CurrentState = INIT;
	buffer_init();
	hardware_init();
	enable_UART0_receive_interrupt();
	PIT_Configure_interrupt_mode(1);
	while(1)
	{
		switch(CurrentState)
		{
		case INIT:	//Check connection to MODEM by sending AT. Expected response is OK
			result = send_command(AT, response, sizeof(response), 2000);
			if(result == SUCCESS || result == ERROR)
			{
				printf_response(response);
			}
			if(result == SUCCESS)	//"OK" was returned by MODEM
				PRINTF("It Worked");
			else	//incorrect response or timeout. Delay and try again
			{
				CurrentTick = tick_count;
				while((tick_count - CurrentTick) < 5)
				{}
			}
			break;

		default:
			break;
		}//end switch-case
	}
}
Esempio n. 4
0
int main (){

	int x;
	//char * ptr;
	char * AT = "\r\nAT\r\n";
	char * PIN_CHECK = "\r\nAT+CPIN?\r\n";
	char * ENTER_PIN = "\r\nAT+CPIN=\"1234\"\r\n";
	char * CREG = "\r\nAT+CREG?\r\n";
	char response[20];

	char * ptr;
	enum STATES {INIT, CHECK_PIN, SEND_PIN, CHECK_NETWORK_REG, SEND_SMS, CONNECTED};
	enum STATES CurrentState = INIT;

	hardware_init();
	enable_UART0_receive_interrupt();
	buffer_init();
	PIT_Configure_interrupt_mode(1);    //PIT interrupt every second
	enable_UART0_receive_interrupt();

	PRINTF("\nGSM Modem Control\n");
	//Configuration

	while(1)
	{
		switch(CurrentState)
		{
		case INIT:  //Check connection to MODEM by sending AT. Expected response is OK
			PRINTF("Testing Modem Connection\n");
			result = send_command(AT, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				printf_response(response);
			}
			if(result == SUCCESS)   //"OK" was returned by MODEM
				CurrentState = CHECK_PIN;
			else    //incorrect response or timeout. Delay and try again
			{
				CurrentTick = tick_count;
				while((tick_count - CurrentTick) < 5)
				{}
			}
			break;

		case CHECK_PIN: //Check if SIM card is ready
			result = send_command(PIN_CHECK, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				printf_response(response);
			}
			if(result == SUCCESS)   //"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				if(strstr(response, "READY")) //if ready ok is typed into terminal
				{

					CurrentState = CHECK_NETWORK_REG; //move to check_network_reg
				}
				else if(strstr(response, "SIM_PIN")) // sim_pin ok entered
				{

					CurrentState = SEND_PIN; //move to send_pin
				}
			}
			else
				CurrentState = INIT;
			break;

		case SEND_PIN:  //Send PIN code. "OK" response if PIN is correct
			result = send_command(ENTER_PIN, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				printf_response(response);
			}
			if(result==SUCCESS) //if logic '0'
					{
				//if(strstr(response, ""))
				CurrentState = CHECK_NETWORK_REG; //move to check_network_reg
					}
			else
			{
				CurrentState = CHECK_PIN; //if '-1' move back to check_pin again
			}
			break;


		case CHECK_NETWORK_REG: //check if registered on mobile network
			result = send_command(CREG, response, sizeof(response), 20);
			if(result == SUCCESS || result == ERROR)
			{
				printf_response(response);
			}
			if(result==SUCCESS)
			{
				if(strstr(response,"+CREG")) //if +creg entered
						{
					ptr = (char*)strchr(response,':');//point to the colon
					ptr+=4; //move 4 places
					switch(*ptr)//switch contents of address pointed to
					{
					case '1'://if  +creg: 0,1 entered
						CurrentState = INIT;// move back to init
						PRINTF("Invalid;Try again");
						break;
					case '2'://if  +creg: 0,2 entered
						CurrentState = SEND_SMS;//move to send_sms
						PRINTF("Proceed to send SMS");
						break;
					case '3'://if  +creg: 0,3 entered
						CurrentTick = tick_count;//wait for "network"
						while((tick_count - CurrentTick) < 5)
						{}
						PRINTF("Checking for Network, Please Wait");
						break;
					case '4'://if  +creg: 0,4 entered
						CurrentState = INIT;//move back to init
						PRINTF("Invalid,Try Again");
						break;
					case '5': //if  +creg: 0,5 entered
						CurrentState = SEND_SMS;//send sms
						PRINTF("Proceed to send SMS");
						break;
					default:
						CurrentState = INIT;
						PRINTF("Invalid,Try Again");
						break;
					}
						}
				else
				{
					CurrentState = INIT;
				}
				printf_response(response);
				break;

		case SEND_SMS:  //Send a text message
			send_sms("\"0871234567\"","\"Testing 123\""); //send number

			send_sms("\"0171112233\"","\"Success\""); // the message
			if(result==SUCCESS) // if logic '0'
			{
				PRINTF("Message has been sent");
				CurrentState = CONNECTED;//move to connected
				break;
			}
			else
			{
				CurrentTick = tick_count;// wait for input
				while((tick_count - CurrentTick) < 5)
				{}
				break;
			}
		case CONNECTED:
			while(1)    //dummy loop
			{}
			break;
		default:
			break;
			}//end switch-case
		}//end while(1)
	}
}
int main()
{

	volatile int temp;
	volatile int rand_no;
	int x;

	hardware_init();

	FRDM_KL26Z_LEDs_Configure();

	FRDM_KL26Z_SW2_Configure(0,FALLING_EDGE);
	FRDM_KL26Z_SW1_Configure(PULLUP,FALLING_EDGE);

	PIT_Configure_interrupt_mode(0.01);

	NVIC_ClearPendingIRQ(31);
	NVIC_EnableIRQ(31);

	LED_set(GREEN,OFF);

	while(1)
	{
		switch(currentstate)
		{
		case INIT:
			sw_count=0;
			sw2_count=0;
			PRINTF("SW1 to start");
			while(sw_count==0)
			{}
			LED_set(GREEN,OFF);
			currentstate = PLAY;
			break;
		case PLAY:
			PRINTF("when led on, press sw2");
			srand(timer_tick);
			rand_no = rand()%5000;
			temp=timer_tick;

			while((timer_tick-temp<rand_no) && (sw2_count==0) )
			{}
			if(sw2_count>0)
			{
				currentstate=INIT;
				break;
			}
			LED_set(GREEN,ON);
			temp=timer_tick;
			while(((sw2_count==0)&&timer_tick-temp<5000))
			{}
			if(timer_tick-temp>=5000)
			{
				PRINTF("too slow");
				currentstate=INIT;
			}
			else
			{
				PRINTF("reaction time: %d MSec \n" ,(timer_tick-temp));
				LED_set(GREEN,OFF);
				currentstate = INIT;
			}
			break;
		default:
			break;

		}
	}

	return 0;
}
Esempio n. 6
0
int main()
{

	char * AT = "\r\nAT\r\n";//Setting up a char variable AT for the a long string
	char * PIN_CHECK = "\r\nAT+CPIN?\r\n";//Setting up a char variable PIN_CHECK for the a long string
	char * ENTER_PIN = "\r\nAT+CPIN=\"1234\"\r\n";//Setting up a char variable ENTER_PIN for the a long string
	char * CREG = "\r\nAT+CREG?\r\n";//Setting up a char variable CREG for the a long string
	char response[20]; //A character buffer called response that can hold 20 characters
	int result = 0;	//int result to check the value of the response sent back
	int transmit_send = 0;
	volatile int CurrentTick;	//Volitile interger to hold the current tick count of the current time
	char * ptr;	//Character
	char * stat;
	enum STATES {INIT, CHECK_PIN, SEND_PIN, CHECK_NETWORK_REG, SEND_SMS, CONNECTED};
	enum STATES CurrentState = INIT;
	uart_state_t uartState; // user provides memory for the driver state structure
	uart_user_config_t uartConfig;
	buffer_init();
	hardware_init();
	//UART0_config();
	PIT_Configure_interrupt_mode(1);
	configure_uart_pins(0);	//instance 0 is UART1???
	// Call OSA_Init to setup LP Timer for timeout
	OSA_Init();


	uartConfig.baudRate = 9600;
	uartConfig.bitCountPerChar = kUart8BitsPerChar;
	uartConfig.parityMode = kUartParityDisabled;
	uartConfig.stopBitCount = kUartOneStopBit;

	UART_DRV_Init(1, &uartState,&uartConfig);
	//PRINTF("UART0 Test Code\n\r");
	//PRINTF("Any entered character will be echoed\r\n\n");
	while(1)
	{
		switch(CurrentState)
		{
		case INIT:	//Check connection to MODEM by sending AT. Expected response is OK
			printf("Testing Modem Connection\n");
			result = send_command(AT, response, sizeof(response), 2000);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" was returned by MODEM
				CurrentState = CHECK_PIN;
			else	//incorrect response or timeout. Delay and try again
			{
				CurrentTick = tick_count;
				while((tick_count - CurrentTick) < 5)
				{}
			}
			break;

		case CHECK_PIN:	//Check if SIM card is ready
			result = send_command(PIN_CHECK, response, sizeof(response), 10);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				if(strstr(response, "READY"))
				{
					CurrentState = CHECK_NETWORK_REG;
				}
				else if(strstr(response, "SIM PIN"))
				{
					CurrentState = SEND_PIN;
				}
			}
			else
				CurrentState = INIT;
			break;

		case SEND_PIN:	//Send PIN code. "OK" response if PIN is correct
			result = send_command(ENTER_PIN, response, sizeof(response),10);
			if(result == SUCCESS || result == ERROR)
			{
				//printf_response(response);
			}
			if(result == SUCCESS)	//"OK" returned, check response string for "READY" or "SIM_PIN"
			{
				CurrentState = CHECK_NETWORK_REG;
			}
			else
				CurrentState = INIT;
			break;


		case CHECK_NETWORK_REG:	//check if registered on mobile network
			result = send_command(CREG, response, sizeof(response), 20);
			if(strstr(response, "+CREG"))
			{
				stat = (char *)strstr(response,":");
				stat += 4;
				switch(*stat)
				{
				case '0':
					CurrentState = INIT;
					break;
				case '1':
					CurrentState = SEND_SMS;
					break;
				case '2':
					CurrentTick = tick_count;
					while((tick_count - CurrentTick) < 5)
					{}
					CurrentState = CHECK_NETWORK_REG;
					break;
				case '3':
					CurrentState = INIT;
					break;
				case '4':
					CurrentState = CONNECTED;
					break;
				case '5':
					CurrentState = SEND_SMS;
					break;

				}
			}


		case SEND_SMS:	//Send a text message
			transmit_send = send_sms("\"0877763894\"","\"Testing 123		\"");
			if(transmit_send == SUCCESS)
			{
				CurrentState = CONNECTED;
			}
			else if(transmit_send == FAIL)
			{
				printf("A transmission fail has been detected or you have timed out\r\n");
				CurrentState = SEND_SMS;
			}
			else if(transmit_send == ERROR)
			{
				printf("A transmission ERROR has been detected,rebooting\r\n");
				CurrentState = INIT;
			}
			break;

		case CONNECTED:
			printf("\nInside Connected \r\n");
			while(1)	//dummy loop
			{}
			break;

		default:
			break;
		}//end switch-case
	}
}