You are on page 1of 2

1 //----------LM35 TESTE -- PIC18F4550----------

2
3 // CLK 8MHZ
4
5
6 //----------LCD-----------
7 sbit LCD_RS at RD2_bit;
8 sbit LCD_EN at RD3_bit;
9 sbit LCD_D4 at RD4_bit;
10 sbit LCD_D5 at RD5_bit;
11 sbit LCD_D6 at RD6_bit;
12 sbit LCD_D7 at RD7_bit;
13
14 sbit LCD_RS_Direction at TRISD2_bit;
15 sbit LCD_EN_Direction at TRISD3_bit;
16 sbit LCD_D4_Direction at TRISD4_bit;
17 sbit LCD_D5_Direction at TRISD5_bit;
18 sbit LCD_D6_Direction at TRISD6_bit;
19 sbit LCD_D7_Direction at TRISD7_bit;
20 //end LCD
21
22 //--------VARIAVEIS--------
23 unsigned int ADC_R; //Leitura sinal ADC
24 float TempC; //Armazena o valor da temperatura
25 char TempC_text[15]; //Armazena o valor da temperatura
convertida para string
26 //end variaveis
27
28 void get_temp() {
29 ADC_R = ADC_Read(0); //Leitura analogica no AN0
30
31
32 TempC = ADC_R * 5; //Calculo da temperatura
33
34 TempC = TempC / 1023;
35
36 TempC = TempC * 100;
37
38
39 floattostr(TempC,TempC_text); //Converte a temperatura em string
40
41 Lcd_Out(1,1,"Temp: ");
42 Lcd_Out(2,1,TempC_text);
43 Lcd_chr_cp('C'); //Unidade Celcius "C"
44
45 }//end get_temp
46
47 //----------FUNCAO PRINCIPAL----------
48 void main() {
49 TRISA = 0xFF; //Configura todo PORTA como entrada
50 TRISB = 0x00; //Configura todo PORTB como saida
51
52 ADCON0 = 0b00000001; //Liga conversor AD no canal AN0
53 ADCON1 = 0b00001110; //Configura somente o pino AN0 como
analogico
54 ADCON2 = 0b00011101; //Configurado com Fosc/16 - 101 - e
6TAD - 011
55
56 Lcd_Init(); //Inicializa modulo LCD
57 Lcd_Cmd(_LCD_CURSOR_OFF); //Apaga cursor
58 Lcd_Cmd(_LCD_CLEAR); //Limpa display
59
60 lcd_out(1,1,"Teste LM35"); //Escreve o texto uma vez no display,
linha 1, coluna1
61 lcd_out(2,1,"11/11/2021"); //Escreve o texto uma vez no display,
linha 2, coluna 1
62 delay_ms(1000);
63 Lcd_Cmd(_LCD_CLEAR); //Limpa display
64
65 while(1) {
66 get_temp();
67 delay_ms(500);
68 }
69
70 }//end main
71
72
73

You might also like