Commit 46b07b74 authored by Martin Enriquez's avatar Martin Enriquez

Se agregan las funciones de conversion de temperatura del ADC para el sensor LM35

parent e1f863c1
......@@ -25,9 +25,10 @@
*/
#include "configuracion.h"
#include "adc.h"
#define VCC 3.3
void inicializarADC(void) {
ADMUX |= (3 << REFS0) | (1 << ADLAR); // Tension de referencia interna de 2,53V y ajuste a la izquierda
ADMUX |= (3 << REFS0); // Tension de referencia= Vcc (3,3) y ajuste a la izquierda
// Se usa ADC0
ADCSRA |= (1 << ADEN); // Habilita el ADC
}
......@@ -39,3 +40,20 @@ unsigned char convertirADC0(void) {
}
unsigned char gradosToLectADC(unsigned char grados)
{
int lectura;
lectura = grados * 256 / (VCC*100);
if (lectura>255) lectura = 255;
if (lectura <0) lectura =0;
return (unsigned char)lectura;
}
unsigned char lectADCToGrados(unsigned char lectura)
{
int grados;
grados = lectura * VCC * 100 / 256;
if (grados>150) grados= 150;
if (grados <0) grados=0;
return (unsigned char)grados;
}
......@@ -27,7 +27,11 @@
#ifndef ADC_H_
#define ADC_H_
#define UN_VALOR 23
void inicializarADC(void);
unsigned char lectADCToGrados (unsigned char);
unsigned char gradosToLectADC (unsigned char);
unsigned char convertirADC0(void);
......
......@@ -34,14 +34,23 @@
#include "hardware.h"
#include "configuracion.h"
#include "mcu.h"
#include "adc.h"
unsigned char temperatura;
int main (void) {
inicializarTodo();
ledBlink();
while(1){
temperatura = convertirADC0();
if (temperatura > UN_VALOR)
{
LED=0; //encendido
}
else
{
LED = 1; //apagado
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment