Datasheet
Library Example
The example changes PWM duty ratio on pin PB3 continually. If LED is connected
to PB3, you can observe the gradual change of emitted light.
char current_duty;
char current_duty1;
void main(){
DDB0 = 0; // Set PORTB pin 0 as input
DDB1 = 0; // Set PORTB pin 1 as input
DDC0 = 0; // Set PORTC pin 0 as input
DDC1 = 0; // Set PORTC pin 1 as input
current_duty = 127; // initial value for current_duty
current_duty1 = 127; // initial value for current_duty
DDRB.B3 = 1; // Set PORTB pin 3 as output pin
for the PWM (according to datasheet)
DDRD.B7 = 1; // Set PORTD pin 7 as output pin
for the PWM (according to datasheet)
PWM_Init(_PWM_FAST_MODE, _PWM_PRESCALER_8, _PWM_NON_INVERTED,
127);
PWM1_Init(_PWM1_FAST_MODE, _PWM1_PRESCALER_8, _PWM1_NON_INVERTED,
127);
do {
if (PINB.B0) { // Detect if PORTB pin 0 is pressed
Delay_ms(40); // Small delay to avoid deboucing effect
current_duty++; // Increment duty ratio
PWM_Set_Duty(current_duty); // Set incremented duty
}
else
if (PINB.B1) { // Detect if PORTB pin 1 is pressed
Delay_ms(40); // Small delay to avoid deboucing effect
current_duty--; // Decrement duty ratio
PWM_Set_Duty(current_duty); // Set decremented duty ratio
}
else
if (PINC.B0) { // Detect if PORTC pin 0 is pressed
Delay_ms(40); // Small delay to avoid deboucing effect
current_duty1++; // Increment duty ratio
PWM1_Set_Duty(current_duty1); // Set incremented duty
}
380
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroC PRO for AVR
CHAPTER 6