Rev Author Line No. Line
1045 jacho 1 #include "C:\Users\Honza\Documents\pic\tomas\main.h"
2  
3 #define LCD_RS PIN_C7 // rizeni registru LCD displeje <lcd.c>
4 #define LCD_E PIN_B7 // enable LCD displeje <lcd.c>
5 #define LCD_D0 PIN_B6 // data LCD <lcd.c>
6 #define LCD_D1 PIN_B5
7 #define LCD_D2 PIN_B4
8 #define LCD_D3 PIN_D4
9 #include "LCD.C" //pro LCD
10  
11 int1 value=0;
12  
13 #INT_EXT //preruseni od RB0
14 void EXT_isr(void)
15 {
16  
17 value=~value;
18  
19 }
20  
21 void main()
22 {
23 double value1, value2;
24 enable_interrupts(INT_EXT); //povolení pøeruseni
25 enable_interrupts(GLOBAL);
26 ext_int_edge(H_TO_L);
27 setup_adc_ports(PIN_A0); //piny pro A/D RA0
28 setup_adc_ports(PIN_A1); //piny pro A/D RA1
29 setup_adc(ADC_CLOCK_DIV_8);
30  
31  
32  
33  
34 setup_spi(SPI_SS_DISABLED);
35 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
36 setup_timer_1(T1_DISABLED);
37 setup_timer_2(T2_DISABLED,0,1);
38 setup_ccp1(CCP_OFF);
39 setup_comparator(NC_NC_NC_NC);
40 setup_oscillator(OSC_8MHZ);
41  
42 lcd_init(); //inicializuje LCD
43  
44 LCD_gotoxy(1,1); //na LCD 1bunka 1øadek
45 printf(lcd_putc,"Tomas Pavlicek");
46 LCD_gotoxy(1,2);
47 printf(lcd_putc,"CVUT 2012/2013");
48 Delay_ms(1000);
49  
50 while(true)
51 {
52 lcd_init(); //inicializuje LCD
53 set_adc_channel(0); //nastavi AD na kanál 0 (RA0)
54 read_adc(ADC_START_ONLY); // Spustime A/D prevod
55 Delay_ms(1);
56 while(!adc_done()); // Cekame na dokonceni prevodu
57 value1=read_adc(); // Precteme hodnotu z prevodniku
58 //Delay_ms(100);
59 set_adc_channel(1); //nastavi AD na kanál 1 (RA1)
60 read_adc(ADC_START_ONLY); // Spustime A/D prevod
61 Delay_ms(1);
62 while(!adc_done()); // Cekame na dokonceni prevodu
63 value2=read_adc(); // Precteme hodnotu z prevodniku
64  
65  
66 if(value==1)
67 {
68 LCD_gotoxy(1,1); //na LCD 1bunka 1øadek
69 printf(lcd_putc,"Napeti:%5.3f V", value1);;
70 LCD_gotoxy(1,2);
71 printf(lcd_putc,"Proud:%5.3f I", value2);
72  
73 }
74 else
75 {
76 LCD_gotoxy(1,1); //na LCD 1bunka 1øadek
77 printf(lcd_putc,"Napeti:%5.3f V", value1);;
78 LCD_gotoxy(1,2);
79 printf(lcd_putc,"Naboj:%5.3f I", value2);
80  
81 }
82 Delay_ms(500);
83 }
84 }
85