Advertisement
Guest User

Untitled

a guest
Jan 14th, 2012
1,057
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. Na začiatku si musíme určiť rýchlosť uC : #define F_CPU 1000000 //1MHz
  2. Potom si zahrnieme štandardne i/o AVR uC : #include <avr/io.h>
  3. A vydeklarujem si nejaké premenné ,ktoré budeme používať :
  4. #define OutputCompareRegister1 OCR1A
  5. #define OutputCompareRegister2 OCR1B
  6.  
  7. #define PWMDDR DDRB
  8.  
  9. #define PWMpin1 PB1
  10. #define PWMpin2 PB2
  11.  
  12. Vytvoríme si funkciu na inicializáciu PWM :
  13. void init16bitPWM() //this function works for ATMega8 but needs to be configured for other AVR uCs (configure the registers and the bits)
  14. {
  15.     PWMDDR |= 1<<PWMpin1;
  16.     PWMDDR |= 1<<PWMpin2;
  17.    
  18.    
  19.     TCCR1A |= 1<<WGM11 | 1<<COM1A1 | 1<<COM1B1;
  20.     TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS10;
  21.    
  22.     ICR1 = 65535;
  23.    
  24.     OutputCompareRegister1 = 0;
  25.     OutputCompareRegister2 = 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement