Mikroelektronika MIKROE-350 数据表

下载
页码 526
program PWM_Test
dim current_duty as byte
current_duty1 
as byte
main:
DDC0_bit = 0                    ' Set PORTC pin 0 as input
DDC1_bit = 0                    ' Set PORTC pin 1 as input
DDC2_bit = 0                    ' Set PORTC pin 2 as input
DDC3_bit = 0                    ' Set PORTC pin 3 as input
current_duty  = 127             ' initial value for current_duty
current_duty1 = 127             ' initial value for current_duty
DDB1_bit = 1                    ' Set PORTB pin 1 as output pin
for the PWM (according to datasheet)
DDB2_bit = 1                    ' Set PORTB pin 2 as output pin
for the PWM (according to datasheet)
PWM16bit_Init(_PWM16_FAST_MODE_9BIT, _PWM16_PRESCALER_16bit_1,
_PWM16_INVERTED, 255, 1)
while TRUE                          ' Endless loop
if (PINC.B0 <> 0) then
' Detect if PORTC pin 0 is pressed
Delay_ms(40)        ' Small delay to avoid deboucing effect
Inc(current_duty)               ' Increment duty ratio
PWM_Set_Duty(current_duty)      ' Set incremented duty
end if
if (PINC.B1 <> 0) then
' Detect if PORTC pin 1 is pressed
Delay_ms(40)        ' Small delay to avoid deboucing effect
Dec(current_duty)               ' Decrement duty ratio
PWM_Set_Duty(current_duty)      ' Set decremented duty ratio
end if
if (PINC.B2 <> 0) then
' Detect if PORTC pin 2 is pressed
Delay_ms(40)        ' Small delay to avoid deboucing effect
Inc(current_duty1)              ' Increment duty ratio
PWM1_Set_Duty(current_duty1)    ' Set incremented duty
end if
if (PINC.B3 <> 0) then
' Detect if PORTC pin 3 is pressed
Delay_ms(40)         ' Small delay to avoid deboucing effect
Dec(current_duty1)              ' Decrement duty ratio
PWM1_Set_Duty(current_duty1)    ' Set decremented duty ratio
end if
wend
323
MIKROELEKTRONIKA
- SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroBasic PRO for AVR
CHAPTER 6