Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Na začiatku si musíme určiť rýchlosť uC : #define F_CPU 1000000 //1MHz
- Potom si zahrnieme štandardne i/o AVR uC : #include <avr/io.h>
- A vydeklarujem si nejaké premenné ,ktoré budeme používať :
- #define OutputCompareRegister1 OCR1A
- #define OutputCompareRegister2 OCR1B
- #define PWMDDR DDRB
- #define PWMpin1 PB1
- #define PWMpin2 PB2
- Vytvoríme si funkciu na inicializáciu PWM :
- void init16bitPWM() //this function works for ATMega8 but needs to be configured for other AVR uCs (configure the registers and the bits)
- {
- PWMDDR |= 1<<PWMpin1;
- PWMDDR |= 1<<PWMpin2;
- TCCR1A |= 1<<WGM11 | 1<<COM1A1 | 1<<COM1B1;
- TCCR1B |= 1<<WGM12 | 1<<WGM13 | 1<<CS10;
- ICR1 = 65535;
- OutputCompareRegister1 = 0;
- OutputCompareRegister2 = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement