#include "C:\Program Files\PICC\ds1820\DS02.h"

#include<lcd_sam3.c>
#include<touch.c>
VOID read_temp(void);
byte buffer[2];
byte temp,a,b,c;
byte const num[12] = {'0','1','2','3','4','5','6','7','8','9','*','o'};
void hex_bcd(int8 k);

void main()
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
  while(1)
   {
     read_temp();
     hex_bcd(TEMP);
     lcd_gotoxy(5,1);
     lcd_putc(num[a]);
     lcd_putc(num[b]);
     lcd_putc(num[c]);
   }
}
VOID read_temp(void)
{
        if(touch_present())
        {
         touch_write_byte(0xCC);
         touch_write_byte (0x44);
         output_high(TOUCH_PIN);
         delay_ms(20);
         touch_present();
         touch_write_byte(0xCC);
         touch_write_byte (0xBE);
         buffer[0] = touch_read_byte();
         buffer[1] = touch_read_byte();
         temp=buffer[0]/2;// get temperature

        }
}
void hex_bcd(int8 k)
{
   a=0;b=0;c=0;
   while(k>=100)
   {
    a++;
    k-=100;
   }
   while(k>=10)
   {
    b++;
    k-=10;
   }
   c=k;
}


