yadelim
Üye
- Katılım
- 7 Şub 2013
- Mesajlar
- 48
- Puanları
- 1
aşağıdaki tam olarak da sizin yukarıdaki tarifinize göre çalışmaktadır.
( sensor / buton ları b7,b6,b5,b4 e bağlamanız gerekecek)
not: ISIS de denenmiştir. (buton arklarına karşı önlem almanız tavsiye edilir)
#include <16F628A.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOBROWNOUT
#FUSES NOLVP
#use delay(int=4000000)
#use fast_io(a)
#use fast_io(b)
#define yuzde_25_artis 50
#define max_pwm_degeri 197
#define min_pwm_degeri 10000
int16 pwm_duty_degeri;
int8 sensor_degeri;
int8 old_sensor_degeri;
#int_RB
void RB_isr(void) {
sensor_degeri=input_b();
sensor_degeri>>=4;
if(sensor_degeri==12){sensor_degeri=8;}
if(sensor_degeri==6){sensor_degeri=4;}
if(sensor_degeri==3){sensor_degeri=2;}
if(sensor_degeri > 0)
{
if((pwm_duty_degeri==0) && (sensor_degeri==1)){pwm_duty_degeri += yuzde_25_artis;}
else if(sensor_degeri > old_sensor_degeri){pwm_duty_degeri += yuzde_25_artis;}
else if(sensor_degeri < old_sensor_degeri){pwm_duty_degeri -= yuzde_25_artis;}
else if(sensor_degeri == old_sensor_degeri){pwm_duty_degeri -= yuzde_25_artis;}
if(pwm_duty_degeri > min_pwm_degeri){pwm_duty_degeri = 0;}
if(pwm_duty_degeri > max_pwm_degeri){pwm_duty_degeri = max_pwm_degeri;}
set_pwm1_duty((int16)pwm_duty_degeri);
old_sensor_degeri = sensor_degeri;
}
}
void main() {
setup_timer_2(T2_DIV_BY_1,49,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty((int16)0);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_4MHZ);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
set_tris_a (0b11111111);
set_tris_b (0b11110111);
sensor_degeri=0;
old_sensor_degeri=0;
pwm_duty_degeri=0;
while(TRUE){}
}
( sensor / buton ları b7,b6,b5,b4 e bağlamanız gerekecek)
not: ISIS de denenmiştir. (buton arklarına karşı önlem almanız tavsiye edilir)
#include <16F628A.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOBROWNOUT
#FUSES NOLVP
#use delay(int=4000000)
#use fast_io(a)
#use fast_io(b)
#define yuzde_25_artis 50
#define max_pwm_degeri 197
#define min_pwm_degeri 10000
int16 pwm_duty_degeri;
int8 sensor_degeri;
int8 old_sensor_degeri;
#int_RB
void RB_isr(void) {
sensor_degeri=input_b();
sensor_degeri>>=4;
if(sensor_degeri==12){sensor_degeri=8;}
if(sensor_degeri==6){sensor_degeri=4;}
if(sensor_degeri==3){sensor_degeri=2;}
if(sensor_degeri > 0)
{
if((pwm_duty_degeri==0) && (sensor_degeri==1)){pwm_duty_degeri += yuzde_25_artis;}
else if(sensor_degeri > old_sensor_degeri){pwm_duty_degeri += yuzde_25_artis;}
else if(sensor_degeri < old_sensor_degeri){pwm_duty_degeri -= yuzde_25_artis;}
else if(sensor_degeri == old_sensor_degeri){pwm_duty_degeri -= yuzde_25_artis;}
if(pwm_duty_degeri > min_pwm_degeri){pwm_duty_degeri = 0;}
if(pwm_duty_degeri > max_pwm_degeri){pwm_duty_degeri = max_pwm_degeri;}
set_pwm1_duty((int16)pwm_duty_degeri);
old_sensor_degeri = sensor_degeri;
}
}
void main() {
setup_timer_2(T2_DIV_BY_1,49,1);
setup_ccp1(CCP_PWM);
set_pwm1_duty((int16)0);
setup_comparator(NC_NC_NC_NC);
setup_oscillator(OSC_4MHZ);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
set_tris_a (0b11111111);
set_tris_b (0b11110111);
sensor_degeri=0;
old_sensor_degeri=0;
pwm_duty_degeri=0;
while(TRUE){}
}