Mikrobilgisayarlar dersi projesi CCS C acil yardım !!

Başlatan mikrobenibitirdi, 23 Mayıs 2016, 22:20:48

mikrobenibitirdi

İyi akşamlar arkadaşlar,
Perşembe günü teslim projemizde bugün itibariyle "delay" kullanmadan yapmamız gerektiğini öğrendik ve timer ile çeviremedik. Yardımcı olursanız çok seviniriz, şimdiden teşekkürler   ::)

#include <18F4550.h>
#fuses NOMCLR INTRC_IO
#use delay(clock = 8000000)
#use fast_io(B)
#use fast_io(C)

int1 toggle;
unsigned int8 count, i, j, address, command;
short remote_read(){
  count = 0;
    // Check if the received signal uses RC5 protocol
    while((input(PIN_B0) == 0) && (count < 20)){
      count++;
      delay_us(50);}
    if( (count > 20) || (count < 14))      // Signal doesn't use RC5 protocol
      return false;                            // Return
    count = 0;
    while((input(PIN_B0)) && (count < 20)){
      count++;
      delay_us(50);}
    if( (count > 20) || (count < 14))      // Signal doesn't use RC5 protocol
      return false ;                            // Return
    count = 0;
    while((input(PIN_B0) == 0) && (count < 40)){
      count++;
      delay_us(50);}
    if( (count > 40) || (count < 14))      // Signal doesn't use RC5 protocol
      return false ;                            // Return
    // End check (The received signal uses RC5 protocol)
    if(count > 30)
      delay_us(400);
    else
      delay_us(1300);
    output_high(PIN_B1);                        // Toggle RB1 LED
    for(i = 0; i < 12; i++){
      if(i == 0){
        if(input(PIN_B0) == 1)   toggle = 0;
        else                     toggle = 1;
        }
      else {
        if(i < 6){                                //Read address bits
          if(input(PIN_B0) == 1)
            bit_clear(address, (5 - i));          //Clear bit (5-i)
          else
            bit_set(address, (5 - i));           //Set bit (5-i)
          }
        else {                                 //Read command bits
          if(input(PIN_B0) == 1)
            bit_clear(command, (11 - i));        //Clear bit (11-i)
          else
            bit_set(command, (11 - i));          //Set bit (11-i)
          }
        }
      delay_us(1778);
      }
  address &= 0x1F;
  command &= 0x3F;
  return true;
}
void main(){
  setup_oscillator(OSC_8MHZ);            // Set internal oscillator to 8MHz
  setup_adc_ports(NO_ANALOGS);                  // Configure AN pins as digital
  port_b_pullups(TRUE);                  // Enable PORTB pull-ups
  output_b(0);                           // PORTB initial state
  set_tris_b(1);                         // Configure RB0 pin as input
  output_c(0);                           // PORTC initial state
  set_tris_c(0);                         // Configure PORTC pins as outputs
  setup_timer_2(T2_DIV_BY_16, 250, 1);   // Set PWM frequency to 500Hz
  delay_ms(100);                         // Wait 100ms
  while(TRUE){
    output_low(PIN_B1);
    while(input(PIN_B0));                // Wait until RB0 pin falls
    if(remote_read()){
      if((address == 0) && (command == 16) && (input(PIN_B3) == 0)){  // Direction 1
          output_b(0);                     // Both LEDs OFF
          setup_ccp1(CCP_OFF);             // CCP1 OFF
          setup_ccp2(CCP_OFF);             // CCP2 OFF
          output_c(0);                     // PORTC pins low
          delay_ms(100);                   // Wait 100ms
          setup_ccp1(CCP_PWM);             // Configure CCP1 as PWM
          set_pwm1_duty(j);                    // Set pwm1 duty cycle
          output_high(PIN_B3);             // RB3 LED ON
          if(j > 250)
            output_high(PIN_B2);          // RB2 LED ON (speed is max)
         }
      if((address == 0) && (command == 17) && (input(PIN_B4) == 0)){  // Direction 2
          output_b(0);                     // Both LEDs OFF
          setup_ccp1(CCP_OFF);             // CCP1 OFF
          setup_ccp2(CCP_OFF);             // CCP2 OFF
          output_c(0);                     // PORTC pins low
          delay_ms(100);                   // Wait 100ms
          setup_ccp2(CCP_PWM);             // Configure CCP2 as PWM
          set_pwm2_duty(j);                    // Set pwm1 duty cycle
          output_high(PIN_B4);             // RB4 LED ON
          if(j > 250)
            output_high(PIN_B2);          // RB2 LED ON (speed is max)
         }
      if((address == 0) && (command == 32) && (j < 251)){     // Speed up
        j++;
        if(j > 250)
          output_high(PIN_B2);          // RB2 LED ON
        if(input(PIN_B3))
          set_pwm1_duty(j);                    // Set pwm1 duty cycle
        if(input(PIN_B4))
          set_pwm2_duty(j);                    // Set pwm2 duty cycle
        }
      if((address == 0) && (command == 33) && (j > 0)){     // Speed down
        j--;
        output_low(PIN_B2);          // RB2 LED OFF
        if(input(PIN_B3))
          set_pwm1_duty(j);                    // Set pwm1 duty cycle
        if(input(PIN_B4))
          set_pwm2_duty(j);                    // Set pwm2 duty cycle
        }
      if((address == 0) && (command == 59)){     // Motor stop
        setup_ccp1(CCP_OFF);               // CCP1 OFF
        setup_ccp2(CCP_OFF);               // CCP2 OFF
        output_b(0);                       // Both LEDs OFF
        output_c(0);                       // PORTC pins low
        }
    }
    delay_ms(10);
  }
}

sifirzero

https://youtu.be/4H7472R9_HY    arkadasim bu adamin videolarini izlermisin.bu ornek senin isine yarayabilir
sifirzero.blogspot.com [email]sifirrzero@gmail.com[/email] iman hem nurdur hem kuvvettir

sifirzero

sifirzero.blogspot.com [email]sifirrzero@gmail.com[/email] iman hem nurdur hem kuvvettir

mehmet

For ya da while içerisinde bir değişkeni
Nop() dan sonra eksilterek gecikme
yapabilirsiniz. 
Olan olmuştur,
olacak olan da olmuştur.
Olacak bir şey yoktur.
---------------------------------------------
http://www.mehmetbilgi.net.tr