Esempio n. 1
0
void IntInit(void){

	 /*	I_ISPC: Registro de 26 bits.
		    	Si escribimos un "1" decimos que todas las interrupciones pendientes
		    	han sido atendidas. Escribir en este resgistro escribe en INTPND.	*/
		    	rI_ISPC=0xFFFFFFFF	;/* Limpiamos todas las interrupciones pendientes */
		    	rEXTINTPND = 0xf;       // Borra EXTINTPND escribiendo 1s en el propio registro

	/*	Manejo del controlador de interrupciones, hay que configurar los siguiente parámetros:
	INTCON: 3 bits: Modo Vectorizado, Habilita IRQ, Habilita FIQ (Activas a baja)
	Activamos sólo la IRQ y en modo NO vectorizado */
	rINTCON  =0x5;

	/*	INTMOD: Registro con un bit por línea. Si ponemos a 0 sus valores decimos que
	estamos usando IRQ, si ponemos 1 decimos que estamos usando FIQ para esa línea.
	Ponemos   a 0. */
	rINTMOD=0x0;			/* Inicializamos las interrupciones */

	/*	INTMSK(26): Máscara de interrupciones del controlador, activamos las líneas:
		    	EINT4/5/6/7 poniendo su bit a 0.	*/
	rINTMSK = ~(BIT_GLOBAL|BIT_EINT4567); // Emascara todas las lineas excepto eint4567 y el bit global

	InitPorts();


	  /* Por precaucion, se vuelven a borrar los bits de INTPND y EXTINTPND */
	      rI_ISPC    |= (BIT_EINT4567);
	    	rEXTINTPND = 0xf;
}
int main (void)
{
	unsigned int n;		

	InitPorts();		
	InitI2C();			

	ControlByte = 0xA0;
	LowAdd = 0x0C;	
	HighAdd = 0x5A;
	Data = 0xAB;
	Length = 0x05;

	for(n = 0; n < PAGESIZE; n++)
	{
		PageString[n] = n;
	}

	while(1)
	{
		LATAbits.LATA0 = 1;
		LDByteWriteI2C(ControlByte, LowAdd, Data);	
		HDByteWriteI2C(ControlByte, HighAdd, LowAdd, Data);
		HDPageWriteI2C(ControlByte, HighAdd, LowAdd, PageString);
		LDByteReadI2C(ControlByte, LowAdd, &Data, 1);
		HDByteReadI2C(ControlByte, HighAdd, LowAdd, &Data, 1);
		HDSequentialReadI2C(ControlByte, HighAdd, LowAdd, PageString, PAGESIZE);

		Nop();
		LATAbits.LATA0 = 0;
		
	}	
}
Esempio n. 3
0
int main(void) {
    WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
    //*************** Initialization Section ***************************
    InitializeVariables();
    InitPorts();
   // InitTimerSystem();

    //********************* End of Initialization Section *********************


    _BIS_SR(GIE);  //Enable Global Interrupts Here ONLY

//      static const unsigned char myArray[] ={ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, A, B, LC, D, E, F};

    while (1) {
    	handle();



//
//    	ManageSoftwareTimers();
//        Debouncer(&(rotaryEncoder.SwitchA)); // debounce SwitchA
//        Debouncer(&(rotaryEncoder.SwitchB)); // debounce SwitchB
//        stateMachine(&rotaryEncoder, gEncoderState); // go through the state machine and change the counter variable respectively
//

    }
    return 0;
}
Esempio n. 4
0
int main(void)
{
	//WDTCTL = WDTPW + WDTHOLD;  	//Stop watchdog
	InitPorts();
	
	while (1)
	{		
		Delayx100us(10);
		if ((B1)==0)
		{
			STATUS_LED_OFF;
		}
		if ((B2)==0)
		{
			Bargraph_Rise();
			STATUS_LED_ON;
		}
		if ((B3)==0)
		{
			Bargraph_Fall();
			STATUS_LED_ON;
		}
		if ((B4)==0)
		{
			Bargraph_Print(7,1);
		}
	}
	return 0;
}
Esempio n. 5
0
char *InitSys( void )
{
    NumTicks = 0;
    InitPorts();
    SetupTimerData();
    CScheduleInterruptTimeCallBack( &TimerData );
    return( 0 );
}
Esempio n. 6
0
int main( void )
{
  unsigned int i;

  InitPorts();
  InitLCD(); 
  clearDisplay();
  printString("Test LCD");
  Delay(10000);
  return 0;
}
Esempio n. 7
0
int main(void) {
	
	InitClock();	// This is the PLL settings

	InitUART2();	// Initialize UART2 for 9600,8,N,1 TX/RX

	InitPorts();	// LEDs outputs, Switches Inputs

	while(1) {	// The ever versatile Infinite Loop!
		SoftwareDebounce();
	}
}
void main ()
{

	// Initializing PIC16LF1827
	InitPorts();
	InitTimers();
	InitInterrupts();
	while(1)
	{

	}



}
Esempio n. 9
0
void main(void) {
  (void)printf("Start of E128 program\r\n");
  InitPorts();
  InitTimer();
  InitMotors();
  InitSide();
  InitBeacons();
  EnableInterrupts;

  StartMasterSM();

  while(1) {		   		     // Repeat State Machine Forever
    (void)RunMasterSM(CheckEvents());
  }
}
Esempio n. 10
0
void main(void) {
  (void)puts("\r\nIn test harness for tape.c \r\n");
	InitPorts();
  
  while(1) 
  {
  	if(kbhit()) {
  	  (void)getchar(); 
  		(void)printf("Front Left;\tValue: %d Color: %d\r\n",GetTapeValue(FRONT_LEFT),GetTapeColor(FRONT_LEFT));
  		(void)printf("Front Right;\tValue: %d Color: %d\r\n",GetTapeValue(FRONT_RIGHT),GetTapeColor(FRONT_RIGHT));
  		(void)printf("Rear;\t\tValue: %d Color: %d\r\n\r\n",GetTapeValue(REAR),GetTapeColor(REAR));
  	}
  	  	
  }
  	
  return;
}
Esempio n. 11
0
void BLDC::init()
{
  //ResetHandler();
  InitPorts();
  //InitTimers();
  //InitADC();
  //MakeTables();
  //InitHalls();
  //InitAnalogComparator();
  
  //setSpeed( 50 );
  // Run startup procedure.
  //StartMotor();

  // Turn on watchdog for stall-detection.
  //WatchdogTimerEnable();
  //sei();

}
int main(void){ 
//**********************************************************************
// The following version tests input on PE0 and output on PE1
//**********************************************************************
  TExaS_Init(SW_PIN_PE0, LED_PIN_PE1);  // activate grader and set system clock to 80 MHz
  InitPorts();
	
	
  EnableInterrupts();           // enable interrupts for the grader
  while(1){
    Delay100ms(1);
		
		in = GPIO_PORTE_DATA_R & 0x01; // in 0 if not pressed, 1 if pressed
		
		if (in && 0x01) { // switch is pressed
			GPIO_PORTE_DATA_R ^= 0x02; // toggle LED			
		} else {
			LED_On();
		}
  }  
}
Esempio n. 13
0
void CIA6526::DoInit() {

  // initialize base class
  Chip::DoInit();

  // set function to call at each clock
  SetOnClock((pfn)OnClock);
  SetBusy();

  // initialize components
  Reset.Init("Reset", this);
  Reset.SetOnHigh((pfn)OnReset);
  Reset.SetOnLow((pfn)OnReset);
  InitPorts();
  InitTimers();
  InitTOD();
  InitSDR();
  InitControl();

  // reset components
  OnReset();
};
Esempio n. 14
0
void CDockingPorts::InitPortsFromXML (CSpaceObject *pOwner, CXMLElement *pElement)

