Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LCD module connections
- sbit LCD_RS at RB4_bit;
- sbit LCD_EN at RB5_bit;
- sbit LCD_D4 at RB0_bit;
- sbit LCD_D5 at RB1_bit;
- sbit LCD_D6 at RB2_bit;
- sbit LCD_D7 at RB3_bit;
- sbit LCD_RS_Direction at TRISB4_bit;
- sbit LCD_EN_Direction at TRISB5_bit;
- sbit LCD_D4_Direction at TRISB0_bit;
- sbit LCD_D5_Direction at TRISB1_bit;
- sbit LCD_D6_Direction at TRISB2_bit;
- sbit LCD_D7_Direction at TRISB3_bit;
- // End LCD module connections
- float pot1;
- float tensao;
- char pot1_string [8];// STRING PARA RECEBER O VALOR CONVERTIDO DA LEITURA DO POTENCIÔMETRO 1
- void main(){
- TRISA0_bit = 1; // CONFIGURA O PINO EM QUE SE ENCONTRA A PORTA ANALÓGICA AN0 COMO ENTRADA
- ADCON1 = 0b00001100;//SELECIONA OS PINOS 2, 3, 4 DO PORTA COMO ENTRADAS ANALÓGICAS
- ADC_Init();//INICIALIZA MÓDULO ANALGÓGICO
- CMCON = 0b00000111;//DESABILITA COMPARADORES INTERNOS
- Lcd_Init(); // Initialize LCD
- Lcd_Cmd(_LCD_CLEAR); // Clear display
- Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
- Lcd_Out(1,1,"Voltimetro"); // Write text in first row
- Lcd_Out(2,1,"Carregando..."); // Write text in second row
- delay_ms(200);
- while(1){
- pot1 = ADC_Get_Sample(0);
- tensao = (pot1 / 204);
- FloatToStr (tensao,pot1_string);//CONVERTE O VALOR DO TIPO INTEIRO OBTIDO PELO CONVERSOR AD NA PORTA AN0 PARA UMA STRING
- Ltrim(pot1_string);
- Lcd_Cmd(_LCD_CLEAR);
- Lcd_Out(1,1,"Voltimeter:");
- Lcd_Out(2,1,pot1_string);
- Lcd_Out(2,5,"V ");
- delay_ms(100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement