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;
   }

}
/*
   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;
   }
   }
}
Пример #3
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();
}
Пример #4
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();
      }
}
Пример #5
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();
      }
}
Пример #6
0
void main(){

	OUTPUT_LOW(LCD_RW); //Che do ghi 
	LCD_Init();        //Khoi tao LCD

	LCD_PutCmd(0x01);  //Xoa man hinh

	ENABLE_INTERRUPTS(INT_TIMER0); //Kich hoat ngat ngoai
	SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_32); //Xung kich noi va chia truoc 32
	ENABLE_INTERRUPTS(GLOBAL); //Cho phep ngat toan cuc
	SET_TIMER0(100); //Bat dau dem tu 100, khi tran Timer0 duoc 1ms

	while (True){ //Duy tri hoat dong cua vi dieu khien

		if (dem > N_max){
			dem = 0;
			LCD_PutCmd(0x01);
		}

		LCD_SetPosition(0x00); //Cot 1 dong 1
		LCD_PutChar("Dem so:");
		LCD_SetPosition(0x07); //Cot 8 dong 1
		printf(LCD_PutChar,"%lu",dem);

	}
}
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();

       }
}
Пример #8
0
void main(){
    float distance = 0;
    
    OUTPUT_LOW(LCD_RW);
    LCD_Init();
    LCD_PutCmd(0x01);
    
    SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_4);
    SETUP_CCP1(CCP_CAPTURE_RE);
    
    ENABLE_INTERRUPTS(INT_CCP1);
    ENABLE_INTERRUPTS(GLOBAL);
    
    
    while (True){
        Trigger();
        
        while (echo == 0){
            ;
        }
        
        distance = value*0.8/58;
        LCD_PutCmd(0x01);
        LCD_SetPosition(0x00);
        LCD_PutChar("Distance:");
        LCD_SetPosition(0x40);
        printf(LCD_PutChar,"%.2fcm",distance);
        delay_ms(1000);
    }
}
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++;

       }

}
Пример #10
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);
}
/*****************************************************************
*  Name                 :	WindowLifter_StopMovement
*  Description          :	Routine to stop the LED switching.
*  Parameters           :	void
*  Return               :	void
*  Critical/explanation :   Change state to WAIT so movement is stopped.
							Turn OFF LED indicators.
******************************************************************/
static void WindowLifter_StopMovement(void){
	OUTPUT_LOW(UP_LED);
	OUTPUT_LOW(DOWN_LED);
	re_currentstate=WAIT_STATE;
}
 /*****************************************************************
 *  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);
 }
Пример #14
0
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
void Trigger(){
    OUTPUT_HIGH(PIN_TRIGGER);
    delay_us(12);
    OUTPUT_LOW(PIN_TRIGGER);    
}
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;
   }

   }
   }
Пример #18
0
/**************************************************************
 *  Name                 :	export_func
 *  Description          :
 *  Parameters           :  [Input, Output, Input / output]
 *  Return               :
 *  Critical/explanation :    [yes / No]
 **************************************************************/
void PELC_TurnOff(T_UBYTE lub_pcr){
	GPIO_AS_OUTPUT(lub_pcr);
	OUTPUT_LOW(lub_pcr);
}