digital thermometer
2009-05-18 by alex levenie
hi everybody,i hope you all be fine
my circuit is a digital thermometer using two lm35(sensor), atmega8(master), two atmega 32(slaves)
the master must read two sensors output voltage and send each one to different slave ,
the slaves must show the tempreture according to corresponding formula ,
but the circuit dosn't work,it just show the primary data on lcd ("hello...")
but after the turning on the circuit ,I must disconnect and connect the power supply in a very short time to make the circuit show the tempreture,also sometimes one of slaves show (after that work) sometimes two , sometimes none of them
please help me
here is the master program:
/*****************************************************
Chip type : ATmega8
Program type : Application
Clock frequency : 1.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega8.h>
#include <delay.h>
// SPI functions
#include <spi.h>
#define Slave_select_1 PORTD.7
#define Slave_select_2 PORTB.0
#define ADC_VREF_TYPE 0xE0
unsigned char read_adc(unsigned char);
void main(void)
{
PORTB=0x00;
DDRB=0x2D;
PORTD=0x00;
DDRD=0x80;
// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: Int., cap. on AREF
// ADC High Speed Mode: Off
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x83;
SFIOR&=0xEF;
// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 250.000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: High
// SPI Data Order: LSB First
SPCR=0x7C;
SPSR=0x00;
Slave_select_1=1;
Slave_select_2=1;
while (1)
{
Slave_select_1=0;
spi(read_adc(5));
Slave_select_1=1;
Slave_select_2=0;
spi(read_adc(4));
Slave_select_2=1;
delay_ms(500);
};
}
and this is the slave program:
/*****************************************************
Chip type : ATmega32
Program type : Application
Clock frequency : 1.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega32.h>
// SPI functions
#include <spi.h>
#include <stdio.h>
#include <stdlib.h>
#include <delay.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x12
#endasm
#include <lcd.h>
char buffer_lcd[40],lcd[40];
void main(void)
{
PORTB=0x00;
DDRB=0x40;
PORTD=0x00;
DDRD=0x00;
// SPI initialization
// SPI Type: Slave
// SPI Clock Rate: 250.000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: High
// SPI Data Order: LSB First
SPCR=0xEC;
SPSR=0x00;
// Clear the SPI interrupt flag
#asm
in r30,spsr
in r30,spdr
#endasm
lcd_init(20);
lcd_clear();
lcd_putsf("hello");
delay_ms(1000);
lcd_clear();
lcd_putsf("micolab project");
delay_ms(1000);
lcd_clear();
lcd_putsf("first semester");
delay_ms(1000);
lcd_gotoxy(0,1);
lcd_putsf("2009");
delay_ms(2000);
// Global enable interrupts
#asm("sei")
while (1);
}
//------------------------------------
// SPI interrupt service routine
interrupt [SPI_STC] void spi_isr(void)
{
unsigned char data;
float temp ,index;
data=SPDR;
index=data*2.56/256;
temp=index/0.01;
lcd_clear();
ftoa(temp,2,buffer_lcd);
sprintf(lcd,"temp %2s \xdfc ",buffer_lcd);
lcd_puts(lcd);
}
that's all , please help me
[Non-text portions of this message have been removed]