Last active
May 14, 2020 15:34
-
-
Save tiagohm/4d1418020960e1707e214187bee5b214 to your computer and use it in GitHub Desktop.
Sensor de Temperatura.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
TC1047A - Sensor de temperatura. | |
Autor: Tiago Melo | |
Blog: Microcontrolandos | |
Compilador: MikroC PRO PIC | |
Bibliotecas: ADC, Lcd, Lcd_Constants, Conversions, C_String | |
*/ | |
// Pinos do LCD. | |
sbit LCD_RS at RC0_bit; | |
sbit LCD_EN at RC1_bit; | |
sbit LCD_D4 at RC2_bit; | |
sbit LCD_D5 at RC3_bit; | |
sbit LCD_D6 at RC4_bit; | |
sbit LCD_D7 at RC5_bit; | |
sbit LCD_RS_Direction at TRISC0_bit; | |
sbit LCD_EN_Direction at TRISC1_bit; | |
sbit LCD_D4_Direction at TRISC2_bit; | |
sbit LCD_D5_Direction at TRISC3_bit; | |
sbit LCD_D6_Direction at TRISC4_bit; | |
sbit LCD_D7_Direction at TRISC5_bit; | |
// O PIC16F876A tem um ADC de 10 bits. | |
#define RESOLUCAO_ADC 10 | |
signed TC1047A_Read(char channel) { | |
long adc = ADC_Get_Sample(channel); | |
return ((adc * 500) >> RESOLUCAO_ADC) - 50; | |
} | |
void main() { | |
char texto[5]; | |
// Define somente o pino RA0 como analógico. | |
ADCON1 = 0x0E; | |
// Desabilita o comparador analógico. | |
CMCON = 7; | |
// Inicializa o módulo ADC. | |
ADC_Init(); | |
// Inicializa o LCD. | |
Lcd_Init(); | |
Lcd_Cmd(_LCD_CLEAR); | |
Lcd_Cmd(_LCD_CURSOR_OFF); | |
while(1) { | |
// Lê a temperatura. Canal analógico 0. | |
signed valor = TC1047A_Read(0); | |
// Converte em texto. | |
IntToStr(valor, texto); | |
// Escreve no LCD. | |
Lcd_Out(2, 1, texto); | |
Lcd_Chr_CP(223); // O símbolo de °. | |
Lcd_Chr_CP('C'); | |
// Faz nada durante 1s. | |
Delay_ms(1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment