
#pragma used+
sfrb TWBR=0;
sfrb TWSR=1;
sfrb TWAR=2;
sfrb TWDR=3;
sfrb ADCL=4;
sfrb ADCH=5;
sfrw ADCW=4;      
sfrb ADCSRA=6;
sfrb ADMUX=7;
sfrb ACSR=8;
sfrb UBRRL=9;
sfrb UCSRB=0xa;
sfrb UCSRA=0xb;
sfrb UDR=0xc;
sfrb SPCR=0xd;
sfrb SPSR=0xe;
sfrb SPDR=0xf;
sfrb PIND=0x10;
sfrb DDRD=0x11;
sfrb PORTD=0x12;
sfrb PINC=0x13;
sfrb DDRC=0x14;
sfrb PORTC=0x15;
sfrb PINB=0x16;
sfrb DDRB=0x17;
sfrb PORTB=0x18;
sfrb EECR=0x1c;
sfrb EEDR=0x1d;
sfrb EEARL=0x1e;
sfrb EEARH=0x1f;
sfrw EEAR=0x1e;   
sfrb UBRRH=0x20;
sfrb UCSRC=0X20;
sfrb WDTCR=0x21;
sfrb ASSR=0x22;
sfrb OCR2=0x23;
sfrb TCNT2=0x24;
sfrb TCCR2=0x25;
sfrb ICR1L=0x26;
sfrb ICR1H=0x27;
sfrw ICR1=0x26;   
sfrb OCR1BL=0x28;
sfrb OCR1BH=0x29;
sfrw OCR1B=0x28;  
sfrb OCR1AL=0x2a;
sfrb OCR1AH=0x2b;
sfrw OCR1A=0x2a;  
sfrb TCNT1L=0x2c;
sfrb TCNT1H=0x2d;
sfrw TCNT1=0x2c;  
sfrb TCCR1B=0x2e;
sfrb TCCR1A=0x2f;
sfrb SFIOR=0x30;
sfrb OSCCAL=0x31;
sfrb TCNT0=0x32;
sfrb TCCR0=0x33;
sfrb MCUCSR=0x34;
sfrb MCUCR=0x35;
sfrb TWCR=0x36;
sfrb SPMCR=0x37;
sfrb TIFR=0x38;
sfrb TIMSK=0x39;
sfrb GIFR=0x3a;
sfrb GICR=0x3b;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-

#asm
	#ifndef __SLEEP_DEFINED__
	#define __SLEEP_DEFINED__
	.EQU __se_bit=0x80
	.EQU __sm_mask=0x70
	.EQU __sm_powerdown=0x20
	.EQU __sm_powersave=0x30
	.EQU __sm_standby=0x60
	.EQU __sm_ext_standby=0x70
	.EQU __sm_adc_noise_red=0x10
	.SET power_ctrl_reg=mcucr
	#endif
#endasm

#asm
   .equ __w1_port=0x15 ;PORTC
   .equ __w1_bit=2
#endasm

#pragma used+
unsigned char w1_init(void);
unsigned char w1_read(void);
unsigned char w1_write(unsigned char data);
unsigned char w1_search(unsigned char cmd,void *p);
unsigned char w1_dow_crc8(void *p,unsigned char n);
#pragma used-

#pragma used+
extern struct __ds1820_scratch_pad_struct
{
unsigned char temp_lsb,temp_msb,
temp_high,temp_low,
res1,res2,
cnt_rem,cnt_c,
crc;
} __ds1820_scratch_pad;

unsigned char ds1820_select(unsigned char *addr);
unsigned char ds1820_read_spd(unsigned char *addr);
int ds1820_temperature_10(unsigned char *addr);
unsigned char ds1820_set_alarm(unsigned char *addr,signed char temp_low,signed char temp_high);
#pragma used-

#pragma library ds1820.lib

#asm
   .equ __lcd_port=0x12 ;PORTD
#endasm

#pragma used+

void _lcd_ready(void);
void _lcd_write_data(unsigned char data);

void lcd_write_byte(unsigned char addr, unsigned char data);

unsigned char lcd_read_byte(unsigned char addr);

void lcd_gotoxy(unsigned char x, unsigned char y);

void lcd_clear(void);
void lcd_putchar(char c);

void lcd_puts(char *str);

void lcd_putsf(char flash *str);

unsigned char lcd_init(unsigned char lcd_columns);

void lcd_control (unsigned char control);

#pragma used-
#pragma library lcd.lib

#pragma used+

void delay_us(unsigned int n);
void delay_ms(unsigned int n);

#pragma used-

unsigned int value;         
unsigned char OutValue[5];  
unsigned char LcdBuffer1[16]; 
unsigned char LcdBuffer2[16]; 

unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (0xC0 & 0xff);

delay_us(10);

ADCSRA|=0x40;

while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}

void ConversionValue(void)
{
OutValue[0] = 0x30;
OutValue[1] = 0x30;
OutValue[2] = 0x30;
OutValue[3] = 0x30;
OutValue[4] = 0x30;
while(value > 9999)
{
value -= 10000;
OutValue[4] ++;
}
while(value > 999)
{
value -= 1000;
OutValue[3] ++;
}
while(value > 99)
{
value -= 100;
OutValue[2] ++;
}        
while(value > 9)
{
value -= 10;
OutValue[1] ++;
}
OutValue[0] += value;
}

void main(void)
{
unsigned char a;

PORTB=0x3F;
DDRB=0x00;

PORTC=0x04;
DDRC=0x05;

PORTD=0x08;
DDRD=0xF7;

TCCR0=0x00;
TCNT0=0x00;

TCCR1A=0x00;
TCCR1B=0x05;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

MCUCR=0x00;

TIMSK=0x00;

ACSR=0x80;
SFIOR=0x00;

ADMUX=0xC0 & 0xff;
ADCSRA=0x87;

w1_init();

lcd_init(16);
lcd_putsf("HELLOW!!!");
delay_ms(1000);

while (1)
{       

for(a = 0; a < 64; a++)
{
value += read_adc(3);     
}
value /= 64;
value = (((unsigned long int) value)*2695/1024);            
value = (((unsigned long int) (value - 509)) * 1000) / 645;
ConversionValue(); 
lcd_gotoxy(0,0); 
lcd_putsf("DS600-1 : ");
lcd_putchar(OutValue[3]);
lcd_putchar(OutValue[2]); 
lcd_putchar(OutValue[1]);
lcd_putsf(".");
lcd_putchar(OutValue[0]); 

for(a = 0; a < 64; a++)
{
value += read_adc(1);     
}
value /= 64;
value = (((unsigned long int) value)*2695/1024);    
value = (((unsigned long int) (value - 509)) * 1000) / 645;
ConversionValue(); 
lcd_gotoxy(0,1); 
lcd_putsf("DS600-2 : ");
lcd_putchar(OutValue[3]);
lcd_putchar(OutValue[2]); 
lcd_putchar(OutValue[1]);
lcd_putsf(".");
lcd_putchar(OutValue[0]);    

value = ds1820_temperature_10(0);
ConversionValue(); 
lcd_gotoxy(2,2);
lcd_putsf("  18B20:");
lcd_putchar(0x20);
lcd_putchar(OutValue[3]);
lcd_putchar(OutValue[2]); 
lcd_putsf(".");
lcd_putchar(OutValue[1]);
lcd_putchar(OutValue[0]);   

};
}
