#include "C:\RS\Lux10brf\main.h"

#define LCD_RS          PIN_B0      // rizeni registru LCD displeje
#define LCD_E           PIN_B1      // enable LCD displeje
#define LCD_DATA_LSB    PIN_C4     // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
#define LUX1            PIN_B2
#define LUX2            PIN_B3
#define LUX3            PIN_B4
#define LUX4            PIN_B5
#define HOLD            PIN_B6
#define IN 0
#include "lcd.c"

void main()
{
unsigned int16 I;
float E;

   port_b_pullups(TRUE);
   setup_adc_ports(AN0_VREF_VREF);
   setup_adc(ADC_CLOCK_DIV_32);
   setup_psp(PSP_DISABLED);
   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_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   set_adc_channel (IN);
   delay_us(20); 
   lcd_init();
   
   
   while(TRUE)
   { 
   I=read_adc();        //pøeètení hodnoty z A/D pøevodníku
   delay_us(600);
   E=0.009775*I;        //výpoèet osvìtlení k=10.0/1023
         
      if(!input(LUX1))
      {
      printf(lcd_putc,"  E=%3.1f lx  \n",10*E);
      printf(lcd_putc,"  rozsah k1 \n\r");
      }
      if(!input(LUX2))
      {
      printf(lcd_putc,"  E=%3.0f lx  \n",100*E);
      printf(lcd_putc,"  rozsah 1k  \n\r");
      }
      if(!input(LUX3))
      {
      printf(lcd_putc,"  E=%3.2f klx  \n",E);
      printf(lcd_putc,"  rozsah 10k  \n\r");
      }
      if(!input(LUX4))
      {
      printf(lcd_putc,"  E=%3.1f klx  \n",10*E);
      printf(lcd_putc,"  rozsah 100k \n\r");
      }
      delay_ms(300);
      while(!input(HOLD)); //podržení hodnoty
    }   
}