Hi all,
I got problem with “IF… ELSE” & ”IF… IF”
Chip 12F615, pins 3 & 7 as analog inputs, pin 5 output PWM.
Internal osc 8MHZ, using MIKROC version 6.0.0 to compile.
_______________[1] [8]
_______________ [2] [7] <--= (ref1) gpio.f0
(ref2) gpio.f4 =-->[3] [6]
_______________[4] [5] =--> (op2) gpio.f2
The following source codes could not work:
#define op2 gpio.f2
unsigned ref1,ref2;
void init(){
ansel=0b010001; // analog gpio.f0; f4
trisio=0b010001; // input gpio.f0; f4
pwm1_init(50000);
ref1=ref2=0;
}//end init()
void main() {
init();
while(1){
adc_init();
ref1=adc_read(0);
ref1/=4;
ref2=adc_read(4);
ref2/=4;
// if ref1 OR ref2 >=8 stop pwm, ELSE pwm start.
if(ref1||ref2>=8){pwm1_stop();}else{pwm1_set_duty(64);
}// end while(1)
}// end main()
The following is workable, by observing the blinking light:
void main() {
init();
while(1){
adc_init();
ref1=adc_read(0);
ref1/=4;
ref2=adc_read(4);
ref2/=4;
if(ref1||ref2>3){pwm1_stop();delay_ms(500);} // if ref1 OR ref2 >3 pwm stop, delay 0.5sec
if(ref1||ref2<1){pwm1_set_duty(128);pwm1_start();} // if ref1 OR ref2 <1 pwm start.
}// end while(1)
}// end main()
Where went wrong with the if…else command?
Thanks
oookey
I got problem with “IF… ELSE” & ”IF… IF”
Chip 12F615, pins 3 & 7 as analog inputs, pin 5 output PWM.
Internal osc 8MHZ, using MIKROC version 6.0.0 to compile.
_______________[1] [8]
_______________ [2] [7] <--= (ref1) gpio.f0
(ref2) gpio.f4 =-->[3] [6]
_______________[4] [5] =--> (op2) gpio.f2
The following source codes could not work:
#define op2 gpio.f2
unsigned ref1,ref2;
void init(){
ansel=0b010001; // analog gpio.f0; f4
trisio=0b010001; // input gpio.f0; f4
pwm1_init(50000);
ref1=ref2=0;
}//end init()
void main() {
init();
while(1){
adc_init();
ref1=adc_read(0);
ref1/=4;
ref2=adc_read(4);
ref2/=4;
// if ref1 OR ref2 >=8 stop pwm, ELSE pwm start.
if(ref1||ref2>=8){pwm1_stop();}else{pwm1_set_duty(64);
}// end while(1)
}// end main()
The following is workable, by observing the blinking light:
void main() {
init();
while(1){
adc_init();
ref1=adc_read(0);
ref1/=4;
ref2=adc_read(4);
ref2/=4;
if(ref1||ref2>3){pwm1_stop();delay_ms(500);} // if ref1 OR ref2 >3 pwm stop, delay 0.5sec
if(ref1||ref2<1){pwm1_set_duty(128);pwm1_start();} // if ref1 OR ref2 <1 pwm start.
}// end while(1)
}// end main()
Where went wrong with the if…else command?
Thanks
oookey