Line 50... |
Line 50... |
50 |
|
50 |
|
51 |
void main() |
51 |
void main() |
52 |
{ |
52 |
{ |
53 |
unsigned int16 setpoint=43; |
53 |
unsigned int16 setpoint=43; |
54 |
unsigned int16 napeti; |
54 |
unsigned int16 napeti; |
55 |
unsigned int16 plneni=0; |
- |
|
56 |
unsigned int1 button_press; // semafor pro cteni tlacitek |
55 |
unsigned int1 button_press; // semafor pro cteni tlacitek |
57 |
unsigned int16 reg; |
- |
|
58 |
float given; |
- |
|
59 |
|
56 |
|
60 |
setup_adc_ports(sAN0|VSS_VDD); |
57 |
setup_adc_ports(sAN0|VSS_VDD); |
61 |
setup_adc(ADC_CLOCK_DIV_2); |
58 |
setup_adc(ADC_CLOCK_DIV_2); |
62 |
setup_spi(SPI_SS_DISABLED); |
59 |
setup_spi(SPI_SS_DISABLED); |
63 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
60 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
64 |
setup_timer_1(T1_DISABLED); |
61 |
setup_timer_1(T1_DISABLED); |
65 |
setup_timer_2(T2_DIV_BY_1,DIVISOR,1); |
62 |
setup_timer_2(T2_DIV_BY_1,DIVISOR,1); |
- |
|
63 |
setup_ccp1(CCP_PWM); |
- |
|
64 |
setup_ccp2(CCP_PWM); |
66 |
set_pwm1_duty(HALFDUTY); |
65 |
set_pwm1_duty(HALFDUTY); |
67 |
set_pwm2_duty(MAXDUTY); |
66 |
set_pwm2_duty(MAXDUTY); |
68 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
67 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
69 |
setup_oscillator(OSC_8MHZ); |
68 |
setup_oscillator(OSC_8MHZ); |
70 |
|
69 |
|
71 |
set_pwm1_duty(0); |
70 |
// set_pwm1_duty(0); |
72 |
set_pwm2_duty(0); |
71 |
// set_pwm2_duty(0); |
73 |
|
72 |
|
74 |
output_high(LED1); |
73 |
output_high(LED1); |
75 |
output_high(LED2); |
74 |
output_high(LED2); |
76 |
output_high(LED3); |
75 |
output_high(LED3); |
77 |
output_high(LED4); |
76 |
output_high(LED4); |
Line 86... |
Line 85... |
86 |
lcd_putc(" MLAB.cz"); |
85 |
lcd_putc(" MLAB.cz"); |
87 |
Delay_ms(1000); |
86 |
Delay_ms(1000); |
88 |
|
87 |
|
89 |
lcd_putc("\f"); |
88 |
lcd_putc("\f"); |
90 |
|
89 |
|
91 |
reg=400; |
- |
|
92 |
given=regreseM*reg+regreseN; |
- |
|
93 |
|
- |
|
94 |
|
90 |
|
95 |
while(true) |
91 |
while(true) |
96 |
{ |
92 |
{ |
97 |
|
- |
|
98 |
set_adc_channel(1); |
- |
|
99 |
delay_us(100); |
- |
|
100 |
napeti = (napeti+read_adc())/2; |
93 |
napeti = read_adc(); |
101 |
if(input(OUTPUT_ENABLE)) |
94 |
if(input(OUTPUT_ENABLE)) |
102 |
{ |
95 |
{ |
103 |
if (napeti <= setpoint) |
96 |
if (napeti <= setpoint) |
104 |
{ |
97 |
{ |
105 |
if (plneni < 300) plneni++; |
98 |
set_pwm2_duty((int16)255); // zapnuti menice |
106 |
output_low(LED2); |
99 |
output_low(LED2); |
107 |
} |
100 |
} |
108 |
else |
101 |
else // vypnuti menice |
109 |
{ |
102 |
{ |
110 |
if (plneni > 0) plneni--; |
103 |
set_pwm2_duty((int16)MAXDUTY); |
111 |
output_high(LED2); |
104 |
output_high(LED2); |
112 |
} |
105 |
} |
113 |
set_pwm1_duty(plneni); |
- |
|
114 |
set_pwm2_duty(1023-plneni); |
- |
|
- |
|
106 |
|
115 |
} |
107 |
} |
116 |
else |
108 |
else |
117 |
{ |
109 |
{ |
118 |
set_pwm1_duty(1023); |
110 |
set_pwm2_duty((int16)MAXDUTY); |
119 |
set_pwm2_duty(0); |
111 |
output_high(LED2); |
120 |
} |
112 |
} |
121 |
|
113 |
|
122 |
lcd_gotoxy(1,1); |
114 |
lcd_gotoxy(1,1); |
123 |
printf(lcd_putc,"%4lu",napeti); |
115 |
printf(lcd_putc,"%4lu",napeti); |
124 |
lcd_gotoxy(1,2); |
116 |
lcd_gotoxy(1,2); |
Line 172... |
Line 164... |
172 |
} |
164 |
} |
173 |
} |
165 |
} |
174 |
} |
166 |
} |
175 |
|
167 |
|
176 |
if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false; |
168 |
if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false; |
177 |
|
- |
|
178 |
output_toggle(LED1); |
169 |
output_toggle(LED1); |
179 |
delay_ms(10); |
- |
|
180 |
} |
170 |
} |
181 |
|
171 |
|
182 |
} |
172 |
} |