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