52,10 → 52,7 |
{ |
unsigned int16 setpoint=43; |
unsigned int16 napeti; |
unsigned int16 plneni=0; |
unsigned int1 button_press; // semafor pro cteni tlacitek |
unsigned int16 reg; |
float given; |
|
setup_adc_ports(sAN0|VSS_VDD); |
setup_adc(ADC_CLOCK_DIV_2); |
63,13 → 60,15 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
setup_timer_1(T1_DISABLED); |
setup_timer_2(T2_DIV_BY_1,DIVISOR,1); |
setup_ccp1(CCP_PWM); |
setup_ccp2(CCP_PWM); |
set_pwm1_duty(HALFDUTY); |
set_pwm2_duty(MAXDUTY); |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
setup_oscillator(OSC_8MHZ); |
|
set_pwm1_duty(0); |
set_pwm2_duty(0); |
// set_pwm1_duty(0); |
// set_pwm2_duty(0); |
|
output_high(LED1); |
output_high(LED2); |
88,35 → 87,28 |
|
lcd_putc("\f"); |
|
reg=400; |
given=regreseM*reg+regreseN; |
|
|
while(true) |
{ |
|
set_adc_channel(1); |
delay_us(100); |
napeti = (napeti+read_adc())/2; |
napeti = read_adc(); |
if(input(OUTPUT_ENABLE)) |
{ |
if (napeti <= setpoint) |
{ |
if (plneni < 300) plneni++; |
set_pwm2_duty((int16)255); // zapnuti menice |
output_low(LED2); |
} |
else |
else // vypnuti menice |
{ |
if (plneni > 0) plneni--; |
output_high(LED2); |
set_pwm2_duty((int16)MAXDUTY); |
output_high(LED2); |
} |
set_pwm1_duty(plneni); |
set_pwm2_duty(1023-plneni); |
|
} |
else |
{ |
set_pwm1_duty(1023); |
set_pwm2_duty(0); |
set_pwm2_duty((int16)MAXDUTY); |
output_high(LED2); |
} |
|
lcd_gotoxy(1,1); |
174,9 → 166,7 |
} |
|
if ( input(S1) && input(S2) && input(S3) && input(S4) ) button_press=false; |
|
output_toggle(LED1); |
delay_ms(10); |
} |
|
} |