/*****************************************************
This program was produced by the
CodeWizardAVR V1.25.9 Standard
Automatic Program Generator
 Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : Ver. 1.0.0
Version : 
Date    : 24.10.2011
Author  : Coviraylhik                            
Company : http://c2.at.ua                           
Comments: 


Chip type           : ATmega8
Program type        : Application
Clock frequency     : 4,000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*****************************************************/

#include <mega8.h>

// 1 Wire Bus functions
#asm
   .equ __w1_port=0x18 ;PORTB
   .equ __w1_bit=0
#endasm
#include <1wire.h>

// Alphanumeric LCD Module functions
#asm
   .equ __lcd_port=0x12 ;PORTD
#endasm
#include <lcd.h> 
#include <ds18b20.h>

#include <delay.h>
#include <stdio.h>    

unsigned char lcd_buffer[10];  



void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port B initialization
PORTB=0b00000000;
DDRB=0b11111100;

// Port C initialization
PORTC=0b10000000;
DDRC=0b00000000;

// Port D initialization
PORTD=0b00000000;
DDRD=0b00000000;


// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// 1 Wire Bus initialization
w1_init();

// LCD module initialization
lcd_init(16);                     // LCD,      16 


while (1) /*   */
  
{
unsigned char devices;         //     
int temp;                        //   
                  
devices=w1_init();               //y 
while(1)                 // ,   
      {
          temp=ds18b20_temperature(0);  //   
          if (temp>1000){               //    1000
             temp=4096-temp;            //   4096
             temp=-temp;                //   ""
          

                    } 
                    if ((temp >= 20) & (temp <= 23))    //   PORTB.6
                    PORTB.6 = 1;
                     else
                        if ((temp >= 25) & (temp <= 32))    //   
                        PORTB.6 = 1;
                        else
                        {
                        PORTB.6 = 0;
                        }
                              
                    if ((temp >= -12) & (temp <= -10))    //   PORTB.7
                    PORTB.7 = 1;
                     else
                        if ((temp >= -16) & (temp <= -14))    //   
                        PORTB.7 = 1;
                        else
                        {
                        PORTB.7 = 0;
                        }
               
      sprintf(lcd_buffer,"t=%i.%u\xdfC",temp,temp%1);    //      
      lcd_clear();    //          
      //lcd_gotoxy(0,0);            
      lcd_puts(lcd_buffer);    //  
     
      /*/     
        sprintf(lcd_buffer,"t=%i.%u\xdfC",temp,temp%1);    //     
      lcd_gotoxy(0,1);
      lcd_puts(lcd_buffer);    //       */
      delay_ms(50);              // 50   
      };
 
}
}
