Electgpl

PIC - Medición TrueRMS v1

Apr 25th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <16F883.h>
  2. #device adc=10
  3. #use delay(int=4000000)
  4. #include <LCD.C>
  5. #include <math.h>
  6. void main(){
  7.    setup_adc_ports(sAN0|VSS_VDD);
  8.    setup_adc(ADC_CLOCK_DIV_2);
  9.    int16 i;
  10.    float adc1, valorMax=0;
  11.    lcd_init();
  12.    while(true){
  13.       do{
  14.          set_adc_channel(0);
  15.          adc1=read_adc()*5.0/1023.0;
  16.          delay_us(20);
  17.       }while(adc1!=0);
  18.       for(i=0;i<300;i++){
  19.          set_adc_channel(0);
  20.          adc1=read_adc()*5.0/1023.0;
  21.          delay_us(60);
  22.          valorMax=adc1*adc1+valorMax;
  23.       }  
  24.       lcd_gotoxy(1,1);
  25.       printf(lcd_putc,"Voltimetro Trms");
  26.       lcd_gotoxy(1,2);
  27.       printf(lcd_putc,"Val RMS: %3.0f ",(sqrt(valorMax/300)*75)+44);
  28.       valorMax=0;
  29.    }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment