Advertisement
Electgpl

PIC - Protector de 220Vac

Jun 19th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include <16F883.h>
  2. #device adc=10
  3. #use delay(int=4000000)
  4. #define OUT_220 PIN_A2
  5. #define LED_LO PIN_A3
  6. #define LED_OK PIN_A4
  7. #define LED_HI PIN_A5
  8. void main(){
  9.    int16 salida;
  10.    setup_adc_ports(sAN0);
  11.    setup_adc(ADC_CLOCK_DIV_2);
  12.    output_low(OUT_220);
  13.    output_high(LED_LO);
  14.    output_high(LED_OK);
  15.    output_high(LED_HI);  
  16.    while(true){
  17.       set_adc_channel(0);
  18.       delay_us(10);
  19.       salida = read_adc();
  20.       switch(true){
  21.       case (salida > 980):              //Si es > 4.1V
  22.          output_low(OUT_220);
  23.          output_low(LED_LO);
  24.          output_low(LED_OK);
  25.          output_high(LED_HI);
  26.          delay_ms(3000);
  27.          break;
  28.       case (salida > 800 && salida < 430):   //Si es > 800 y < 430
  29.          output_high(OUT_220);
  30.          output_low(LED_LO);
  31.          output_high(LED_OK);
  32.          output_low(LED_HI);
  33.          break;
  34.       case (salida < 390):               //Si es < 390
  35.          output_low(OUT_220);
  36.          output_high(LED_LO);
  37.          output_low(LED_OK);
  38.          output_low(LED_HI);
  39.          delay_ms(3000);
  40.          break;      
  41.       }  
  42.    }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement