Ejemplo n.º 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;
}
Ejemplo n.º 2
0
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;
}