Skip to content

Instantly share code, notes, and snippets.

@tiagohm tiagohm/TC1047A.c
Created Mar 3, 2018

What would you like to do?
Sensor de Temperatura.
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 (2^10 = 1024)
#define RESOLUCAO_ADC 1024
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.
//Inicializa o LCD.
while(1) {
//Temperatura. Canal analógico 0.
signed valor = TC1047A_Read(0);
//Converte em texto.
IntToStr(valor, texto);
//Escreve no LCD.
Lcd_Out(2, 1, texto);
//Faz nada durante 1s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.