|
- #include <iom128v.h>
- void main(void)
- {
- // Port B initialization, PB.5-PB.7輸出PWM
- // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
- PORTB=0xFF;
- DDRB=0xFF;
- // Timer/Counter 1 initialization
- // Clock source: System Clock
- // Clock value: Timer 1 Stopped
- // Mode: 相位修正PWM, top=ICR1, PWM頻率50Hz,外部晶振16M
- // OC1A output: Non-Inv.
- // OC1B output: Non-Inv.
- // OC1C output: Non-Inv.
- // Noise Canceler: Off
- // Input Capture on Falling Edge
- // Timer 1 Overflow Interrupt: OFF
- // Input Capture Interrupt: Off
- // Compare A Match Interrupt: OFF
- // Compare B Match Interrupt: OFF
- // Compare C Match Interrupt: OFF
- TCCR1A=0xAA; //普通PWM
- TCCR1B=0x10;
- //TOP1=FOSC/FPWM/2/64; //64分頻
- //ICR1H=TOP1>>8; ICR1L=TOP1&0xFF;
- ICR1H=0x09; ICR1L=0xf6; //TOP,64分頻 49Hz PWM, TOP=2550
- OCR1AH=0x09;OCR1AL=0xC4; //100%
- OCR1BH=0x04;OCR1BL=0xE2; //50%
- OCR1CH=0x00;OCR1CL=0xFA; //10%
- TCCR1B|=0x03; //啟動(dòng)T1,64分頻
- while(1);
- }
復(fù)制代碼
|
|