void phaseControl()
{

   switch(noOfPeople)
   {
   
   case 0 : OUTPUT_HIGH(PIN_B7);
            break;
   
   default :
   if(INPUT(PIN_B6) && pin_changed == 1)
   {
         pin_changed = 0;
         if(0<=temperature && temperature<20)
         {
            OUTPUT_HIGH(PIN_B7);
         }
       else if(temperature>=20&& temperature<35)
       {
           delay_ms(5);
           OUTPUT_HIGH(PIN_B7);
            delay_ms(5);
            OUTPUT_LOW(PIN_B7);

       }
       else if(temperature>=35)
       {
            OUTPUT_LOW(PIN_B7);
       }
   }
   //else if(!INPUT(PIN_B6) && pin_changed==0) pin_changed = 1;
   if(!INPUT(PIN_B6)) pin_changed = 1;
   }

}
void main()
{
   init_pic();

     initialDisplay();
     t = read_adc();

   OUTPUT_HIGH(PIN_C0);
   OUTPUT_HIGH(PIN_C2);
   OUTPUT_LOW(PIN_C3);
       while(1)
       {
       //  if(number_changed)
      //   {
            lcd_display(noOfPeople,14,1);
      //      number_changed = 0;
      //   }
         read_temperature();
         if(temp_changed)
         {
            lcd_display(temperature,13,2);
            temp_changed = 0;
         }

       //  phaseControl();

       }
}
示例#3
0
void stop()      //stop - not meaningful for test?
{
      OUTPUT_HIGH(MotorLeft1);
      OUTPUT_HIGH(MotorLeft2);
      OUTPUT_HIGH(MotorRight1);
      OUTPUT_HIGH(MotorRight2); 
}
void main()
{

 /*  setup_adc_ports(AN0);
   setup_adc(ADC_CLOCK_DIV_32);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   enable_interrupts(INT_RTCC);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);

   EXT_INT_EDGE(L_TO_H);

   OUTPUT_B(0);
   OUTPUT_C(0);

   SET_TRIS_B(0b00000111);   //pins B0, B1 and B2 are set to give inputs. b0 is the external interuupt pin
   SET_TRIS_C(0b00000000);
   SET_TRIS_D(0b00000000);

   set_adc_channel(0); */           //the next read_adc call will read channel 0

   init_pic();

     initialDisplay();
    // OUTPUT_HIGH(PIN_C0);
    // OUTPUT_LOW(PIN_C1);

   OUTPUT_HIGH(PIN_C0);
   OUTPUT_HIGH(PIN_C2);
   OUTPUT_LOW(PIN_C3);

       while(1)
       {
           phaseControl();
         if(number_changed)
         {
            lcd_display(noOfPeople,14,1);
            number_changed = 0;
         }

         if(counter_for_temp == 10000)
         {
            lcd_display_temperature();
            counter_for_temp=0;
         }
         counter_for_temp++;

       }

}
示例#5
0
void turn_left()      //turn left using 2 wheels (by 90 degree)
{
      OUTPUT_HIGH(MotorLeft1);
      OUTPUT_LOW(MotorLeft2);
      OUTPUT_HIGH(MotorRight1);
      OUTPUT_LOW(MotorRight2); 
      
      delay_ms(400);
      
      stop();
}
示例#6
0
void go_backward()      //reverse
{
      OUTPUT_HIGH(MotorLeft1);
      OUTPUT_LOW(MotorLeft2);
      OUTPUT_LOW(MotorRight1);
      OUTPUT_HIGH(MotorRight2); 
      
      if(buffer[0] == 't'){
         delay_ms(500);
         stop();
      }
}
示例#7
0
void go_forward()      //forward
{
      OUTPUT_LOW(MotorLeft1);
      OUTPUT_HIGH(MotorLeft2);
      OUTPUT_HIGH(MotorRight1);
      OUTPUT_LOW(MotorRight2);   
      
      if(buffer[0] == 't'){
         delay_ms(500);
         stop();
      }
}
示例#8
0
void ActivaLed() {
	Ticks++;

	if (Ticks==0) {
		//LedAzul=1;
		OUTPUT_HIGH(LedAzul);
		//LedRojo=1;
		OUTPUT_HIGH(LedRojo);
		//LedVerde=1;
		OUTPUT_HIGH(LedVerde);
	};
	if (Ticks==Rojo)
			OUTPUT_LOW(LedRojo);
	if (Ticks==Verde)
			OUTPUT_LOW(LedVerde);
	if (Ticks==Azul)
			OUTPUT_LOW(LedAzul);
	set_timer0(140);
}
/*
   the fan is controlled using phase control method.
   Fan is on only if the number of people >0
*/
void phaseControl()
{
   switch(noOfPeople)
   {
      case 0: OUTPUT_HIGH(PIN_B7);
              break;

      default:
       if(INPUT(PIN_B6) && pin_changed == 1)
      {
         if(0<=temperature && temperature<20)
         {
            OUTPUT_HIGH(PIN_B7);
         }
       else if(temperature>=20&& temperature<23)
       {
            delay_us(6000);
            OUTPUT_LOW(PIN_B7);
            delay_us(500);
            OUTPUT_HIGH(PIN_B7);
       }
       else if(temperature>=23 && temperature<25)
       {
            delay_us(5000);
            OUTPUT_LOW(PIN_B7);
            delay_us(500);
            OUTPUT_HIGH(PIN_B7);
       }
       else if(temperature>=25 && temperature<27)
       {
            delay_us(4500);
            OUTPUT_LOW(PIN_B7);
            delay_us(500);
            OUTPUT_HIGH(PIN_B7);
       }
      else if(temperature>=27 && temperature<30)
       {
            delay_us(4000);
            OUTPUT_LOW(PIN_B7);
            delay_us(500);
            OUTPUT_HIGH(PIN_B7);
       }
       else if(temperature>=30)
       {
            OUTPUT_LOW(PIN_B7);
       }
        pin_changed = 0;
      }

   if(!INPUT(PIN_B6))
   {
      pin_changed = 1;
   }
   }
}
示例#10
0
void Trigger(){
    OUTPUT_HIGH(PIN_TRIGGER);
    delay_us(12);
    OUTPUT_LOW(PIN_TRIGGER);    
}
 /*****************************************************************
 *  Name                 :	WindowLifter_Move1LevelDown
 *  Description          :	Routine to turn OFF next LED.
 *  Parameters           :	void
 *  Return               :	void
 *  Critical/explanation :  Turn OFF next LED and sets LED indicators.
 ******************************************************************/
 void WindowLifter_Move1LevelDown(void){
	OUTPUT_LOW(UP_LED);
	OUTPUT_HIGH(DOWN_LED);
	OUTPUT_LOW(rub_led_level);
	rub_led_level--;
 }
 /*****************************************************************
 *  Name                 :	WindowLifter_Move1LevelUp
 *  Description          :	Routine to turn ON next LED.
 *  Parameters           :	void
 *  Return               :	void
 *  Critical/explanation :  Turn ON next LED and sets LED indicators.
 ******************************************************************/
 void WindowLifter_Move1LevelUp(void){
 	OUTPUT_HIGH(UP_LED);
	OUTPUT_LOW(DOWN_LED);
	rub_led_level++;
	OUTPUT_HIGH(rub_led_level);
 }
void phaseControl()
{

 /*  switch(noOfPeople)
   {

   case 0 : OUTPUT_HIGH(PIN_B7);
            break;

   default :
   if(INPUT(PIN_B6) && pin_changed == 1)
   {
         pin_changed = 0;
         if(0<=temperature && temperature<20)
         {
            OUTPUT_HIGH(PIN_B7);
         }
       else if(temperature>=20&& temperature<35)
       {
           delay_ms(5);
           OUTPUT_HIGH(PIN_B7);
            delay_ms(5);
            OUTPUT_LOW(PIN_B7);

       }
       else if(temperature>=35)
       {
            OUTPUT_LOW(PIN_B7);
       }
   }
   //else if(!INPUT(PIN_B6) && pin_changed==0) pin_changed = 1;
   if(!INPUT(PIN_B6)) pin_changed = 1;
   }*/

    if(noOfPeople<1)
   {
      OUTPUT_HIGH(PIN_B7);
      //OUTPUT_LOW(PIN_B7);
   }
   else
   {
     // OUTPUT_LOW(PIN_B7);
      if(INPUT(PIN_B6) && pin_changed == 1)
      {

         if(0<=temperature && temperature<20)
         {
            OUTPUT_HIGH(PIN_B7);
         }
       else if(temperature>=20&& temperature<25)
       {
            delay_us(7000);
            OUTPUT_LOW(PIN_B7);
            delay_us(500);
            OUTPUT_HIGH(PIN_B7);

       }

       else if(temperature>=25&& temperature<28)
       {
           delay_us(6000);
            OUTPUT_LOW(PIN_B7);
            delay_us(500);
            OUTPUT_HIGH(PIN_B7);
       }
      else if(temperature>=28&& temperature<35)
       {
           delay_us(5000);
            OUTPUT_LOW(PIN_B7);
            delay_us(500);
            OUTPUT_HIGH(PIN_B7);
       }
       else if(temperature>=35)
       {
            OUTPUT_LOW(PIN_B7);
       }
        pin_changed = 0;
   }
   if(!INPUT(PIN_B6))
   {
      pin_changed = 1;
   }

   }
   }
示例#14
0
文件: codigo.c 项目: bahiarca/git
void main(void)
{   
  
   set_tris_a(0b11110000);    //  PROBAR SACAR ESTOO
   set_tris_b(0b11111111);
   
   // PORT_B_PULLUPS(0b00000000);    //  PROBAR SACAR ESTOO
   
   output_a(0b00000000);
   output_b(0b00000000);
     
   OUTPUT_HIGH(LED_APAGADO);
   
   if(!INPUT(MODO))
      delay=1;   
   
   while(!delay){  // MODO DEPURACION
   
      OUTPUT_HIGH(CONTACTOR);
      
      if(INPUT(START)&&(!encendido))
      {
         encendido=1;
         OUTPUT_HIGH(SENNAL_ENCENDIDO);
         OUTPUT_LOW(LED_APAGADO);
         OUTPUT_HIGH(LED_ENCENDIDO);
         delay_ms(200);         
         OUTPUT_LOW(SENNAL_ENCENDIDO);
         OUTPUT_HIGH(NEON);
      }      
      
      if(INPUT(STOP)&&(encendido))
      {
         encendido=0;
         OUTPUT_HIGH(SENNAL_APAGADO);
         OUTPUT_LOW(LED_ENCENDIDO);
         OUTPUT_HIGH(LED_APAGADO);
         delay_ms(200);         
         OUTPUT_LOW(SENNAL_APAGADO);
         OUTPUT_LOW(NEON);
      }
      
      
      if(INPUT(ERROR)&&(encendido))   // LIMPIA LOS ERRORES
      {
         encendido=0;
         OUTPUT_LOW(LED_ENCENDIDO);
         OUTPUT_HIGH(LED_APAGADO);
         OUTPUT_LOW(NEON);
      }
   
   }   // MODO DEPURACION
   
   while(delay)  //  MODO NORMAL
   {  
      
      if(INPUT(START)&&(!encendido))
      {
         encendido=1;
         delay_ms(50);
         OUTPUT_HIGH(CONTACTOR);
         OUTPUT_LOW(LED_APAGADO);
         
         for (int i = 0; i < 10; i++){
            OUTPUT_HIGH(LED_ENCENDIDO);
            delay_ms(200);
            OUTPUT_LOW(LED_ENCENDIDO);
            delay_ms(200);

         }
         
         OUTPUT_HIGH(LED_ENCENDIDO);
         
         OUTPUT_HIGH(SENNAL_ENCENDIDO);
         delay_ms(200);
         OUTPUT_LOW(SENNAL_ENCENDIDO);
         
         OUTPUT_HIGH(NEON);
         
      }  
      
      
      if(INPUT(STOP)&&(encendido))
      {
         encendido=0;
         delay_ms(50);
         OUTPUT_HIGH(SENNAL_APAGADO);
         OUTPUT_LOW(LED_ENCENDIDO);
         
         delay_ms(200);
         OUTPUT_LOW(SENNAL_APAGADO);
         
         OUTPUT_LOW(NEON);
         
         delay_ms(200);
         OUTPUT_LOW(CONTACTOR);
                 
         for (int i = 0; i < 10; i++){
            OUTPUT_HIGH(LED_APAGADO);
            OUTPUT_HIGH(NEON);
            delay_ms(200);
            OUTPUT_LOW(LED_APAGADO);
            OUTPUT_LOW(NEON);
            delay_ms(200);
            if (i==2){
               OUTPUT_HIGH(SENNAL_ENCENDIDO);
               delay_ms(200);
               OUTPUT_LOW(SENNAL_ENCENDIDO);
            }
            else
               OUTPUT_LOW(SENNAL_ENCENDIDO);

         }
         OUTPUT_HIGH(SENNAL_APAGADO);        
         delay_ms(200);
         OUTPUT_LOW(SENNAL_APAGADO);
         /*OUTPUT_HIGH(SENNAL_ENCENDIDO);
         delay_ms(500);
         OUTPUT_LOW(SENNAL_ENCENDIDO);*/
         delay_ms(20);
         OUTPUT_HIGH(LED_APAGADO);         
         
         OUTPUT_LOW(NEON);

      }
      
      if(INPUT(ERROR)&&(encendido))   // LIMPIA LOS ERRORES
      {
         encendido=0;
         OUTPUT_LOW(LED_ENCENDIDO);
         OUTPUT_HIGH(LED_APAGADO);
         OUTPUT_LOW(NEON);
      }   

   }   // MODO NORMAL 
   
}  // FUNCION PRINCIPAL
示例#15
0
void show(void)      //light led
{
      OUTPUT_HIGH(LED);
      delay_ms(3000);
      OUTPUT_LOW(LED);
}
示例#16
0
/**************************************************************
 *  Name                 :	export_func
 *  Description          :
 *  Parameters           :  [Input, Output, Input / output]
 *  Return               :
 *  Critical/explanation :    [yes / No]
 **************************************************************/
void PELC_TurnOnFull(T_UBYTE lub_pcr){
	GPIO_AS_OUTPUT(lub_pcr);
	OUTPUT_HIGH(lub_pcr);
}