Electgpl

PIC - Medidor VA con GLCD

Nov 20th, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. #include <16F887.h>
  2. #device adc=10
  3. #fuses HS,NOWDT,NOPROTECT,NOLVP
  4. #use delay(clock=20000000)
  5. #include <HDM64GS12.c>
  6. #include <graphics.c>
  7. void main(){
  8.    int16 voltajeADC, voltajeADC_ant,
  9.          corrienteADC, corrienteADC_ant;
  10.    setup_adc_ports(sAN0|sAN1|VSS_VDD);
  11.    setup_adc(ADC_CLOCK_DIV_2);
  12.    char nombre[]="Electgpl";
  13.    char parametro[]="   [V]       [A]   ";
  14.    char voltaje[9];
  15.    char corriente[9];
  16.    glcd_init(ON);
  17.    glcd_rect(1, 1, 127, 63, NO, ON);
  18.    glcd_rect(3, 3, 125, 13, NO, ON);
  19.    glcd_text57(41, 5, nombre, 1, ON);
  20.    glcd_rect(3, 15, 125, 25, NO, ON);
  21.    glcd_text57(8, 17, parametro, 1, ON);
  22.    glcd_rect(3, 27, 125, 61, NO, ON);
  23.    while(true){
  24.       set_adc_channel(0);
  25.       delay_us(10);
  26.       voltajeADC=read_adc();
  27.       if(voltajeADC_ant != voltajeADC){
  28.          glcd_text57(13, 38, voltaje, 2, OFF);
  29.          sprintf(voltaje, "%1.2f", (float)voltajeADC*5/1023.0);
  30.          voltaje[4] = '\0';
  31.          glcd_text57(13, 38, voltaje, 2, ON);  
  32.          voltajeADC_ant=voltajeADC;
  33.       }
  34.       set_adc_channel(1);
  35.       delay_us(10);
  36.       corrienteADC=read_adc();
  37.       if(corrienteADC_ant != corrienteADC){
  38.          glcd_text57(70, 38, corriente, 2, OFF);
  39.          sprintf(corriente, "%1.2f", (float)corrienteADC*5/1023.0);
  40.          corriente[4] = '\0';
  41.          glcd_text57(70, 38, corriente, 2, ON);  
  42.          corrienteADC_ant=corrienteADC;
  43.       }  
  44.    }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment