예제 #1
0
int main(void) {
	u8 Local_u8SwitchValue; // to store the Switch Value
	u8 Local_u8SwitchFlag = FALSE; // to run the switch in the single mode

	u16 Local_u16ADCValue; // to store the ADC Value
	u16 Local_u16PrevADCValue = 2000; // to store the Previous ADC Value
	f32 Local_f32VoltageValue;
	u8 Local_u8Buffer[5]; // to store the Volt value as characters

	DIO_voidInit();
	ADC_voidInit();
	ADC_voidEnable();
	LCD_voidInit();
	LCD_u8Write_String("Voltage:");
	//LCD_u8Write_Command(0x80); //go to First line and --0 is for 0th position
	while (1) {

		TSW_u8CheckSwitch(TSW_u8NUM1, &Local_u8SwitchValue);
		if (Local_u8SwitchValue == TSW_u8PRESSED) {
			if (!Local_u8SwitchFlag) {
				Local_u8SwitchFlag = TRUE;
				DIO_u8WritePinVal(RELAYCONTROL, DIO_u8HIGH);
			}

		} else { //Local_u8SwitchValue == TSW_u8RELEASED
			if (Local_u8SwitchFlag) {
				Local_u8SwitchFlag = FALSE;
				DIO_u8WritePinVal(RELAYCONTROL, DIO_u8LOW);
			}
		}
		//ADC_u8ReadChannel(ADC_u8CH7, &Local_u16ADCValue);
		ADC_u8ReadChannelFiltered(ADC_u8CH7, &Local_u16ADCValue);
		if (Local_u16ADCValue == Local_u16PrevADCValue) {
		} else { //Local_u16ADCValue != Local_u16PrevADCValue
			Local_u16PrevADCValue = Local_u16ADCValue;
			CalculateVlotage(Local_u8SwitchFlag, Local_u16ADCValue, &Local_f32VoltageValue);
			ftoa(Local_u8Buffer, Local_f32VoltageValue, 2);
			//Local_f32VoltageValue = Local_u16ADCValue * ADC_STEP;
//			Local_u8IntVoltageValue = Local_f32VoltageValue;
//			itoa(Local_u8IntVoltageValue, Local_u8PotienoValue, 10);
//			LCD_u8Write_Command(0xC0); //go to Second line and --0 is for 0th position
			//dtostrf(value, width, precision, char array)
			LCD_u8Write_Command(0xC0); //go to Second line and --0 is for 0th position
			LCD_u8Write_String(Local_u8Buffer);
			LCD_u8Write_String("  ");
//			LCD_u8Write_String(".");
//			Local_f32VoltageValue = Local_f32VoltageValue - Local_u8IntVoltageValue;
//			Local_u8IntVoltageValue = 100 * Local_f32VoltageValue;
//			itoa(Local_u8IntVoltageValue, Local_u8PotienoValue, 10);
//			LCD_u8Write_String(Local_u8PotienoValue);
		}
	}
	return 0;
}
예제 #2
0
int main (void)
{
	u16 local_u8AdcRead=0 ,local_u8OldAdcRead=1 ;
	u8 local_u8AdcStr[2],local_u8CountStr[2];
	u8	THR_COUNT= 0 , Old_THR_COUNT= 1 , THR_FLAG=0;
	DIO_voidInit();
	ADC_voidInit();
	CLC_voidInit();
	ADC_voidEnable();
while(1)
	{

		TSEN_u8ReadTSensr(0,&local_u8AdcRead);

	    if( local_u8AdcRead > (TSEN_u8THRSHOLD - TSEN_u8TOLERANCE) && THR_FLAG==0  )
	    {
	    	BUZ_voidBuzOn();
	    	THR_COUNT++;
	    	THR_FLAG=1 ;

	    	if(THR_COUNT>100)
	    		THR_COUNT=0 ;
	    }
	    else if( local_u8AdcRead < (TSEN_u8THRSHOLD - TSEN_u8TOLERANCE)  )
	    {
	    	BUZ_voidBuzOff();
	    	THR_FLAG=0;
	    }



	    if(THR_COUNT != Old_THR_COUNT || local_u8AdcRead != local_u8OldAdcRead)
	    {
	    	CLCD_u8WriteComand( CLC_u8CLRDISP);
	    	CLCD_u8WriteComand(CLC_u8STL);

	    	itoa(local_u8AdcRead,local_u8AdcStr,10);
	    	CLCD_u8WriteDataStr(local_u8AdcStr) ;

	    	CLCD_u8WriteComand(CLC_u8NEWL );

	    	itoa(THR_COUNT,local_u8CountStr,10);
	    	CLCD_u8WriteDataStr(local_u8CountStr);


	    	local_u8OldAdcRead = local_u8AdcRead ;
	    	Old_THR_COUNT=THR_COUNT ;
	    }
	}

return 0;
}
예제 #3
0
파일: main.c 프로젝트: mamdooh133/my-Work
void main ()
{

	DIO_voidInit();
	CLC_voidInit();
	TSW_voidinit() ;
	ADC_voidInit();
	ADC_voidEnable();


	while(1)
	{

		Read_sw();
	}
}
예제 #4
0
파일: main.c 프로젝트: BelalElkady/MyWork
void main(void) {

	u16 Local_u8ADCReading;
	u16 Local_u8LCDresult[5];
	u8 Local_u8SW;
	u8 Local_u8ADCanalog;
	DIO_voidInit();
	TACTILE_voidInit();
	ADC_voidConfig();
	ADC_voidEnable();
	LCD_voidInit();

	while (1) {

		ADC_voidReadSingleShot(&Local_u8ADCReading);
		DIO_u8ReadPinVal(DIO_u8PIN31, &Local_u8SW);
        Local_u8ADCanalog=((Local_u8ADCReading>>6)*(u16)5)/(u16)1024;
		switch (Local_u8SW) {
		case TACTILE_u8Pressed:
			DIO_u8WritePinVal(DIO_u8PIN27, 1);
			itoa(Local_u8ADCanalog+5, Local_u8LCDresult, 10);
			LCD_voidWriteString(Local_u8LCDresult);
			delay_ms(5);
			break;
		case TACTILE_u8Released:
			DIO_u8WritePinVal(DIO_u8PIN27, 0);
			itoa(Local_u8ADCanalog, Local_u8LCDresult, 10);
			LCD_voidWriteString(Local_u8LCDresult);
			delay_ms(5);
			break;

		}

		LCD_voidClearSceen();


	}

	return;
}