abdulQ8
Newbie level 4
lm35 thermostat
I Use in my project LM35 and I want to design thermostat that if Temp >44 the DC motor on
and i write my code but i want some one to help me cause i think there is problem is ADC and the range of LM35 (how to present 44C in the program )
I uses attiny26 ,LM35 and DC motor
and this is my code (winAVR)
#define F_CPU 8000000L
#include <avr/pgmspace.h>
#include <avr/io.h>
#define setbit(port, bit) (port) |= (1 << (bit))
#define clearbit(port, bit) (port) &= ~(1 << (bit))
int main()
{
{
unsigned char x;
unsigned int result,temp;
DDRA = 0xff;
DDRB=0;
ADMUX = 0b00100111; // chan 7, left adjusted, [ref=AVCC]
ADCSR = 0b10000111; // ADC enabled,ADC interrupt enabled,
//prescalar=64 ->ADC frequency 125 kHz
while (1){
setbit(ADCSR, 6); // start conversion. can also be written ADCSR= [ADCSR | 0x40];
do {
x = ADCSR & 0x10;
}while (x == 0); // repeat until EOC
PORTA = ADCH;
}
temp=ADCH;
if(temp>44)
PortA=0xf;
else
portA=0;
return o;
}
if some one knows the write code please tell me as possible as you can
I Use in my project LM35 and I want to design thermostat that if Temp >44 the DC motor on
and i write my code but i want some one to help me cause i think there is problem is ADC and the range of LM35 (how to present 44C in the program )
I uses attiny26 ,LM35 and DC motor
and this is my code (winAVR)
#define F_CPU 8000000L
#include <avr/pgmspace.h>
#include <avr/io.h>
#define setbit(port, bit) (port) |= (1 << (bit))
#define clearbit(port, bit) (port) &= ~(1 << (bit))
int main()
{
{
unsigned char x;
unsigned int result,temp;
DDRA = 0xff;
DDRB=0;
ADMUX = 0b00100111; // chan 7, left adjusted, [ref=AVCC]
ADCSR = 0b10000111; // ADC enabled,ADC interrupt enabled,
//prescalar=64 ->ADC frequency 125 kHz
while (1){
setbit(ADCSR, 6); // start conversion. can also be written ADCSR= [ADCSR | 0x40];
do {
x = ADCSR & 0x10;
}while (x == 0); // repeat until EOC
PORTA = ADCH;
}
temp=ADCH;
if(temp>44)
PortA=0xf;
else
portA=0;
return o;
}
if some one knows the write code please tell me as possible as you can