Advertisement
Electgpl

PIC - Instrumento de Medición para Fuentes

May 8th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 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.    lcd_gotoxy(1,1);
  15.    printf(lcd_putc,"  Medidor  VAP  ");
  16.    lcd_gotoxy(1,2);
  17.    printf(lcd_putc,"  Version 2017  ");
  18.    delay_ms(2000);
  19.    lcd_init();
  20.    while(TRUE){
  21.       for(i=0;i<10;i++){
  22.          set_adc_channel(0);
  23.          delay_us(200);
  24.          currentADC=read_adc();
  25.          vecCorr[i]=currentADC;
  26.          set_adc_channel(1);
  27.          delay_us(200);
  28.          voltajeADC=read_adc();
  29.          vecVolt[i]=voltajeADC;
  30.       }
  31.       auxCorr=0;
  32.       auxVolt=0;
  33.       for(i=0;i<10;i++){
  34.          auxCorr=vecCorr[i]+auxCorr;
  35.          auxVolt=vecVolt[i]+auxVolt;
  36.       }
  37.       delay_ms(500);
  38.       current=(5.0*(auxCorr/10)/1023.0)/1.6665;
  39.       voltaje=((5.0*(auxVolt/10)/1023.0)/0.151)-(current/10);
  40.       power=voltaje*current;
  41.       lcd_gotoxy(1,1);
  42.       if(voltaje>9.999)
  43.          printf(lcd_putc," %02.2fV %02.3fA ",voltaje,current);
  44.       else
  45.          printf(lcd_putc,"  %02.2fV %02.3fA",voltaje,current);
  46.       lcd_gotoxy(1,2);
  47.       if(power>9.999)
  48.          printf(lcd_putc,"     %02.2fW      ",power);
  49.       else
  50.          printf(lcd_putc,"      %02.2fW     ",power);
  51.    }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement