Advertisement
Guest User

C Voltimeter PIC18F4550

a guest
Apr 25th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. // LCD module connections
  2. sbit LCD_RS at RB4_bit;
  3. sbit LCD_EN at RB5_bit;
  4. sbit LCD_D4 at RB0_bit;
  5. sbit LCD_D5 at RB1_bit;
  6. sbit LCD_D6 at RB2_bit;
  7. sbit LCD_D7 at RB3_bit;
  8. sbit LCD_RS_Direction at TRISB4_bit;
  9. sbit LCD_EN_Direction at TRISB5_bit;
  10. sbit LCD_D4_Direction at TRISB0_bit;
  11. sbit LCD_D5_Direction at TRISB1_bit;
  12. sbit LCD_D6_Direction at TRISB2_bit;
  13. sbit LCD_D7_Direction at TRISB3_bit;
  14. // End LCD module connections
  15. float pot1;
  16. float tensao;
  17. char pot1_string [8];// STRING PARA RECEBER O VALOR CONVERTIDO DA LEITURA DO POTENCIÔMETRO 1
  18. void main(){
  19.      TRISA0_bit = 1;  // CONFIGURA O PINO EM QUE SE ENCONTRA A PORTA ANALÓGICA AN0 COMO ENTRADA
  20.      ADCON1 = 0b00001100;//SELECIONA OS PINOS 2, 3, 4 DO PORTA COMO ENTRADAS ANALÓGICAS
  21.      ADC_Init();//INICIALIZA MÓDULO ANALGÓGICO
  22.      CMCON = 0b00000111;//DESABILITA COMPARADORES INTERNOS
  23.      Lcd_Init();                        // Initialize LCD
  24.      Lcd_Cmd(_LCD_CLEAR);               // Clear display
  25.      Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  26.      Lcd_Out(1,1,"Voltimetro");                 // Write text in first row
  27.      Lcd_Out(2,1,"Carregando...");                 // Write text in second row
  28.      delay_ms(200);
  29.     while(1){
  30.         pot1 = ADC_Get_Sample(0);
  31.         tensao = (pot1 / 204);
  32.         FloatToStr (tensao,pot1_string);//CONVERTE O VALOR DO TIPO INTEIRO OBTIDO PELO CONVERSOR AD NA PORTA AN0 PARA UMA STRING
  33.         Ltrim(pot1_string);
  34.         Lcd_Cmd(_LCD_CLEAR);
  35.         Lcd_Out(1,1,"Voltimeter:");
  36.         Lcd_Out(2,1,pot1_string);
  37.         Lcd_Out(2,5,"V           ");
  38.         delay_ms(100);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement