
Department of Computer Science and Electronics
37
eeprom_write_word((unsigned int*) &val[i],result_c[i]);
}
}
unsigned int read_data(unsigned int chanel)
{
wdt_reset ();
ADMUX=0x40;
ADMUX|=(1<<REFS0) + chanel;
PORTB|=(1<<EN_TRANSISTOR);
_delay_ms(1);
ADCSRA|=(1<<ADSC);
do
{}
while(ADCSRA&(1<<ADSC));
PORTB&=~(1<<EN_TRANSISTOR);
return (unsigned int)ADCW;
}
void send_sensors_state(void)
{
dades=0x00;
for(i=0;i<=7;i++)
{
data_sensor[i]=read_data(i);
if(data_sensor[i]>=result_c[i])
{
dades|=(1<<i);
}
else
{
dades=dades | 0b00000000;
}
}
while ((UCSRA & (1 << UDRE)) == 0) {};// Do nothing until UDR is
ready for more data to be written to it
PORTB|=(1<<ENABLE);
UDR=dades;
while ((UCSRA & (1 << UDRE)) == 0) {}
_delay_us(30);
PORTB&=~(1<<ENABLE);
}
int main (void)
{
init_function();
while (1)
{
wdt_reset ();
while ((UCSRA & (1 << RXC)) == 0) {}; // Do nothing until
data have been recieved and is ready to be read from UDR
my_UDR=UDR;
address=my_UDR&0X0f;
function=my_UDR&0xf0;
if((address==my_address)||(address==0x00))
{
if(function==0x80)
{
calibrar();
result_calibration_eeprom();
}
else
{
send_sensors_state();
}
}
}
}
Comentarios a estos manuales