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