Exemplo n.º 1
0
void interrupt ISR(){   
    
    #ifndef TEST_RFID
    checkI2C(); 
    
    if(TMR0IF == 1){
        if(!FIRST_SEND){
            heartBeatCounter++;
        }
        TMR0IF = 0;
    }
    #endif
    
    
    #ifdef TEST_RFID

    Interrupt_counter++;
  
    if(Interrupt_counter == 2){//2   2 = 125kHZ       // 10på emilkod
              
        sample();
        Interrupt_counter = 0;
    }
    #endif
    
    
}
Exemplo n.º 2
0
//QuadCopt
int main(void)
{
	CSPR = CRP;  //set code protection to none

	CycleCount 				= 0;
	printCount 				= 0;
	refreshCount 			= 0;
	I2C0Mode 				= 1;
	int oldSec 				= 0;
	int countComponentCheck = 0;
	int countToCalc 		= 0;
	int countToI2C 			= 0;
	int servoCount 			= 0;

	init_system();



	print_uart0("FCm0;OsiFC v0.%d successful started;00#",VERSION);

	I2C0Mode = I2CMODE_FLIGHTMODE;
	I2C0State = 0;
	//I2C0Start();

	while(1){

		/*
		if (countComponentCheck++ > sysSetup.CYCLE.componentCycle) {
			//components enabled ?
			if (fcSetup.components[2] == 1) {
				if (navSol.packetStatus == 1 && PWM_channel[PWM_POTI1] > 80) {
					if (led2Status == 1) {
						LED2_OFF;
						led2Status = 0;
					} else {
						LED2_ON;
						led2Status = 1;
					}
					navSol.packetStatus = 0;
				} else {
					LED2_OFF;
					led2Status = 0;
				}

			}

			//compass enabled ?

			countComponentCheck = 0;
		}
		*/

		if (adcRead++ > adcRate) {
				ReadADC();
				adcRead = 0;

		}



		if (countToCalc++ > sysSetup.CYCLE.calcCycle) {
			countToCalc = 0;
			CycleCount++;

			if (servoCount++ > 80){
				setServo();
				servoCount = 0;
			}
			checkUBat();

			if (HMC5843Read++ > 130) {
				HMC5843Read = 0;
				//readHMC5843();
				//heading = calcHeading(HMC_runtime.X_axis,HMC_runtime.Y_axis,HMC_runtime.Z_axis);
			}


			//print telemtrie ?
			if(printCount++ > sysSetup.CYCLE.telemetrieCycle && sysSetup.CYCLE.telemetrieCycle != 0) {
				printTelemetrie();
				printCount = 0;
			}

			current_time = RTCGetTime();
			if (current_time.RTC_Sec != oldSec) {
				I2C1Mode = 0;

				//adjustSensorDrift();
				lastCycleCount = (int)CycleCount;
				CycleCount = 0;
				oldSec = current_time.RTC_Sec;
			}

			//the serial user interface always active
			serialUI();

			//engines Off so do...
			if (engineStatus == ENGINE_OFF) {
				//check for I2C commands to be send out
				//this is mainly for YGE setup
				checkI2C();
				//off flight RC UI to do setup and engines startup
				offFlightRcUI();			//the RC user interface off flight
			}
			//engines On so do...
			if (engineStatus == ENGINE_ON && PWM_valid >= 10000) {
				//check the in flight RC UI
				inFlightRcUI();				//the RC UI for in flight
			}

			I2C0Start();
		}
	}

	return (1);
}