#include "C:\Users\Honza\Documents\pic\tomas\main.h"

#define LCD_RS          PIN_C7      // rizeni registru LCD displeje <lcd.c>
#define LCD_E           PIN_B7      // enable LCD displeje <lcd.c>
#define LCD_D0          PIN_B6      // data LCD  <lcd.c>
#define LCD_D1          PIN_B5
#define LCD_D2          PIN_B4
#define LCD_D3          PIN_D4
#include "LCD.C"  //pro LCD

int1 value=0;

#INT_EXT //preruseni od RB0
void  EXT_isr(void)
{

   value=~value;
   
}

void main()
{
double value1, value2;
enable_interrupts(INT_EXT); //povolení pøeruseni
enable_interrupts(GLOBAL);
ext_int_edge(H_TO_L);
setup_adc_ports(PIN_A0); //piny pro A/D RA0
setup_adc_ports(PIN_A1); //piny pro A/D RA1
setup_adc(ADC_CLOCK_DIV_8);

  
  

   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);      
   setup_oscillator(OSC_8MHZ);

      lcd_init(); //inicializuje LCD
      
      LCD_gotoxy(1,1);  //na LCD 1bunka 1øadek
      printf(lcd_putc,"Tomas Pavlicek"); 
      LCD_gotoxy(1,2);
      printf(lcd_putc,"CVUT   2012/2013"); 
      Delay_ms(1000);
      
while(true)
   {
     lcd_init(); //inicializuje LCD
      set_adc_channel(0); //nastavi AD na kanál 0 (RA0)
      read_adc(ADC_START_ONLY);              // Spustime A/D prevod
     Delay_ms(1);  
      while(!adc_done());                    // Cekame na dokonceni prevodu
      value1=read_adc();            // Precteme hodnotu z prevodniku
      //Delay_ms(100);
      set_adc_channel(1); //nastavi AD na kanál 1 (RA1)
      read_adc(ADC_START_ONLY);              // Spustime A/D prevod
      Delay_ms(1); 
      while(!adc_done());                    // Cekame na dokonceni prevodu
      value2=read_adc();            // Precteme hodnotu z prevodniku
     
     
     if(value==1)
     {
      LCD_gotoxy(1,1);  //na LCD 1bunka 1øadek
      printf(lcd_putc,"Napeti:%5.3f V", value1);; 
      LCD_gotoxy(1,2);
      printf(lcd_putc,"Proud:%5.3f I", value2); 
     
     }
     else
     {
      LCD_gotoxy(1,1);  //na LCD 1bunka 1øadek
      printf(lcd_putc,"Napeti:%5.3f V", value1);; 
      LCD_gotoxy(1,2);
      printf(lcd_putc,"Naboj:%5.3f I", value2); 
    
     }
     Delay_ms(500);
   }
}