找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3318|回復(fù): 0
收起左側(cè)

快速PWM模式

[復(fù)制鏈接]
ID:80436 發(fā)表于 2015-5-21 23:50 | 顯示全部樓層 |閱讀模式




  1. #include <iom128v.h>

  2. void main(void)

  3. {

  4. // Port B initialization, PB.5-PB.7輸出PWM

  5. // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out

  6. PORTB=0xFF;

  7. DDRB=0xFF;

  8. // Timer/Counter 1 initialization

  9. // Clock source: System Clock

  10. // Clock value: Timer 1 Stopped

  11. // Mode: 相位修正PWM, top=ICR1, PWM頻率50Hz,外部晶振16M

  12. // OC1A output: Non-Inv.

  13. // OC1B output: Non-Inv.

  14. // OC1C output: Non-Inv.

  15. // Noise Canceler: Off

  16. // Input Capture on Falling Edge

  17. // Timer 1 Overflow Interrupt: OFF

  18. // Input Capture Interrupt: Off

  19. // Compare A Match Interrupt: OFF

  20. // Compare B Match Interrupt: OFF

  21. // Compare C Match Interrupt: OFF

  22. TCCR1A=0xAA;    //普通PWM

  23. TCCR1B=0x10;

  24. //TOP1=FOSC/FPWM/2/64;       //64分頻

  25. //ICR1H=TOP1>>8; ICR1L=TOP1&0xFF;

  26. ICR1H=0x09; ICR1L=0xf6;     //TOP,64分頻 49Hz PWM, TOP=2550

  27. OCR1AH=0x09;OCR1AL=0xC4;    //100%

  28. OCR1BH=0x04;OCR1BL=0xE2;    //50%

  29. OCR1CH=0x00;OCR1CL=0xFA;   //10%

  30. TCCR1B|=0x03;   //啟動T1,64分頻

  31. while(1);

  32. }
復(fù)制代碼






回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表