Electgpl

PIC - Medidor Potencia

Sep 2nd, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <16F883.h>
  2. #device adc=8
  3. #use delay(int=4000000)
  4. #include <LCD.C>
  5. void main(){
  6.    setup_adc_ports(sAN0|sAN1|sAN2|VSS_VDD);
  7.    setup_adc(ADC_CLOCK_DIV_2);
  8.    setup_spi(SPI_SS_DISABLED);
  9.    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
  10.    setup_timer_1(T1_DISABLED);
  11.    setup_timer_2(T2_DISABLED,0,1);
  12.    setup_ccp1(CCP_OFF);
  13.    setup_comparator(NC_NC_NC_NC);
  14.    lcd_init();
  15.    int8 currentADC, voltajeADC;
  16.    float current, voltaje, power;
  17.    while(TRUE){
  18.       set_adc_channel(0);
  19.       delay_us(10);
  20.       currentADC = read_adc();
  21.       current = (5.0 * currentADC / 255)/4.7;
  22.       set_adc_channel(1);
  23.       delay_us(10);
  24.       voltajeADC = read_adc();      
  25.       voltaje = ((5.0 * voltajeADC / 255)*3.2)-current*4.7;
  26.       power = voltaje * current;
  27.       lcd_gotoxy(1,1);      
  28.       if(voltaje>9.99)
  29.       printf(lcd_putc,"V:%02.2f Po:%01.2f ",voltaje,power);
  30.       else
  31.          printf(lcd_putc,"V:%02.2f  Po:%01.2f ",voltaje,power);
  32.       lcd_gotoxy(1,2);
  33.       printf(lcd_putc,"A:%01.3f         ",current);  
  34.    }  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment