Advertisement
Electgpl

PIC - Multimetro con Menu

Jun 19th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.91 KB | None | 0 0
  1. #include <16F883.h>
  2. #device adc=10
  3. #FUSES XT,NOWDT
  4. #use delay(clock=4000000)
  5. #include <LCD.C>
  6. void main(){
  7.    int16 valorADC, frecuencia;
  8.    int menu=1;
  9.    float corriente, tension, diodos, temperatura, capacitancia;
  10.    setup_adc_ports(sAN0|VSS_VDD);
  11.    setup_adc(ADC_CLOCK_INTERNAL);
  12.    lcd_init();
  13.    while(TRUE){      
  14.       if(input(PIN_C1)==1){
  15.          delay_ms(200);
  16.          menu++;
  17.          if(menu>7)
  18.          menu=1;
  19.       }    
  20.       switch(menu){
  21.       case 1:
  22.          lcd_gotoxy(1,1);
  23.          printf(lcd_putc,"VOLTIMETRO    DC");
  24.          output_low(pin_c4);
  25.          output_low(pin_c5);
  26.          output_low(pin_c7);    
  27.          set_adc_channel(0);
  28.          delay_us(20);
  29.          valorADC = read_adc();
  30.          tension = 5.0 * valorADC / 1024.0;        
  31.          lcd_gotoxy(1,2);
  32.          printf(lcd_putc,"VM:10V    %1.3fV",tension*2);
  33.          break;
  34.       case 2:
  35.          lcd_gotoxy(1,1);
  36.          printf(lcd_putc,"AMPERIMETRO   DC");
  37.          output_high(pin_c4);
  38.          output_low(pin_c5);
  39.          output_low(pin_c7);
  40.          set_adc_channel(0);
  41.          delay_us(20);
  42.          valorADC = read_adc();
  43.          corriente = (5.0 * valorADC / 1024.0) * 0.2118;  
  44.          lcd_gotoxy(1,2);
  45.          printf(lcd_putc,"IM:1A     %1.3fA",corriente);
  46.          break;
  47.       case 3:
  48.          lcd_gotoxy(1,1);
  49.          printf(lcd_putc,"DIODOS Y LEDS   ");
  50.          output_low(pin_c4);
  51.          output_high(pin_c5);
  52.          output_low(pin_c7);
  53.          set_adc_channel(0);
  54.          delay_us(20);
  55.          valorADC = read_adc();
  56.          diodos = 5.0 * valorADC / 1024.0;        
  57.          lcd_gotoxy(1,2);
  58.          printf(lcd_putc,"          %1.3fV",diodos);
  59.          break;
  60.       case 4:
  61.          lcd_gotoxy(1,1);
  62.          printf(lcd_putc,"TEMPERATURA     ");
  63.          output_high(pin_c4);
  64.          output_high(pin_c5);
  65.          output_low(pin_c7);
  66.          set_adc_channel(0);
  67.          delay_us(20);
  68.          valorADC = read_adc();
  69.          temperatura = (5.0 * valorADC / 1024.0) * 100;        
  70.          lcd_gotoxy(1,2);
  71.          printf(lcd_putc,"          %2.1fâ,temperatura);
  72.         break;  
  73.      case 5:
  74.         lcd_gotoxy(1,1);
  75.         printf(lcd_putc,"CAPACITANCIA     ");
  76.         output_low(pin_c4);
  77.         output_low(pin_c5);
  78.         output_high(pin_c7);
  79.         set_timer1(0);
  80.         setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
  81.         delay_ms(1000);
  82.         setup_timer_1(T1_DISABLED);
  83.         frecuencia=get_timer1();
  84.         capacitancia = (7.178 / frecuencia) * 1000000;
  85.         lcd_gotoxy(1,2);
  86.         if(capacitancia > 1000)
  87.            printf(lcd_putc,"        %4.1f nF ",capacitancia/1000);
  88.         else  
  89.            printf(lcd_putc,"        %4.1f pF ",capacitancia);        
  90.         break;          
  91.      case 6:
  92.         lcd_gotoxy(1,1);
  93.         printf(lcd_putc,"FRECUENCIMETRO  ");
  94.         output_high(pin_c4);
  95.         output_low(pin_c5);
  96.         output_high(pin_c7);
  97.         set_timer1(0);
  98.         setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
  99.         delay_ms(1000);
  100.         setup_timer_1(T1_DISABLED);
  101.         frecuencia=get_timer1();
  102.         lcd_gotoxy(1,2);
  103.         printf(lcd_putc,"       %6lu Hz",frecuencia);
  104.         break;          
  105.      case 7:
  106.         lcd_gotoxy(1,1);
  107.         printf(lcd_putc,"CONTINUIDAD     ");
  108.         output_low(pin_c4);
  109.         output_high(pin_c5);
  110.         output_high(pin_c7);
  111.         lcd_gotoxy(1,2);
  112.         if(input(PIN_C2)==0){
  113.            printf(lcd_putc,"CIRCUITO CERRADO");
  114.            output_high(pin_c3);
  115.         }
  116.         else{  
  117.            printf(lcd_putc,"CIRCUITO ABIERTO");
  118.            output_low(pin_c3);
  119.         }            
  120.         break;        
  121.      default:
  122.         lcd_gotoxy(1,1);
  123.         printf(lcd_putc,"    **ERROR**   ");
  124.         lcd_gotoxy(1,2);
  125.         printf(lcd_putc,"   [REINICIAR]  ");      
  126.      }
  127.   }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement