コード例 #1
0
ファイル: main.c プロジェクト: mohamed-selim-a/avr-calculator
void calculateResult()
{
	long x,y;
	if(stack_isempty(sd1))
	{
		x=result;
	}
	else
	{
		x=get_value_of_stack(sd1);
	}
	y=get_value_of_stack(sd2);

	//do the operation
	switch (operator)
	{
	case 0:
		result = x + y;
		break;
	case 1:
		result = x-y;
		break;
	case 2:
		result = x*y;
		break;
	case 3:
		result = x/y;
		break;
	}

	//display
//	if(stack_isempty(sd1))
//	{
		LCD_Clear();
		LCD_Gotoxy(0,0);
		char* d=(char*)malloc(digitsLength);
		LCD_SendStr(itoa(result, d, 10));

		_log("operator \0") _log1(ops[operator]) _log("\r\0")
		_log("result \0") _log(d) _log("\r\0")
//	}
//	else
//	{
//		LCD_Clear();
//		LCD_Gotoxy(0,0);
//		char* d1=(char*)malloc(digitsLength);
//		LCD_SendStr(itoa(x, d1, 10));
//		LCD_SendData(ops[operator]); //error send the op as char not int
//		char* d2=(char*)malloc(digitsLength);
//		LCD_SendStr(itoa(y, d2, 10));
//	}

	//clear stacks
	stack_Clear(sd1);
	stack_Clear(sd2);
}
コード例 #2
0
ファイル: LCD_VP.c プロジェクト: Freerider82/ChargeAVR
void showWinSettings(uint8_t x,uint8_t y ,uint16_t value){
	LCD_ClearField(x,y,16);
	LCD_Goto(x,y);
	switch(value){
		case DISPLAY_P0:
			LCD_SendStr(" U off");
			break;
		case DISPLAY_P1:
			LCD_SendStr(" U discharge");
			break;	
		case DISPLAY_P2:
			LCD_SendStr(" I discharge");
			break;
		case DISPLAY_P3:
			LCD_SendStr(" I charge");
			break;
		case DISPLAY_P4:
			LCD_SendStr(" Mode A or M");
			break;
		case DISPLAY_P5:
			LCD_SendStr(" N Disch_Charge");
			break;
	}
}
コード例 #3
0
ファイル: LCD_VP.c プロジェクト: Freerider82/ChargeAVR
void showAndSetValue(uint8_t display ,volatile uint16_t *array,volatile uint8_t *array8){	
	
	switch(display){
		
		case DISPLAY_START:
			{
				volatile uint16_t time=(array8[charge])? chargeTime:dischargeTime;
				volatile uint8_t index=(array8[charge])? oldChargeTime:oldDischargeTime;
				
				if(array[index]!=time){
					array[index]=time;
					showTime(8,1,time);
				}
			}			
			if(array[oldCurrentVoltage]!=array[currentVoltage]){
				array[oldCurrentVoltage]=array[currentVoltage];
				showADC(2,0,array[currentVoltage]);				
			}			
			if(array[oldCurrentAmperage]!=array[currentAmperage]){
				array[oldCurrentAmperage]=array[currentAmperage];
				LCD_Goto(2,1);
				volatile uint8_t ch=(array8[charge])? '+':'-';								
				LCD_WriteData(ch);				
				showADC(3,1,array[currentAmperage]);
			}
			if(array[oldCurrentPWM]!=array[currentPWM]){
				array[oldCurrentPWM]=array[currentPWM];
				showPWM(10,0,array[currentPWM]);
				setPwm(array[currentPWM]);
			}	
			if(array8[oldNumDischargeCharge]!=array8[numDischargeCharge]){
				array8[oldNumDischargeCharge]=array8[numDischargeCharge];
				LCD_Goto(14,0);
				LCD_SendNumber(array8[numDischargeCharge],' ');
			}		
		break;
		case DISPLAY_FAST_CHANGE:
			if(array8[oldCharge]!=array8[charge]){
				array8[oldCharge]=array8[charge];	
				LCD_ClearField(0,1,9);			
				LCD_Goto(0,1);
				if(array8[charge]){					
					LCD_SendStr("Charge");
					BM_ClearBit(TCCR1A,COM1A0);
					SET_CHARGE;					
				}else{
					LCD_SendStr("Discharge");
					BM_SetBit(TCCR1A,COM1A0);
					SET_DISCHARGE;
				}				
			}			
		break;
		case DISPLAY_PROGR:
			if(array[oldWindowsSettings]!=array[windowsSettings]){
				array[oldWindowsSettings]=array[windowsSettings];
				showWinSettings(0,1,DISPLAY_PROGR+array[windowsSettings]);
			}
		break;
		case DISPLAY_P0:
			if(array[oldNormalVoltage]!=array[normalVoltage]){
				array[oldNormalVoltage]=array[normalVoltage];
				showADC(0,0,array[normalVoltage]);
			}
		break;
		case DISPLAY_P1:
			if(array[oldDischargeVoltage]!=array[dischargeVoltage]){
				array[oldDischargeVoltage]=array[dischargeVoltage];
				showADC(0,0,array[dischargeVoltage]);
			}
		break;
		case DISPLAY_P2:
			if(array[oldDischargeAmperage]!=array[dischargeAmperage]){
				array[oldDischargeAmperage]=array[dischargeAmperage];
				showADC(0,1,array[dischargeAmperage]);
			}
		break;
		case DISPLAY_P3:
			if(array[oldNormalAmperage]!=array[normalAmperage]){
				array[oldNormalAmperage]=array[normalAmperage];
				showADC(7,1,array[normalAmperage]);
			}
		break;
		case DISPLAY_P4:
			if(array8[oldAutomatic]!=array8[automatic]){
				array8[oldAutomatic]=array8[automatic];
				LCD_ClearField(0,1,9);
				LCD_Goto(0,1);
				if(array8[automatic]){
					LCD_SendStr("Automatic");				
					} else {
					LCD_SendStr("Manual");				
				}
			}
		break;
		case DISPLAY_P5:
			if(array8[oldNumDischargeCharge]!=array8[numDischargeCharge]){
				array8[oldNumDischargeCharge]=array8[numDischargeCharge];
				LCD_ClearField(0,1,3);
				LCD_Goto(0,1);
				LCD_SendNumber(array8[numDischargeCharge],' ');
			}
		break;
	}
}
コード例 #4
0
ファイル: LCD_VP.c プロジェクト: Freerider82/ChargeAVR
void showCurrentDisplay(uint8_t display){
	LCD_Clear();
	
	switch(display){
		case DISPLAY_START:
			LCD_Goto(0,0);
			LCD_SendStr("V=");
			LCD_Goto(0,1);
			LCD_SendStr("I=");
			LCD_Goto(8,0);
			LCD_SendStr("M=");			
		break;
		case DISPLAY_FAST_CHANGE:
			LCD_Goto(0,0);
			LCD_SendStr("CHARGE DISCHARGE");			
		break;
		case DISPLAY_PROGR:
			LCD_Goto(0,0);
			LCD_SendStr("WINDOWS SETTING");
				
			break;
		case DISPLAY_P0:
			LCD_Goto(0,1);
			LCD_SendStr("U Normal");
		break;
		case DISPLAY_P1:
			LCD_Goto(0,1);
			LCD_SendStr("U Discharge");
		break;
		case DISPLAY_P2:
			LCD_Goto(0,0);
			LCD_SendStr("I Discharge");
		break;
		case DISPLAY_P3:
			LCD_Goto(0,0);
			LCD_SendStr("I Сharge");
			LCD_Goto(0,1);
			LCD_SendStr("Norm.I=");
		break;
		case DISPLAY_P4:
			LCD_Goto(0,0);
			LCD_SendStr("Automat or Manual");
		break;
		case DISPLAY_P5:
			LCD_Goto(0,0);
			LCD_SendStr("N DischargeCharg");
		break;
	}
}