欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: stc12C5A60S2 PWM 問題 [打印本頁]

作者: 不將就123    時間: 2019-11-20 23:49
標題: stc12C5A60S2 PWM 問題
請問 stc12C5A60S2 單片機的兩路PWM波形 占空比是不是 不能獨立調節啊

作者: angmall    時間: 2019-11-21 09:13
STC12C5A60S2 單片機的兩路PWM波形 占空比是 可以獨立調節的

  1. /*------------------------------------------------------------------*/
  2. /* --- STC MCU Limited ---------------------------------------------*/
  3. /* --- STC12C5Axx Series MCU PCA module output PWM wave Demo -------*/
  4. /* If you want to use the program or the program referenced in the  */
  5. /* article, please specify in which data and procedures from STC    */
  6. /*------------------------------------------------------------------*/

  7. #include "reg51.h"
  8. #include "intrins.h"

  9. #define FOSC    11059200L

  10. typedef unsigned char BYTE;
  11. typedef unsigned int WORD;

  12. /*Declare SFR associated with the PCA */
  13. sfr CCON        =   0xD8;           //PCA control register
  14. sbit CCF0       =   CCON^0;         //PCA module-0 interrupt flag
  15. sbit CCF1       =   CCON^1;         //PCA module-1 interrupt flag
  16. sbit CR         =   CCON^6;         //PCA timer run control bit
  17. sbit CF         =   CCON^7;         //PCA timer overflow flag
  18. sfr CMOD        =   0xD9;           //PCA mode register
  19. sfr CL          =   0xE9;           //PCA base timer LOW
  20. sfr CH          =   0xF9;           //PCA base timer HIGH
  21. sfr CCAPM0      =   0xDA;           //PCA module-0 mode register
  22. sfr CCAP0L      =   0xEA;           //PCA module-0 capture register LOW
  23. sfr CCAP0H      =   0xFA;           //PCA module-0 capture register HIGH
  24. sfr CCAPM1      =   0xDB;           //PCA module-1 mode register
  25. sfr CCAP1L      =   0xEB;           //PCA module-1 capture register LOW
  26. sfr CCAP1H      =   0xFB;           //PCA module-1 capture register HIGH
  27. sfr PCAPWM0     =   0xf2;
  28. sfr PCAPWM1     =   0xf3;

  29. void main()
  30. {
  31.     CCON = 0;                       //Initial PCA control register
  32.                                     //PCA timer stop running
  33.                                     //Clear CF flag
  34.                                     //Clear all module interrupt flag
  35.     CL = 0;                         //Reset PCA base timer
  36.     CH = 0;
  37.     CMOD = 0x02;                    //Set PCA timer clock source as Fosc/2
  38.                                     //Disable PCA timer overflow interrupt
  39.     CCAP0H = CCAP0L = 0x80;         //PWM0 port output 50% duty cycle square wave
  40.     CCAPM0 = 0x42;                  //PCA module-0 work in 8-bit PWM mode and no PCA interrupt

  41.     CCAP1H = CCAP1L = 0xff;         //PWM1 port output 0% duty cycle square wave
  42.     PCAPWM1 = 0x03;
  43.     CCAPM1 = 0x42;                  //PCA module-1 work in 8-bit PWM mode and no PCA interrupt

  44.     CR = 1;                         //PCA timer start run

  45.     while (1);
  46. }

復制代碼


作者: dzbj    時間: 2019-11-21 10:34
當然可以啊 如"沙發"給的范例 改變CCAPxH和CCAPxL的值即可
作者: 不將就123    時間: 2019-12-1 11:02
謝謝 各位大師的解答 ,  我需要兩個獨立調節的量來做一個可調電源




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1