1 |
#include ".\main.h" |
1 |
#include ".\main.h" |
2 |
|
2 |
|
3 |
#define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 |
3 |
#define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 |
4 |
#define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 |
4 |
#define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 |
5 |
#define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER |
5 |
#define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER |
6 |
#define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER |
6 |
#define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER |
7 |
|
7 |
|
8 |
#define S1 PIN_B0 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 |
8 |
#define S1 PIN_B0 //Raw up |
9 |
#define S2 PIN_B1 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 |
9 |
#define S2 PIN_B1 //Raw down |
10 |
#define S3 PIN_D0 //CHANGE PIN_XX TO YOUR LED PIN NUMBER |
10 |
#define S3 PIN_D0 //Fine up |
11 |
#define S4 PIN_D1 //CHANGE PIN_XX TO YOUR LED PIN NUMBER |
11 |
#define S4 PIN_D1 //Fine down |
12 |
|
12 |
|
13 |
#define BEEP PIN_D2 //piezo beeper |
13 |
#define BEEP PIN_D2 //piezo beeper |
14 |
|
14 |
|
15 |
#define LCD_ENABLE_PIN PIN_E0 //// |
15 |
#define LCD_ENABLE_PIN PIN_E0 //// |
16 |
#define LCD_RS_PIN PIN_E1 //// |
16 |
#define LCD_RS_PIN PIN_E1 //// |
17 |
#define LCD_RW_PIN PIN_E2 //// |
17 |
#define LCD_RW_PIN PIN_E2 //// |
18 |
#define LCD_DATA4 PIN_D4 //// |
18 |
#define LCD_DATA4 PIN_D4 //// |
19 |
#define LCD_DATA5 PIN_D5 //// |
19 |
#define LCD_DATA5 PIN_D5 //// |
20 |
#define LCD_DATA6 PIN_D6 //// |
20 |
#define LCD_DATA6 PIN_D6 //// |
21 |
#define LCD_DATA7 PIN_D7 |
21 |
#define LCD_DATA7 PIN_D7 |
22 |
#include <lcd.c> |
22 |
#include <lcd.c> |
23 |
|
23 |
|
- |
|
24 |
#define OUTPUT_ENABLE PIN_C1 |
- |
|
25 |
|
24 |
void sound_beep( unsigned int lenght, int16 frequency) |
26 |
void sound_beep( unsigned int lenght, int16 frequency) |
25 |
{ |
27 |
{ |
26 |
unsigned int i; |
28 |
unsigned int i; |
27 |
|
29 |
|
28 |
for(i=0;i<=lenght;i++) |
30 |
for(i=0;i<=lenght;i++) |
29 |
{ |
31 |
{ |
30 |
output_toggle(BEEP); |
32 |
output_toggle(BEEP); |
31 |
delay_us(1/frequency); |
33 |
delay_us(1/frequency); |
32 |
} |
34 |
} |
33 |
} |
35 |
} |
34 |
|
36 |
|
35 |
void main() |
37 |
void main() |
36 |
{ |
38 |
{ |
37 |
unsigned int16 setpoint=43; |
39 |
unsigned int16 setpoint=43; |
38 |
unsigned int16 napeti; |
40 |
unsigned int16 napeti; |
39 |
unsigned int16 plneni=0; |
41 |
unsigned int16 plneni=0; |
40 |
unsigned int1 button_press; // semafor pro cteni tlacitek |
42 |
unsigned int1 button_press; // semafor pro cteni tlacitek |
41 |
|
43 |
|
42 |
setup_adc_ports(sAN0|VSS_VDD); |
44 |
setup_adc_ports(sAN0|VSS_VDD); |
43 |
setup_adc(ADC_CLOCK_DIV_32); |
45 |
setup_adc(ADC_CLOCK_DIV_32); |
44 |
setup_spi(SPI_SS_DISABLED); |
46 |
setup_spi(SPI_SS_DISABLED); |
45 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
47 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
46 |
setup_timer_1(T1_DISABLED); |
48 |
setup_timer_1(T1_DISABLED); |
47 |
setup_timer_2(T2_DIV_BY_1,255,1); |
49 |
setup_timer_2(T2_DIV_BY_1,255,1); |
48 |
setup_ccp1(CCP_PWM); |
50 |
setup_ccp1(CCP_PWM); |
49 |
setup_ccp2(CCP_PWM); |
51 |
setup_ccp2(CCP_PWM); |
50 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
52 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
51 |
setup_oscillator(OSC_8MHZ); |
53 |
setup_oscillator(OSC_8MHZ); |
52 |
|
54 |
|
53 |
set_pwm1_duty(0); |
55 |
set_pwm1_duty(0); |
54 |
set_pwm2_duty(0); |
56 |
set_pwm2_duty(0); |
55 |
|
57 |
|
56 |
output_high(LED1); |
58 |
output_high(LED1); |
57 |
output_high(LED2); |
59 |
output_high(LED2); |
58 |
output_high(LED3); |
60 |
output_high(LED3); |
59 |
output_high(LED4); |
61 |
output_high(LED4); |
60 |
output_low(BEEP); |
62 |
output_low(BEEP); |
61 |
|
63 |
|
62 |
lcd_init(); |
64 |
lcd_init(); |
63 |
|
65 |
|
64 |
lcd_gotoxy(1,1); |
66 |
lcd_gotoxy(1,1); |
65 |
lcd_putc("HVPS01A"); |
67 |
lcd_putc("HVPS01A"); |
66 |
lcd_gotoxy(1,2); |
68 |
lcd_gotoxy(1,2); |
67 |
lcd_putc(" MLAB.cz"); |
69 |
lcd_putc(" MLAB.cz"); |
68 |
Delay_ms(1000); |
70 |
Delay_ms(1000); |
69 |
|
71 |
|
70 |
lcd_putc("\f"); |
72 |
lcd_putc("\f"); |
71 |
|
73 |
|
72 |
while(true) |
74 |
while(true) |
73 |
{ |
75 |
{ |
74 |
|
76 |
|
75 |
set_adc_channel(1); |
77 |
set_adc_channel(1); |
76 |
delay_us(100); |
78 |
delay_us(100); |
77 |
napeti = (napeti+read_adc())/2; |
79 |
napeti = (napeti+read_adc())/2; |
78 |
|
- |
|
79 |
if (napeti <= setpoint) |
80 |
if(input(OUTPUT_ENABLE)) |
80 |
{ |
81 |
{ |
- |
|
82 |
if (napeti <= setpoint) |
- |
|
83 |
{ |
81 |
if (plneni < 300) plneni++; |
84 |
if (plneni < 300) plneni++; |
82 |
output_low(LED2); |
85 |
output_low(LED2); |
- |
|
86 |
} |
- |
|
87 |
else |
- |
|
88 |
{ |
- |
|
89 |
if (plneni > 0) plneni--; |
- |
|
90 |
output_high(LED2); |
- |
|
91 |
} |
- |
|
92 |
set_pwm1_duty(plneni); |
- |
|
93 |
set_pwm2_duty(1023-plneni); |
83 |
} |
94 |
} |
84 |
else |
95 |
else |
85 |
{ |
96 |
{ |
86 |
if (plneni > 0) plneni--; |
97 |
set_pwm1_duty(0); |
87 |
output_high(LED2); |
98 |
set_pwm2_duty(1023); |
88 |
} |
99 |
} |
89 |
set_pwm1_duty(plneni); |
- |
|
90 |
set_pwm2_duty(1023-plneni); |
- |
|
91 |
|
100 |
|
92 |
lcd_gotoxy(1,1); |
101 |
lcd_gotoxy(1,1); |
93 |
printf(lcd_putc,"%lu",napeti); |
102 |
printf(lcd_putc,"%4lu",napeti); |
94 |
lcd_gotoxy(1,2); |
103 |
lcd_gotoxy(1,2); |
- |
|
104 |
|
95 |
printf(lcd_putc,"Set:%lu"setpoint); |
105 |
if(input(OUTPUT_ENABLE))printf(lcd_putc,"Set:%lu "setpoint); |
- |
|
106 |
else printf(lcd_putc,"DISABLED"); |
96 |
|
107 |
|
97 |
if(button_press==false ) // tlacitka se ctou znovu pouze pokud v redchozim cyklu nebyla zmacknuta. |
108 |
if(button_press==false ) // tlacitka se ctou znovu pouze pokud v redchozim cyklu nebyla zmacknuta. |
98 |
{ |
109 |
{ |
99 |
if(!input(S1)) |
110 |
if(!input(S1)) |
100 |
{ |
111 |
{ |
101 |
delay_ms(20); |
112 |
delay_ms(20); |
102 |
if(!input(S1)) |
113 |
if(!input(S1)) |
103 |
{ |
114 |
{ |
104 |
button_press=true; |
115 |
button_press=true; |
105 |
sound_beep(100,700); |
116 |
sound_beep(100,700); |
106 |
if(setpoint < (1023-5) )setpoint+=5; |
117 |
if(setpoint < (1023-5) )setpoint+=5; |
107 |
} |
118 |
} |
108 |
} |
119 |
} |
109 |
|
120 |
|
110 |
if(!input(S2)) |
121 |
if(!input(S2)) |
111 |
{ |
122 |
{ |
112 |
delay_ms(20); |
123 |
delay_ms(20); |
113 |
if(!input(S2)) |
124 |
if(!input(S2)) |
114 |
{ |
125 |
{ |
115 |
button_press=true; |
126 |
button_press=true; |
116 |
sound_beep(100,600); |
127 |
sound_beep(100,600); |
117 |
if(setpoint > 0x05 ) setpoint-=5; |
128 |
if(setpoint > 0x05 ) setpoint-=5; |
118 |
} |
129 |
} |
119 |
} |
130 |
} |
120 |
|
131 |
|
121 |
if(!input(S3)) |
132 |
if(!input(S3)) |
122 |
{ |
133 |
{ |
123 |
delay_ms(20); |
134 |
delay_ms(20); |
124 |
if(!input(S3)) |
135 |
if(!input(S3)) |
125 |
{ |
136 |
{ |
126 |
button_press=true; |
137 |
button_press=true; |
127 |
sound_beep(100,500); |
138 |
sound_beep(100,500); |
128 |
if(setpoint < 1023 )setpoint++; |
139 |
if(setpoint < 1023 )setpoint++; |
129 |
} |
140 |
} |
130 |
} |
141 |
} |
131 |
|
142 |
|
132 |
if(!input(S4)) |
143 |
if(!input(S4)) |
133 |
{ |
144 |
{ |
134 |
delay_ms(20); |
145 |
delay_ms(20); |
135 |
if(!input(S4)) |
146 |
if(!input(S4)) |
136 |
{ |
147 |
{ |
137 |
button_press=true; |
148 |
button_press=true; |
138 |
sound_beep(100,400); |
149 |
sound_beep(100,400); |
139 |
if(setpoint > 0x00 ) setpoint--; |
150 |
if(setpoint > 0x00 ) setpoint--; |
140 |
} |
151 |
} |
141 |
} |
152 |
} |
142 |
} |
153 |
} |
143 |
|
154 |
|
144 |
if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false; |
155 |
if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false; |
145 |
|
156 |
|
146 |
output_toggle(LED1); |
157 |
output_toggle(LED1); |
147 |
delay_ms(10); |
158 |
delay_ms(10); |
148 |
} |
159 |
} |
149 |
|
160 |
|
150 |
} |
161 |
} |