Electgpl

PIC - Medidor de V A P para Fuentes con promedio

Jun 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <16F883.h>
  2. #device adc=10
  3. #use delay(int=4000000)
  4. #include <LCD.C>
  5. void main(){
  6.    setup_adc_ports(sAN0|sAN1|VSS_VDD);
  7.    setup_adc(ADC_CLOCK_DIV_2);
  8.    lcd_init();
  9.    int i;
  10.    int16 vecCorr[10], vecVolt[10];
  11.    int16 auxCorr=0, auxVolt=0;
  12.    int16 currentADC, voltajeADC;
  13.    float current, voltaje, power;
  14.    while(TRUE){
  15.       for(i=0;i<10;i++){
  16.          set_adc_channel(0);
  17.          delay_us(200);
  18.          currentADC=read_adc();
  19.          vecCorr[i]=currentADC;
  20.          set_adc_channel(1);
  21.          delay_us(200);
  22.          voltajeADC=read_adc();      
  23.          vecVolt[i]=voltajeADC;        
  24.       }
  25.       auxCorr=0;
  26.       auxVolt=0;
  27.       for(i=0;i<10;i++){
  28.          auxCorr=vecCorr[i]+auxCorr;
  29.          auxVolt=vecVolt[i]+auxVolt;        
  30.       }
  31.       delay_ms(500);
  32.       current=(5.0*(auxCorr/5)/1023.0)/1.6665;
  33.       voltaje=((5.0*(auxVolt/5)/1023.0)/0.151)-(current/10);
  34.       power=voltaje*current;
  35.       lcd_gotoxy(1,1);      
  36.       if(voltaje>9.999)
  37.          printf(lcd_putc," %02.2fV %02.3fA ",voltaje,current);
  38.       else              
  39.          printf(lcd_putc,"  %02.2fV %02.3fA",voltaje,current);    
  40.       lcd_gotoxy(1,2);
  41.       if(power>9.999)
  42.          printf(lcd_putc,"     %02.2fW      ",power);  
  43.       else              
  44.          printf(lcd_putc,"      %02.2fW     ",power);        
  45.    }  
  46. }
Add Comment
Please, Sign In to add comment