//	InitPortsFromXML
//
//	InitPortsFromXML 

	{
	//	See if we've got a special element with docking port geometry

	CXMLElement *pDockingPorts = pElement->GetContentElementByTag(DOCKING_PORTS_TAG);
	if (pDockingPorts)
		{
		m_iPortCount = pDockingPorts->GetContentElementCount();
		if (m_iPortCount > 0)
			{
			m_pPort = new DockingPort[m_iPortCount];

			for (int i = 0; i < m_iPortCount; i++)
				{
				CXMLElement *pPort = pDockingPorts->GetContentElement(i);
				CVector vDockPos((pPort->GetAttributeInteger(X_ATTRIB) * g_KlicksPerPixel),
						(pPort->GetAttributeInteger(Y_ATTRIB) * g_KlicksPerPixel));

				m_pPort[i].iStatus = psEmpty;
				m_pPort[i].pObj = NULL;
				m_pPort[i].vPos = vDockPos;
				m_pPort[i].iRotation = (VectorToPolar(vDockPos) + 180) % 360;
				}
			}
		}

	//	Otherwise, initialize ports based on a count

	else
		InitPorts(pOwner,
				pElement->GetAttributeInteger(DOCKING_PORTS_ATTRIB),
				64 * g_KlicksPerPixel);
	}
Esempio n. 15
0
int main()
{
	volatile signed int i, aColumn, aLevel, mask, mux, patterncntr;

	patterncntr = 0;
	Hold = 0;

	InitPorts();
	CARDinit();
	USARTinit();

	while (1) 
	{
	
		while (patterncntr < numanimas)
		{
			X = 0;
			eX = 0;
			XChanged = 0;
			dX = pgm_read_byte(&AnimationA[patterncntr].hold);
			fademode = pgm_read_byte(&AnimationA[patterncntr].fade);

			for (i = 0; i < MaxLedPins; i++)
			{	
				eY[i] = 0;
				/*
				aDivRes = div(i, LedPinsPerLevel);
				aLevel = aDivRes.quot;
				aLedPin = i;
				aLedPin %= LedPinsPerLevel;
				*/
			  	YStart = pgm_read_byte(&AnimationA[patterncntr].pwm[i]);
				PWM[i] = YStart;
				if (patterncntr < numanimas-1) idx = patterncntr+1; else idx = 0;
				YEnd = pgm_read_byte(&AnimationA[idx].pwm[i]);
				dY[i] = YEnd-YStart;		 
			}
			Hold = 0;

			while (Hold <= pgm_read_byte(&AnimationA[patterncntr].hold))
			{
				
				if (fademode > 0) fade();

				for (i=0; i<=PWMres; i++)
				{	
					
					CARDloop();
					USARTloop();
					
					mux = MaxMux;
					while (mux > 0)
					{
						mux--;
						for (aColumn = LedPinsPerColumn-1; aColumn >= 0; aColumn--)
						{	
							mask = 0;
							aLevel = MaxLevels;
							while (aLevel > 0)
							{	
								aLevel--;
								idx = aColumn+mux * LedPinsPerColumn + aLevel * LedPinsPerLevel;
								if (i < PWM[idx]) mask |= (1 << aLevel);
							}
							SetLevelPins(mask);
			
						}
						switch (mux)
						{
							case 0 :
							   SetLevelPins(15);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   break;
							case 1 :
							   SetLevelPins(0);
							   SetLevelPins(15);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   break;
							case 2 :
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(15);
							   SetLevelPins(0);
							   break;
							case 3 :
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(0);
							   SetLevelPins(15);
							   break;
						}
						i = i;	
						Latch();
					}		
				}
			if (fademode == 0)	Hold++;	
			} 
			Hold = 0;
			patterncntr++;	
		}
		patterncntr = 0;
	}
}
Esempio n. 16
0
void initDisplay() {
  InitOsc();
  InitPorts();
  InitLCD();
  clearDisplay();
}
//-------------------------------------------------------------------
//----------------------------Code-----------------------------------
//-------------------------------------------------------------------
void main(void)
{
	// should only execute main loop once; after this just respond to interrupts
	InitTimers();	
	InitPorts();
	InitComm();
	InitInterrupts();
	SSPBUF = BytesOut[i];
	
	while(1)
	{		
		//-----------------------------------------------------------------------------------------		
		//-----------------------------------------------------------------------------------------
		//-----EUART STUFF-------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------------
	if(CommActive)
	{

		if( X_Transition!=0 )
		{
			X_Transition = 0;

			switch( CurrentX_State )
			{
				case X_Idle_State :
				{
						SEND = 1;
						NextX_State = X_StartDelim_State;
						NextByteOut = 0x7E;	
						//	Starting Edit for Variable Message Size		
						MessageCounter = Encode_Message(CurrentType);	
						X_LengthLSB = MessageCounter + 5; //For framing bytes
						//  Populating the Message Frame
						X_CMD = TXData[0];
						X_RF1 = TXData[1];
						X_RF2 = TXData[2];
						X_RF3 = TXData[3];
					    X_RF4 = TXData[4];
						X_RF5 = TXData[5];
					
				}
				break;

				case X_StartDelim_State :
				{

					NextX_State = X_LengthMSB_State;
					NextByteOut = X_LengthMSB ; 
				}
				break;

				case X_LengthMSB_State :
				{
					NextX_State = X_LengthLSB_State;
					NextByteOut = X_LengthLSB; 
				}
				break;
	
				case X_LengthLSB_State :
				{
					NextX_State = X_API_State;
					NextByteOut = X_API; 
				}
				break;
	
				case X_API_State :
				{
					NextX_State = X_FID_State;
					NextByteOut = X_FID; 
				}
				break;
		
				case X_FID_State :
				{
					NextX_State = X_AddrMSB_State;
					NextByteOut = X_AddrMSB; 
				}
				break;

				case X_AddrMSB_State :
				{
					NextX_State = X_AddrLSB_State;
					NextByteOut = X_AddrLSB; 
				}
				break;
	
				case X_AddrLSB_State :
				{
					NextX_State = X_Options_State;
					NextByteOut = X_Options; 
				}
				break;

				case X_Options_State :
				{
					NextX_State = X_CMD_State; // will later need logic here for what transition to do based on length LSB
					NextByteOut = X_CMD; 
				}
				break;
	
				case X_CMD_State :
				{
					MessageCounter--;
					if(MessageCounter)
						{	
							NextX_State = X_RF1_State;
					     	NextByteOut = X_RF1; 
						}
					else
						{	
							NextX_State = X_Checksum_State;
							NextByteOut = CalculateChecksum(); 
      					}     
				}
				break;

				case X_RF1_State :
				{
					MessageCounter--;
					if(MessageCounter)
						{	
							NextX_State = X_RF2_State;
					     	NextByteOut = X_RF2; 
						}
					else
						{	
							NextX_State = X_Checksum_State;
							NextByteOut = CalculateChecksum(); 
      					}                   
				}
				break;

				case X_RF2_State :
				{
					MessageCounter--;
					if(MessageCounter)
						{	
							NextX_State = X_RF3_State;
					     	NextByteOut = X_RF3; 
						}
					else
						{	
							NextX_State = X_Checksum_State;
							NextByteOut = CalculateChecksum(); 
      					}  
				}
				break;

				case X_RF3_State :
				{
					MessageCounter--;
					if(MessageCounter)
						{	
							NextX_State = X_RF4_State;
					     	NextByteOut = X_RF4; 
						}
					else
						{	
							NextX_State = X_Checksum_State;
							NextByteOut = CalculateChecksum(); 
      					}  
				}
				break;

				case X_RF4_State :
				{
					MessageCounter--;
					if(MessageCounter)
						{	
							NextX_State = X_RF5_State;
					     	NextByteOut = X_RF5; 
						}
					else
						{	
							NextX_State = X_Checksum_State;
							NextByteOut = CalculateChecksum(); 
      					}  
				}
				break;

				case X_RF5_State :
				{
					NextX_State = X_Checksum_State;
					NextByteOut = CalculateChecksum(); 
				}
				break;
	
				case X_Checksum_State :
				{
					SEND = 0;
					NextX_State = X_Idle_State;	
					NextByteOut = 0x7E;
				}
				break;
			} // end switch case
		}// end if X_Transition

		if( R_Transition!=0 )
		{
			R_Transition = 0;

			switch( CurrentR_State )
			{
				case R_Idle_State :
				{
					if (ByteIn == 0x7E) // should always be this!	
					{ NextR_State = R_LengthMSB_State; }
				}
				break;

				case R_LengthMSB_State :
				{
					if ( ByteIn == 0x00 ) // should always be this!
					{ NextR_State = R_LengthLSB_State; }
				}
				break;
	
				case R_LengthLSB_State :
				{
					NextR_State = R_API_State;
					R_LengthLSB = ByteIn;
				}
				break;
	
				case R_API_State :
				{
				///Adding Code to Handle different types of received messages
					R_API = ByteIn; 
					if (R_API == API_TXSTAT)
						NextR_State = R_FID_State;
					else if (R_API == API_RXPACK)
						{
							NextR_State = R_AddrMSB_State;
							LostCommCounter = 0;
						}
					else
						NextR_State = R_Idle_State;
				}
				break;

				case R_AddrMSB_State :
				{
					NextR_State = R_AddrLSB_State;
					R_AddrMSB = ByteIn;
				}
				break;
	
				case R_AddrLSB_State :
				{
					NextR_State =R_SigStr_State;
					R_AddrLSB = ByteIn;
				}
				break;

				case R_SigStr_State :
				{
					NextR_State = R_Options_State;
					R_SigStr = ByteIn; 
				}
				break;

				case R_Options_State :
				{
					NextR_State = R_CMD_State; // will later need logic here for what transition to do based on length LSB
					R_Options = ByteIn; 
				}
				break;
	
				
				case R_CMD_State:
				{
					NextR_State = R_RF1_State;
					R_CMD = ByteIn;
					
				}
				break;

				case R_RF1_State :
				{	
					NextR_State = R_Idle_State;
					R_RF1 = ByteIn;
					if (R_CMD == 0x05)
						{	//PAIR_RESP Received
							
							if(R_RF1&BIT0HI)
								{
									Paired = 1;
									//Stop Broadcasting and send Direct Messages
									X_AddrMSB = R_AddrMSB;
				 					X_AddrLSB = R_AddrLSB;
									CurrentType = CTRL;
									Set_PAIRED;
									PORTC = PORTC_Copy;
									LostCommCounter = 0;

								}
							else
								{
									XBee_State(0);
								}

						}
					if (R_CMD == 0x06)
						{  //STATUS Received
							Process_Status(R_RF1);
						}
							
								
				}
				break;
				
								
				case R_FID_State :
				{
					NextR_State = R_STATUS_State;	
					R_FID = ByteIn; 
				}
				break;
				
				case R_STATUS_State :
				{
					NextR_State = R_Idle_State;	
					R_STATUS = ByteIn; 
					//Code to Resend Message if no ACK
					if (R_STATUS)
						{
							X_Transition = 1;
							CurrentX_State = X_Idle_State;
							NextX_State = CurrentX_State;
						}
				}
				break;
				
				

			} // end switch case
		}// end if R_Transition


		if (SEND && TXIF) // for some reason, with TXIE I get 0x7E transmitted twice. 
		{
			X_Transition = 1; 
			TXREG = NextByteOut;
		}

		CurrentX_State = NextX_State;
		CurrentR_State = NextR_State;

	}	
}

}; // end main
Esempio n. 18
0
void main(void) {

  

  int t=15;
  /* include your code here */
  
  f1.functionId=ULTRASONIC_FRONT;
  f1.status=READY;
  f1.root=UNIQUE_FUNCTION;
  f1.timerCount=50;
  
  DisableInterrupts;
  InitReg();  
  InitClock();
  InitComunication();  
  InitPorts();
  InitInputCompare();
  
  InitKbi();
  beginComunication();
  initExecutingVector();
  InitBuffer(&bufferIn);
  InitBuffer(&bufferOut);
  InitPwm();
  InitADC();  
  EnableInterrupts;
  InitRtc();
  /*  
    despues de habilitar interrupciones y
    antes de empezar a mover el robot debe calibrar sensores de meta
    no arrancar el motor sin antes ejecutar initGoalSensor()! 
  */
  initGoalSensor();

  
  setPwmValue(t);
  
  if(t>35){
    kbiSampleFreq=1000;
  }else{
    kbiSampleFreq=1000+((35-t)*200);
  }
  

  
  for(;;) {
  if(goalStatus == 0){
  
    PTDD_PTDD1;
    
    setGoalMode(STOP_ON_GOAL);
    
    SENTIDO_M1_1=1;
    SENTIDO_M1_2=0;
    
    
    SENTIDO_M2_1=1;
    SENTIDO_M2_2=0;  
    
    SENSOR_DE_META_ON;
    PTDD_PTDD0=1;

    
    /*
    functionHandler();
    dispatcher(&executingVector,&bufferOut);
    frameGenerator();*/
     /* f1.functionId=ULTRASONIC_FRONT;
      f1.status=READY;
      getUltrasonic(&f1);
      
      while(f1.status!=AVAILABLE);
      t=3000;
      while(t!=0){
        t--;
      } */
      
      /*
      f1.functionId=ULTRASONIC_FRONT;
      f1.status=READY;
      f1.root=UNIQUE_FUNCTION;
      f1.timerCount=50;
      getUltrasonic(&f1);
      
      while(f1.status!=AVAILABLE);
      t=3000;
      while(t!=0){
        t--;
      } */
      /*
      f1.functionId=ULTRASONIC_RIGHT;
      f1.status=READY;
      getUltrasonic(&f1);
      
      while(f1.status!=AVAILABLE);
      t=30000;
      while(t!=0){
        t--;
      } */
      
    } /* loop forever */
  } 
  /* please make sure that you never leave main */
}
Esempio n. 19
0
int main(void) {     

	//Ports 
	InitPorts();


	//Init Uart1 
	InitUart1();
	               	 
	//LCD initialisation 
	LCD_Ini(); 					     
	// delay_ms(2);  		
	SEND_CMD(DISP_ON);
	// delay_ms(10);  						
	SEND_CMD(CLR_DISP); 
	// write
	SEND_STR(" www.olimex.com");


	while (1) {  

		// Uart Echo
		ch = ReceiveCharUart1_nonstop();
		if(ch!=0) {
	
			SendCharUart1(ch);
			SendCharUart1('*');
			ch = 0;
		}


		//Buttons scan                
   
		// Button 1
		if (B1==0) {
			RELAY_HIGH;        
		}
	    else { 
			RELAY_LOW;	      
		}
    
		// Button 2
		if (B2==0) {
	
			SEND_CMD(CLR_DISP);      	
			SEND_CMD(DD_RAM_ADDR);
			SEND_STR("Press button 2"); 
		}  
    

		// Button 3    
		if (B3==0) {
	       
			SEND_CMD(CLR_DISP);   
			SEND_CMD(DD_RAM_ADDR);  
			SEND_STR("Press button 3"); 
		  
		}       
		
		// Button 4
		while (B4==0) 
			Buzzer();


		// Button 3    
		if (B5==0) {
	       
			SEND_CMD(CLR_DISP);   
			SEND_CMD(DD_RAM_ADDR);  
			SEND_STR("Press button 5"); 
		  
		} 
   
  	}
}
Esempio n. 20
0
int main(void)
{

	InitOsc();  
	InitPorts();           
	InitUART0();
	InitLCD();

	TCPLowLevelInit();                            //after TCPLowLevelInit() UCLK = ACLK = MCLK/4 = 2 000 000 Hz   

	UART_transmit (CR);
	UART_transmit (LF);  
	for (i=0; i!=26; i++)  UART_transmit (UART_Message[i]); 
	UART_transmit (CR);
	UART_transmit (LF);  

	for (i=0; i!=32; i++)  
	{
		SEND_CHAR(LCD_Message[i]);
		if (i==15) SEND_CMD (DD_RAM_ADDR2);
	}  

	SEND_CMD(DD_RAM_ADDR);    
	RX_flag=0; 
	cntr = 0;   

	HTTPStatus = 0;                                // clear HTTP-server's flag register
	TCPLocalPort = TCP_PORT_HTTP;                  // set port we want to listen to

	while (1)                                      // repeat forever
	{

		//--------------buttons scan---------------------------------------------------------

		if ((B1) == 0)                                 //B1 is pressed
		{
			STATUS_LED_ON;                             //switch on status_led
			SEND_CMD(CLR_DISP);
			SEND_CMD(DD_RAM_ADDR);
			cntr=0;
		}
		else  STATUS_LED_OFF;                           //B1 is released 

		if ((B2) == 0)
		{      
			//        time_out = BUTTON_TIME;
			//        while (time_out != 0) 
			//        if ((B2) == 0) time_out--;
			//        else time_out = BUTTON_TIME;  

			Delayx100us(50);
			RELAY1_ON;                                        
		}
		else
		{      
			//        time_out = BUTTON_TIME;
			//        while (time_out != 0) 
			//        if ((B2) != 0) time_out--;
			//        else time_out = BUTTON_TIME;  

			Delayx100us(50);
			RELAY1_OFF;                                        
		}                   

		if ((B3) == 0)   
		{
			Delayx100us(50);
			RELAY2_ON;                     //B3 is pressed
		}
		else  
		{
			Delayx100us(50);
			RELAY2_OFF;                               //B3 is released
		}  

		while ((B4) == 0)                               //B4 is pressed
		{
			BUZ1_OFF;                                 
			BUZ2_ON;
			Delay(_100us);
			Delay(_100us);                            //buzzer with 5 000 Hz
			BUZ2_OFF;
			BUZ1_ON;
			Delay(_100us);          
		}    
		BUZ1_OFF;                                      //B4 is released
		BUZ2_OFF;      

		//--------UART0 receiv scan------------------------------------------------------------------     

		if (RX_flag == 1)                              //new receiv byte
		{                    
			STATUS_LED_ON;
			if (cntr == 0) 
			{
				SEND_CMD(CLR_DISP);
				SEND_CMD(DD_RAM_ADDR);                //set address for first row
			}
			SEND_CHAR(RXData);          
			if(cntr == 15) SEND_CMD(DD_RAM_ADDR2);    //set address for second row
			if(cntr++ == 31) cntr = 0;           
			RX_flag = 0;            
			STATUS_LED_OFF;
		}
		//---------Digital Inputs scan--------------------------------------------------------------

		if ((DI1) == 0)  for (i=0 ; i != 5; i++)UART_transmit(DI1_Message[i]);  
		if ((DI2) == 0)  for (i=0 ; i != 5; i++)UART_transmit(DI2_Message[i]);  
		if ((DI3) == 0)  for (i=0 ; i != 5; i++)UART_transmit(DI3_Message[i]);  
		if ((DI4) == 0)  for (i=0 ; i != 5; i++)UART_transmit(DI4_Message[i]);  

		//---------DALLAS scan ---------------------------------------------------------------------

		if ((DALLAS) == 0)                      
		{
			cntr=0;
			SEND_CMD(CLR_DISP);
			SEND_CMD(DD_RAM_ADDR);
			for (i=0 ; i!= 14; i++) SEND_CHAR(DALLAS_Message[i]);
		}   

		//---------FREQ scan ----------------------------------------------------------------------      

		if ((FREQ) != 0) 
		{
			cntr=0;
			SEND_CMD(CLR_DISP);
			SEND_CMD(DD_RAM_ADDR);
			for (i=0 ; i!= 16; i++) SEND_CHAR(FREQ_Message[i]);
		}   

		//***********************************************************************************    
		//this is the end of my programm
		//***********************************************************************************

		if (!(SocketStatus & SOCK_ACTIVE)) {
			TCPPassiveOpen();   // listen for incoming TCP-connection
		}
		DoNetworkStuff();                                      // handle network and easyWEB-stack
		// events
		HTTPServer();
	}                               
	return 0;
}
Esempio n. 21
0
File: pu-test.c Progetto: gke/UAVP
void main(void)
{
	int8	i;

	DisableInterrupts;

	InitPorts();
	InitADC();

	OpenUSART(USART_TX_INT_OFF&USART_RX_INT_OFF&USART_ASYNCH_MODE&
			USART_EIGHT_BIT&USART_CONT_RX&USART_BRGH_HIGH, _B38400);
	
	OpenTimer0(TIMER_INT_OFF&T0_8BIT&T0_SOURCE_INT&T0_PS_1_16);
	OpenTimer1(T1_8BIT_RW&TIMER_INT_OFF&T1_PS_1_8&T1_SYNC_EXT_ON&T1_SOURCE_CCP&T1_SOURCE_INT);

	OpenCapture1(CAPTURE_INT_ON & C1_EVERY_FALL_EDGE); 	// capture mode every falling edge
	CCP1CONbits.CCP1M0 = NegativePPM;

	OpenTimer2(TIMER_INT_ON&T2_PS_1_16&T2_POST_1_16);		
	PR2 = TMR2_5MS;		// set compare reg to 9ms

	INTCONbits.TMR0IE = false;

	// setup flags register
	for ( i = 0; i<16; i++ )
		Flags[i] = false;

	_NoSignal = true;
	InitArrays();
	ReadParametersEE();
	ConfigParam = 0;

    ALL_LEDS_OFF;
	Beeper_OFF;

	LedBlue_ON;

	INTCONbits.PEIE = true;		// enable peripheral interrupts
	EnableInterrupts;

	LedRed_ON;		// red LED on

	Delay1mS(100);
	IsLISLactive();
#ifdef ICD2_DEBUG
	_UseLISL = 1;	// because debugger uses RB7 (=LISL-CS) :-(
#endif

	NewK1 = NewK2 = NewK3 = NewK4 =NewK5 = NewK6 = NewK7 = 0xFFFF;

	PauseTime = 0;

	InitBarometer();

	InitDirection();
	Delay1mS(COMPASS_TIME);

	// send hello text to serial COM
	Delay1mS(100);
	ShowSetup(true);
	Delay1mS(BARO_PRESS_TIME);
	while(1)
	{
		// turn red LED on of signal missing or invalid, green if OK
		// Yellow led to indicate linear sensor functioning.
		if( _NoSignal || !Switch )
		{
			LedRed_ON;
			LedGreen_OFF;
			if ( _UseLISL  )
				LedYellow_ON;
		}
		else
		{
			LedGreen_ON;
			LedRed_OFF;
			LedYellow_OFF;
		}

		ProcessComCommand();

	}
} // main
Esempio n. 22
0
void CDockingPorts::InitPortsFromXML (CSpaceObject *pOwner, CXMLElement *pElement)

//	InitPortsFromXML
//
//	InitPortsFromXML 

	{
	int i;

	//	See if we've got a special element with docking port geometry

	CXMLElement *pDockingPorts = pElement->GetContentElementByTag(DOCKING_PORTS_TAG);
	if (pDockingPorts)
		{
		//	Initialize max dist

		m_iMaxDist = pDockingPorts->GetAttributeIntegerBounded(MAX_DIST_ATTRIB, 1, -1, DEFAULT_DOCK_DISTANCE_LS);

		//	If we have sub-elements then these are port definitions.

		m_iPortCount = pDockingPorts->GetContentElementCount();
		if (m_iPortCount > 0)
			{
			m_pPort = new DockingPort[m_iPortCount];

			for (i = 0; i < m_iPortCount; i++)
				{
				CXMLElement *pPort = pDockingPorts->GetContentElement(i);
				CVector vDockPos((pPort->GetAttributeInteger(X_ATTRIB) * g_KlicksPerPixel),
						(pPort->GetAttributeInteger(Y_ATTRIB) * g_KlicksPerPixel));

				m_pPort[i].iStatus = psEmpty;
				m_pPort[i].pObj = NULL;
				m_pPort[i].vPos = vDockPos;

				if (pPort->FindAttributeInteger(ROTATION_ATTRIB, &m_pPort[i].iRotation))
					m_pPort[i].iRotation = (m_pPort[i].iRotation % 360);
				else
					m_pPort[i].iRotation = (VectorToPolar(vDockPos) + 180) % 360;
				}
			}

		//	Otherwise, we expect a port count and radius

		else if ((m_iPortCount = pDockingPorts->GetAttributeIntegerBounded(PORT_COUNT_ATTRIB, 0, -1, 0)) > 0)
			{
			m_pPort = new DockingPort[m_iPortCount];
			
			int iRadius = pDockingPorts->GetAttributeIntegerBounded(PORT_RADIUS_ATTRIB, 0, -1, DEFAULT_PORT_POS_RADIUS);
			Metric rRadius = g_KlicksPerPixel * iRadius;

			int iAngle = 360 / m_iPortCount;
			for (i = 0; i < m_iPortCount; i++)
				{
				m_pPort[i].iStatus = psEmpty;
				m_pPort[i].pObj = NULL;
				m_pPort[i].vPos = PolarToVector(i * iAngle, rRadius);
				m_pPort[i].iRotation = ((i * iAngle) + 180) % 360;
				}
			}

		//	Otherwise, no ports

		else
			{
			m_iPortCount = 0;
			m_pPort = NULL;
			}
		}

	//	Otherwise, initialize ports based on a count

	else
		InitPorts(pOwner,
				pElement->GetAttributeInteger(DOCKING_PORTS_ATTRIB),
				64 * g_KlicksPerPixel);
	}
Esempio n. 23
0
void CDockingPorts::InitPortsFromXML (CSpaceObject *pOwner, CXMLElement *pElement)

//	InitPortsFromXML
//
//	InitPortsFromXML 

	{
	int i;

	//	See if we've got a special element with docking port geometry

	CXMLElement *pDockingPorts = pElement->GetContentElementByTag(DOCKING_PORTS_TAG);
	if (pDockingPorts)
		{
		//	Initialize max dist
		//	NOTE: pOwner can be NULL because sometimes we init ports from a ship class 
		//	(without an object).

		int iDefaultDist = Max(DEFAULT_DOCK_DISTANCE_LS, (pOwner ? 8 + (int)((pOwner->GetBoundsRadius() / LIGHT_SECOND) + 0.5) : 0));
		m_iMaxDist = pDockingPorts->GetAttributeIntegerBounded(MAX_DIST_ATTRIB, 1, -1, iDefaultDist);


		//	If we have sub-elements then these are port definitions.

		m_iPortCount = pDockingPorts->GetContentElementCount();
		if (m_iPortCount > 0)
			{
			m_pPort = new SDockingPort[m_iPortCount];

			for (i = 0; i < m_iPortCount; i++)
				{
				CXMLElement *pPort = pDockingPorts->GetContentElement(i);
				CVector vDockPos((pPort->GetAttributeInteger(X_ATTRIB) * g_KlicksPerPixel),
						(pPort->GetAttributeInteger(Y_ATTRIB) * g_KlicksPerPixel));

				m_pPort[i].vPos = vDockPos;

				if (pPort->FindAttributeInteger(ROTATION_ATTRIB, &m_pPort[i].iRotation))
					m_pPort[i].iRotation = (m_pPort[i].iRotation % 360);
				else
					m_pPort[i].iRotation = (VectorToPolar(vDockPos) + 180) % 360;

				if (pPort->GetAttributeBool(BRING_TO_FRONT_ATTRIB))
					m_pPort[i].iLayer = plBringToFront;
				else if (pPort->GetAttributeBool(SEND_TO_BACK_ATTRIB))
					m_pPort[i].iLayer = plSendToBack;
				}
			}

		//	Otherwise, we expect a port count and radius

		else if ((m_iPortCount = pDockingPorts->GetAttributeIntegerBounded(PORT_COUNT_ATTRIB, 0, -1, 0)) > 0)
			{
			int iRadius = pDockingPorts->GetAttributeIntegerBounded(PORT_RADIUS_ATTRIB, 0, -1, DEFAULT_PORT_POS_RADIUS);
			int iAngle = 360 / m_iPortCount;

			//	We need the image scale to adjust coordinates

			int iScale = (pOwner ? pOwner->GetImage().GetImageViewportSize() : 512);

			//	Initialize ports

			m_pPort = new SDockingPort[m_iPortCount];
			for (i = 0; i < m_iPortCount; i++)
				{
				C3DConversion::CalcCoord(iScale, i * iAngle, iRadius, 0, &m_pPort[i].vPos);
				m_pPort[i].iRotation = ((i * iAngle) + 180) % 360;
				}
			}

		//	Otherwise, no ports

		else
			{
			m_iPortCount = 0;
			m_pPort = NULL;
			}
		}

	//	Otherwise, initialize ports based on a count

	else
		InitPorts(pOwner,
				pElement->GetAttributeInteger(DOCKING_PORTS_ATTRIB),
				64 * g_KlicksPerPixel);
	}