Rev Author Line No. Line
157 pavlicek 1 #include "C:\RS\Lux10brf\main.h"
2  
180 pavlicek 3 #define LCD_RS PIN_B0 // rizeni registru LCD displeje
4 #define LCD_E PIN_B1 // enable LCD displeje
157 pavlicek 5 #define LCD_DATA_LSB PIN_C4 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou)
6 #define LUX1 PIN_B2
7 #define LUX2 PIN_B3
8 #define LUX3 PIN_B4
9 #define LUX4 PIN_B5
10 #define HOLD PIN_B6
11 #define IN 0
12 #include "lcd.c"
13  
14 void main()
15 {
16 unsigned int16 I;
17 float E;
18  
19 port_b_pullups(TRUE);
20 setup_adc_ports(AN0_VREF_VREF);
21 setup_adc(ADC_CLOCK_DIV_32);
22 setup_psp(PSP_DISABLED);
23 setup_spi(SPI_SS_DISABLED);
24 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
25 setup_timer_1(T1_DISABLED);
26 setup_timer_2(T2_DISABLED,0,1);
27 setup_comparator(NC_NC_NC_NC);
28 setup_vref(FALSE);
29  
30 set_adc_channel (IN);
31 delay_us(20);
32 lcd_init();
33  
180 pavlicek 34  
157 pavlicek 35 while(TRUE)
36 {
180 pavlicek 37 I=read_adc(); //pøeètení hodnoty z A/D pøevodníku
157 pavlicek 38 delay_us(600);
180 pavlicek 39 E=0.009775*I; //výpoèet osvìtlení k=10.0/1023
40  
157 pavlicek 41 if(!input(LUX1))
42 {
180 pavlicek 43 printf(lcd_putc," E=%3.1f lx \n",10*E);
44 printf(lcd_putc," rozsah k1 \n\r");
157 pavlicek 45 }
46 if(!input(LUX2))
47 {
180 pavlicek 48 printf(lcd_putc," E=%3.0f lx \n",100*E);
49 printf(lcd_putc," rozsah 1k \n\r");
157 pavlicek 50 }
51 if(!input(LUX3))
52 {
180 pavlicek 53 printf(lcd_putc," E=%3.2f klx \n",E);
54 printf(lcd_putc," rozsah 10k \n\r");
157 pavlicek 55 }
56 if(!input(LUX4))
57 {
180 pavlicek 58 printf(lcd_putc," E=%3.1f klx \n",10*E);
59 printf(lcd_putc," rozsah 100k \n\r");
60 }
157 pavlicek 61 delay_ms(300);
180 pavlicek 62 while(!input(HOLD)); //podržení hodnoty
63 }
157 pavlicek 64 }