Rev Author Line No. Line
2596 kaklik 1 #include ".\main.h"
2 //#include <LCD.C>
3  
2600 kaklik 4 #define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
5 #define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
6 #define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
7 #define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5
2596 kaklik 8  
9  
2600 kaklik 10 #int_EXT
11 void EXT_isr(void)
12 {
13 output_toggle(LED3);
14 }
15  
2596 kaklik 16 //#define LCD_TYPE 1
17 //#include <lcd.c>
18 void main()
19 {
20 unsigned int setpoint;
21 unsigned int napeti;
2600 kaklik 22 unsigned int16 plneni=0;
2596 kaklik 23  
24 /* lcd_init();
25  
26 lcd_putc("\fReady...\n");
27  
28 while (TRUE) {
29 k=kbd_getc();
30 if(k!=0)
31 if(k=='*')
32 lcd_putc('\f');
33 else
34 lcd_putc(k);
35 }
36 */
37  
38 setup_adc_ports(sAN0|VSS_VDD);
39 setup_adc(ADC_CLOCK_DIV_32);
40 setup_spi(SPI_SS_DISABLED);
41 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
42 setup_timer_1(T1_DISABLED);
43 setup_timer_2(T2_DIV_BY_1,255,1);
44 setup_ccp1(CCP_PWM);
45 setup_ccp2(CCP_PWM);
46 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
47 setup_oscillator(OSC_8MHZ);
48  
49 set_pwm1_duty(0);
50 set_pwm2_duty(0);
51  
52  
2600 kaklik 53 output_high(LED1);
54 output_high(LED2);
55 output_high(LED3);
56 output_high(LED4);
57  
58 ext_int_edge( L_TO_H ); // Sets up EXT
59 enable_interrupts(INT_EXT);
60 enable_interrupts(GLOBAL);
61  
2596 kaklik 62 // lcd_init();
63  
2600 kaklik 64 setpoint = 43;
2596 kaklik 65  
66 while(true)
67 {
68 set_adc_channel(1);
69 delay_us(100);
70 napeti = read_adc();
71  
72 if (napeti <= setpoint)
73 {
2600 kaklik 74 if (plneni < 300) plneni++;
75 output_low(LED2);
2596 kaklik 76 }
77 else
78 {
79 if (plneni > 0) plneni--;
2600 kaklik 80 output_high(LED2);
2596 kaklik 81 }
82  
83 set_pwm1_duty(plneni);
2600 kaklik 84 set_pwm2_duty(1023-plneni);
2596 kaklik 85  
2600 kaklik 86 output_toggle(LED1);
87 delay_ms(10);
2596 kaklik 88 }
89  
90 }