コード例 #1
0
ファイル: FinExo.c プロジェクト: hugodav/ProjetAMI
int FinExo(){

        lcd_clearscreen();
        lcd_position(0, 0);
        lcd_ascii("1.Recommencer");
        lcd_position(0, 1);
        lcd_ascii("2.Retour Menu");
        lcd_position(0, 2);
        lcd_ascii("3.Quitter");

        int c =0;

			while(P1IN==0) {

				if (c==3){

                    c=0;
                }

                    else if (P2IN==0x01){

                            c++;
                    }


				lcd_position(0, c);

			}

        return c;

}
コード例 #2
0
ファイル: main.c プロジェクト: dalmirdasilva/lcd
void main() {
    int8_t i = 0;
    char c = 'A';
    char custom_chars[] = {
        0x00, 0x00, 0x00, 0x04,
        0x00, 0x00, 0x00, 0x00,
        
        0x00, 0x00, 0x0e, 0x0a,
        0x0e, 0x00, 0x00, 0x00,
        
        0x00, 0x1f, 0x11, 0x11,
        0x11, 0x1f, 0x00, 0x00
    };
    _asm bcf _WDTCON, 0 _endasm;
    init_io();
    
    lcd_init();
    
    lcd_custom_char_create(custom_chars, 0, 3);
    delay_ms(500);
    lcd_command(LCD_CMD_DISPLAY_CONTROL | LCD_CMD_DISPLAY_CONTROL_ON);
    //lcd_test_do();
    while(1) {
        lcd_position(0, 0);
        lcd_write(i++ % 3, LCD_RS_DATA, 2);
        delay_ms(150);
        PORTEbits.RE1 ^= 1;
    }
}
コード例 #3
0
ファイル: lcd.c プロジェクト: athurg/study_work
void lcd_init(void)
{
/*
*  初始化LCD
*
* 调用:lcd_cls()、lcd_cmd()、lcd_position
*/
	lcd_cls();
	lcd_cmd(LCD_CURSOR);
	lcd_cmd(LCD_AC_AUTO_INCREMENT);
	lcd_cmd(LCD_DISPLAY_ON);

	lcd_cmd(LCD_LINES);	//工作方式(行数)

	lcd_position(2,0);		//定位到第一行第一列

}
コード例 #4
0
ファイル: Keyprocess.c プロジェクト: smhuang426/Keil
void key_process(U8 key)
{
	if(key>10)
	{
		switch(key)
		{
			case 11 : if(offset==4)	offset++; if(offset<6) lcd_position(++offset); break;
			case 12 : if(offset==6) offset--; if(offset>0) lcd_position(--offset); break;
			case 13 : stat=0; rtc_writertc(); lcd_normal_init(); break;
			case 14 : stat=1; lcd_adjust_init(); break;
		}
	}
	else if(stat==1)
	{
		if(count==0)
		{
			lcd_position(offset);
			lcd_writecd(DATA,' ');
			lcd_writecd(DATA,' ');
			lcd_position(offset);
			lcd_writecd(DATA,key+'0');
			count++;
			key_record=10*key;
		}
		else
		{
			lcd_writecd(DATA,key+'0');
			lcd_position(offset);
			count=0;
			key_record+=key;
			if(!rtc_range(offset,key_record))
				rtc_settime(offset,key_record);
			else
			{
				lcd_position(offset);
				lcd_writecd(DATA,range[offset][0]/10+'0');
				lcd_writecd(DATA,range[offset][0]%10+'0');
				lcd_position(offset);
			}
		}
	}
}
コード例 #5
0
ファイル: main.c プロジェクト: enolan2/Micro-Hydro-ELC
void main(void)
{

	int i=0;					// Loop Variable
	timeout_ctr	= 0	;

//############################ Initialisation ###############################//

						// _SOURCE_
	DeviceInit();		// DeviceInit.c
	InitGpio();			// GpioInit.c
	InitPieVectTable();	// PieVect.c
	InitPieCtrl();		// PieCtrl.c

	InitSci();			// Serial.c
	init_lcd_menu();	// LcdMenu.c
	lcd_init();			// LcdDriver.c

	SineRefInit();		// SineRefInit.c
	AdcInit();			// AdcInit.c
	PwmInit();			// PwmInit.c

	State.all				= 0;
	State.bit.Start			= 1;
	PeripheralEn.bit.Buttons= 1;	// Allow button checks

	EnableInterrupts();				// PieCtrl.c
	DisableInverter();				// Ensure inverter is disabled on start-up

	lcd_position(0x5,0x0);
	lcd_puts("Kingfisher");				// Print introductory message on top line
	lcd_position(0x0,0x1);				// Start Cursor From First Line
	lcd_puts("  Hydro Controller    ");	// Print introductory message on bottom line

	asm(" CLRC INTM, DBGM");			// Enable global interrupts and real-time debug

	CpuTimer0Regs.PRD.all =  COUNTER0_PRD;	// Initialise CPU timer0
	CpuTimer1Regs.PRD.all =  COUNTER1_PRD;	// Initialise CPU timer0



//############################# Polling Loop ################################//

	while(1)
	{

	//#######################################################################//
	//									STATES 								 //
	//#######################################################################//
	//
	//############################ START STATE ##############################//
		if(State.bit.Start)
		{
			asm("NOP");
		}

	//######################### EXCITATION STATE ############################//
		if (State.bit.Excitation)
		{
			data_out.bit.led_ctrl_green	= 1;
			data_out.bit.led_ctrl_red	= 0;

			if ( (AdcSignal.V_HVDC < 50) && (AdcSignal.Shaft_Velocity > 2000) && !(State.bit.Fault) )
			{
//				PeripheralEn.bit.Buttons= 0;

				timeout_ctr++;
				if (timeout_ctr > 3)
				{
					State.all		= 0;
					State.bit.Fault	= 1;
					timeout_ctr		= 0;
				}
				else
				{
					data_out.bit.startup = 1;
					shift_data_out();
					if (CpuTimer0Regs.TCR.bit.TIF == 1)
					{
						for (i=1;i<=2;i++)						// wait 2 seconds
						{
							CpuTimer0Regs.TCR.bit.TIF	= 1;	// Clear flag
							while(!CpuTimer0Regs.TCR.bit.TIF);
						}
					}
					data_out.bit.startup = 0;
					shift_data_out();
					if (CpuTimer0Regs.TCR.bit.TIF == 1)
					{
						for(i=1;i<=3;i++)						// wait 3 seconds
						{
							CpuTimer0Regs.TCR.bit.TIF	= 1;	// Clear flag
							while(!CpuTimer0Regs.TCR.bit.TIF);
						}
					}
				}
			}
			else if ( (AdcSignal.V_HVDC >= 50) && (AdcSignal.V_HVDC < 250) )
			{
				timeout_ctr			= 0;
				State.all			= 0;
				State.bit.Excited	= 1;
				// Perhaps change LCD Screen to message saying "Slowly increase turbine speed to increase voltage."
			}
			else if ( (AdcSignal.V_HVDC > 250) )
			{
				timeout_ctr					= 0;		// Resets the timeout counter for excitation
				State.all					= 0;
				State.bit.StartupSequence	= 1;
			}
		}

	//############################ EXCITED STATE ############################//
		if (State.bit.Excited)
		{
			if (AdcSignal.V_HVDC > 250)
			{
				timeout_ctr					= 0;		// Resets the timeout counter for excitation
				State.all					= 0;
				State.bit.StartupSequence	= 1;
			}
			else
			{
				// !!!!! ADD SOME CODE FOR THIS CONDITION !!!!!
			}
		}

	//############################# FAULT STATE #############################//
		if (State.bit.Fault)
		{
			if (PeripheralEn.bit.Inverter)
			{
				DisableInverter();
				data_out.bit.led_dump1		= 0;
				data_out.bit.led_dump2		= 0;
				data_out.bit.led_inverter	= 0;
				data_out.bit.led_update		= 0;
			}
			data_out.bit.protect_trig	= 1;

			data_out.bit.led_ctrl_green	= 0;
			data_out.bit.led_ctrl_red	= 1;
			if ( !(LED_Fault_Ctr++ % 16384) )
			{
				data_out.bit.led_dump1		= ~(data_out.bit.led_dump1);
				data_out.bit.led_dump2		= ~(data_out.bit.led_dump2);
				data_out.bit.led_inverter	= ~(data_out.bit.led_inverter);
				data_out.bit.led_update		= ~(data_out.bit.led_update);
			}
		}

	//########################### DC STABLE STATE ###########################//
		if (State.bit.DcStable)
		{
			if ( !(PeripheralEn.bit.Inverter) )	EnableInverter();
			data_out.bit.led_ctrl_green	= 1;
			data_out.bit.led_ctrl_red	= 0;
		}

	//############################## TEST STATE #############################//
		if (State.bit.Test)
		{

		}

	//########################### TURNED OFF STATE ##########################//
		if (State.bit.TurnOff)
		{
			data_out.bit.led_ctrl_green	= 0;
			data_out.bit.led_ctrl_red	= 0;
			data_out.bit.led_dump1		= 0;
			data_out.bit.led_dump2		= 0;
			data_out.bit.led_inverter	= 0;
			data_out.bit.led_update		= 0;
		}

	//#######################################################################//
	//								FLAGS 									 //
	//#######################################################################//
	//
	//######################## SCREEN UPDATE FLAG #######################//
		if (flag_bc)
		{
			menu_update_lcd();
			flag_bc = 0;
		}
		asm(" nop");

	//########################### READ IN DATA FLAG #########################//
		if (flag.bit.DataIN)
		{
			shift_data_in();
			check_buttons();
			flag.bit.DataIN = 0;
		}

	//########################## SEND OUT DATA FLAG #########################//
		if (flag.bit.DataOUT)
		{
			shift_data_out();
			flag.bit.DataOUT = 0;
		}

	//######################## HVDC VOLTAGE REGULATION ######################//
		if (flag.bit.V_HVDC)
		{
			if ( !(State.bit.TurnOff) && !(State.bit.Fault) )
			{
				V_DcError	= V_DC_REF - AdcSignal.V_HVDC;			// Calculate the DC error from the reference
				DutyError	= 0.75*K_DC*V_DcError + 0.25*DutyError;	// Modify the dump load duty cycle with respect to the DC error

				if (V_DcError > 0)		// If the DC voltage is less than the reference, dump no power
				{
					EPwm3Regs.CMPA.half.CMPA= 0;
					EPwm3Regs.CMPB			= 0;
				}
				else if (DutyError > DUMP1_DUTY_MAX)
				{
					DutyFeedback			= 1.0*(DUMP1_DUTY_MAX)*DUMP_PRD;
					EPwm3Regs.CMPA.half.CMPA= DutyFeedback;
					DutyFeedback			= 1.0*(DutyError - DUMP1_DUTY_MAX)*DUMP_PRD;
					EPwm3Regs.CMPB			= DutyFeedback;
				}
				else
				{
					DutyFeedback			= 1.0*(DutyError)*DUMP_PRD;
					EPwm3Regs.CMPA.half.CMPA= DutyFeedback;
					EPwm3Regs.CMPB			= 0;
				}
			}else		// If there is a fault or the system is off, dump all power
			{
				EPwm3Regs.CMPA.half.CMPA	= (DUMP1_DUTY_MAX)*DUMP_PRD;	// Dump all power!
				EPwm3Regs.CMPB				= DUMP_PRD;	// Dump all power!
			}

			flag.bit.V_HVDC	= 0;		// Reset the flag
		}


	//###################### SHAFT VELOCITY MEASUREMENT #####################//
		if (ShaftVelocCtr >= 1000)										// Updates the measured velocity every 1000*(1/EPWM8) = 0.5s
		{
			AdcSignal.Shaft_Velocity	= shaftspeedtest; //0.8*(ShaftPulseCtr/0.5)*60 + 0.2*AdcSignal.Shaft_Velocity;	// Where 1 pulse = 1 rotation
			ShaftPulseCtr				= 0;	// { Reset counters
			ShaftVelocCtr				= 0;	// {
		}

	//################### OUTPUT AC VOLTAGE FREQUENCY MEASURE ################//
		if (V_AcOutPrdCtr >= 10)
		{
			AdcSignal.V_AcOut_Freq	= (SYSCLK/ADC_SAMP_PRD+1)*(V_AcOutPrdCtr/FreqOutDivCtr);	// Approximate frequency over at least 10 periods
			AcOutFreqError			= AC_OUT_FREQ - AdcSignal.V_AcOut_Freq;	// Find frequency error
			V_AcOutReqFreq			= V_AcOutReqFreq + 0.05*AcOutFreqError;	// Frequency feedback loop
			sinGen.freq				= V_AcOutReqFreq*(BIT31)*(2*BIT32*INVERTER_PWM_PRD)*(1/(sinGen.step_max*SYSCLK));	// Alter reference sine wave frequency
			V_AcOutPrdCtr			= 0	;	// }
			FreqOutDivCtr			= 0	;	// } Reset counters
		}

	//####################### INVERTER CONTROL #######################//
		if (flag.bit.Inverter)
		{
/* BROKEN	InverterMaxDuty	= V_AC_OUT_REF*(1.0/(AdcSignal.V_HVDC));	// Find the maximum duty cycle necessary to create Vacoutpeak=325V
			DutyScaleMax	= (BIT16*InverterMaxDuty-BIT15)*30.51850948e-6;	// 30.51850948e-6 = 1/(BIT15-1)

			if ( !(State.bit.InvSoftStart) )
			{
				DutyScaleError	= DutyScaleMax - DutyScale;
				DutyScale	= DutyScale + 0.01*DutyScaleError;
				if (DutyScale < 0.2)
				{
				DutyScale	= 0.2;
				ADD SOME CODE IN CASE IT IS DANGEROUS TO GO BELOW 0.2
				}
			}
*/

			// ----- Toggle the onboard LED to show inverter control is active
			if (GPIO34_count >= 4000)						// toggle_time = GPIO34_count_limit/fpwm
			{
				GpioDataRegs.GPBTOGGLE.bit.GPIO34	= 1;	// Toggle the pin
				GPIO34_count	= 0;						// Reset the count
			}

			flag.bit.Inverter	= 0;
		}

	//################### INPUT AC VOLTAGE FREQUENCY MEASURE ################//
		if (V_AcInPrdCtr >= 10)
		{
			AdcSignal.V_AcIn_Freq	= 0.8*((SYSCLK/ADC_SAMP_PRD+1)*(V_AcInPrdCtr/FreqInDivCtr)) + 0.2*(AdcSignal.V_AcIn_Freq);	// Approximate frequency over at least 10 periods
			genSlip					= 100*((AdcSignal.V_AcIn_Freq*60) - (AdcSignal.Shaft_Velocity))/(AdcSignal.V_AcIn_Freq*60);	// Calculates slip: s= 100%*((ns-nr)/ns)
			V_AcInPrdCtr			= 0	;	// }
			FreqInDivCtr			= 0	;	// } Reset counters
		}


/*		if(SendADCResult)
		{
			SendADCResult = 0;

			SerialSendStr("Voltage: ");
			SerialSendInt((int)V_DC_measured);
			SerialSendStr("   PWM1: ");
			SerialSendInt((int)(EPwm3Regs.CMPA.half.CMPA*100.0/(DUMP_PRD*1.0)));
			SerialSendCR();
			SerialSendStr("   PWM2: ");
			SerialSendInt((int)((EPwm3Regs.CMPB*100.0)/(DUMP_PRD*1.0)));
			SerialSendCR();
		}*/

	}

}