The way I would do it is to implement a soft PWM. I think it's been covered on this site already. Let a timer run in the background every mS. Give it a value for on time of the buzzer (0-1000mS) Every time the timer ticks, you can verify if the buzzer needs to be on or off. Now, all you have to do is give it a value from your mainline code.