mikroc'de program yardım ir sensörlü motor hız kontrolü

Başlatan ahmetyesevi, 02 Aralık 2012, 00:44:20

ahmetyesevi

herkese selamlar
üzerinde çalıştığım proje şu http://e1212.hizliresim.com/14/2/gh68y.jpg
devre olarak tamam ama yazılım olarak sıkıntım var pic16f877 nin RA0 portuna bağlı infrared sensörün 1 olması durumuna göre RC2 çıkışından 10 saniyelik bir çıkış alarak motoru döndürmek, 0 olması durumunda motorun durmasını istiyorum motor dönerkende RB0 ve RB1 portlarına bağlı butonlarla hızını arttırıp azaltmak istiyorum. microc'de yazmaya çalıştığım kod şöyle birşey;


unsigned short current_duty, old_duty, current_duty1, old_duty1;

void InitMain() {
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
C1ON_bit = 0; // Disable comparators
C2ON_bit = 0;

PORTA = 255;
TRISA = 255; // configure PORTA pins as input
PORTB = 0; // set PORTB to 0
TRISB = 1; // designate PORTB pins as input
PORTC = 0; // set PORTC to 0
TRISC = 0; // designate PORTC pins as output
PWM1_Init(5000); // Initialize PWM1 module at 5KHz
PWM2_Init(5000); // Initialize PWM2 module at 5KHz
}

void main() {
InitMain();
current_duty = 16; // initial value for current_duty
current_duty1 = 16; // initial value for current_duty1

PWM1_Start(); // start PWM1
PWM2_Start(); // start PWM2
PWM1_Set_Duty(current_duty); // Set current duty for PWM1
PWM2_Set_Duty(current_duty1); // Set current duty for PWM2

if (RA0==1) {
while (1) { // endless loop
if (RB0_bit) { // button on RA0 pressed
Delay_ms(40);
current_duty++; // increment current_duty
PWM1_Set_Duty(current_duty);
}

if (RB1_bit) { // button on RA1 pressed
Delay_ms(40);
current_duty--; // decrement current_duty
PWM1_Set_Duty(current_duty);
}

Delay_ms(5); // slow down change pace a little
}
else if (RA0==0){
PORTC=0;
end
}
}

ama çalıştıramıyorum
şimdiden yardım edenlere çok teşekkür ediyorum