Mikroelektronika MIKROE-724 Scheda Tecnica

Pagina di 726
mikroBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
435
  pwm_period1 = PWM_Init(5000 , 1, 1, 2)
  pwm_period2 = PWM_Init(10000, 2, 1, 3)
  PWM_Start(1)
  PWM_Start(2)
  PWM_Set_Duty(current_duty,  1)             ‘ Set current duty for PWM1
  PWM_Set_Duty(current_duty1, 2)             ‘ Set current duty for PWM2
  while (TRUE)                               ‘ endless loop
    if RB0_bit = 1 then                      ‘ button on RB0 pressed
      Delay_ms(20)
      Inc(current_duty)                      ‘ increment current_duty
      if (current_duty > pwm_period1) then   ‘ if we increase current_duty greater then 
possible pwm_period1 value
        current_duty = 0                     ‘ reset current_duty value to zero
      end if
      PWM_Set_Duty(current_duty,  1)         ‘ set newly acquired duty ratio
    end if
    if RB1_bit = 1 then                      ‘ button on RB1 pressed
      Delay_ms(20)
      Dec(current_duty)                      ‘ decrement current_duty
      if (current_duty > pwm_period1) then   ‘ if we decrease current_duty greater then 
possible pwm_period1 value (overflow)
        current_duty = pwm_period1           ‘ set current_duty to max possible value
      end if
      PWM_Set_Duty(current_duty,  1)         ‘ set newly acquired duty ratio
    end if
    if RB2_bit = 1 then                      ‘ button on RB2 pressed
      Delay_ms(20)
      Inc(current_duty1)                     ‘ increment current_duty1
      if (current_duty1 > pwm_period2) then  ‘ if we increase current_duty1 greater then 
possible pwm_period2 value
        current_duty1 = 0                    ‘ reset current_duty1 value to zero
      end if
      PWM_Set_Duty(current_duty1,  2)        ‘ set newly acquired duty ratio
    end if
    if RB3_bit = 1 then                      ‘ button on RB3 pressed
      Delay_ms(20)
      Dec(current_duty1)                     ‘ decrement current_duty1
      if (current_duty1 > pwm_period2) then  ‘ if we decrease current_duty1 greater then 
possible pwm_period1 value (overflow)
        current_duty1 = pwm_period2          ‘ set current_duty to max possible value
      end if
      PWM_Set_Duty(current_duty1,  2)
    end if
  
Delay_ms(5)                           ‘ slow down change pace a little
  wend
end.