Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <avr/io.h>
  2. #include <util/delay.h>
  3. void pwm_init()
  4. {
  5.     // initialize TCCR0 as per requirement, say as follows
  6.     TCCR0 |= (1<<WGM00)|(1<<COM01)|(1<<WGM01)|(1<<CS00);
  7.  
  8.     // make sure to make OC0 pin (pin PB3 for atmega32) as output pin
  9.     DDRB |= (1<<PB3);
  10. }
  11.  
  12. void main()
  13. {
  14.     uint8_t duty;
  15.     duty = 115;       // duty cycle = 45% of 255 = 114.75 = 115
  16.  
  17.     // initialize timer in PWM mode
  18.     pwm_init();
  19.  
  20.     // run forever
  21.     while(1)
  22.     {
  23.         OCR0 = duty;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement