void delayNoInt(uint16_t delay){
	//	DI();
	//	for ( ; delay > 0 ; delay--);
	//	EI();
	startTMR0(delay); // Start timer with delay value
	while(TMIF00 == 0) // Wait for timer flag
		NOP();
	R_TAU0_Channel0_Stop(); // Stop timer and clear all flags
	EI();
}
void SpeakerOFF()
{
    R_TAU0_Channel0_Stop();
}
/***********************************************************************************************************************
* Function Name: main
* Description  : This function implements main function.
* Arguments    : None
* Return Value : None
***********************************************************************************************************************/
void main(void)
{
    R_MAIN_UserInit();
    /* Start user code. Do not edit comment generated here */

    int transmit_count = 0;
	R_UART2_Create();
	R_UART2_Start();
	uart2Status = R_UART2_Receive(&uart2RxBuf[0],1);	// Prime UART2 Rx

	R_TAU0_Create();
	R_TAU0_Channel0_Start();

	R_PORT_Create();

	R_ADC_Create();

	while (1U)
	{
		if(oneSec)
		{
			if(transmit)
				uart2Status = R_UART2_Send(uart2TxBuf, 1);

			counter++;
			oneSec = !oneSec;
		}

		if(uart2RxFlag)
		{
			uart2RxFlag = 0U;

			if(uart2RxBuf[0] == 'b')
			{
				uart2TxBuf[0] = counter;
				transmit_count = convertToNum(uart2TxBuf); //convert the ASCII symbols to integers instead.
				uart2Status = R_UART2_Send(uart2TxBuf, transmit_count);
			}
			else
			if(uart2RxBuf[0] == 'l')
				P7_bit.no7 = !P7_bit.no7;
			else
			if(uart2RxBuf[0] == 'a')
			{
				uint8_t adcvalue = 0;
				R_ADC_Start();
				while(!adc_done_flag); //wait for interrupt
				adc_done_flag = 0;
				R_ADC_Get_Result_8bit(&adcvalue);
				uart2TxBuf[0] = adcvalue;
				transmit_count = convertToNum(uart2TxBuf); //convert the ASCII symbols to integers instead.
				R_ADC_Stop();
				uart2Status = R_UART2_Send(uart2TxBuf, transmit_count);
			}
			else
			if(uart2RxBuf[0] == 't')
				transmit = !transmit;
			else
				uart2TxBuf[0] = uart2RxBuf[0];

			// Prime UART2 Rx
			uart2Status = R_UART2_Receive(uart2RxBuf, 1);
		}

		//If a character has been transmitted
		if (uart2TxFlag)
		{
			// End of UART2 transmit
			uart2TxFlag = 0U;   // clear tx flag
		}
	}

	R_UART2_Stop();
	R_TAU0_Channel0_Stop();
	//R_ADC_Stop();
	/* End user code. Do not edit comment generated here */
}