• <li id="00i08"><input id="00i08"></input></li>
  • <sup id="00i08"><tbody id="00i08"></tbody></sup>
    <abbr id="00i08"></abbr>
  • 新聞中心

    EEPW首頁 > 嵌入式系統 > 設計應用 > C8051F單片機PWM輸出程序

    C8051F單片機PWM輸出程序

    作者: 時間:2016-11-30 來源:網絡 收藏
    //PWM輸出腳P0.3
    //-----------------------------------------------------------------------------
    // Includes
    //-----------------------------------------------------------------------------
    #include // SFR declarations
    #include
    #include
    //-----------------------------------------------------------------------------
    // Function PROTOTYPES
    //-----------------------------------------------------------------------------
    void PORT_Init (void);
    void PCA_Init (void);
    void PCA_ISR (void);
    void SYSCLK_Init (void);
    //-----------------------------------------------------------------------------
    // MAIN Routine
    //-----------------------------------------------------------------------------
    void main (void)
    {
    unsignedadclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=84997066f841cb24&k=long&k0=long&kdi0=0&luki=2&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=24cb41f866709984&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2173%2Ehtml&urlid=0" id="1_nwl" mpid="1" target="_blank">longb;
    WDTCN = 0xde; // disable watchdog timer
    WDTCN = 0xad;
    SYSCLK_Init ();
    PORT_Init (); /*初始化I/O口*/
    PCA_Init (); /*PCA初始化成8位脈寬調置方式*/
    EIE1= 0x08;
    EA=1;
    PCA0CPH0=0x20;
    while (1)
    { }
    }
    //-----------------------------------------------------------------------------
    // Initialization Subroutines
    //-----------------------------------------------------------------------------
    //-----------------------------------------------------------------------------
    // PORT_Init
    //-----------------------------------------------------------------------------
    void PORT_Init (void)
    {
    XBR0 = 0x11; // XBAR0: Initial Reset Value
    XBR1 = 0x00; // XBAR1: Initial Reset Value
    XBR2 = 0x40; // XBAR2: Initial Reset Value
    // Port configuration (1 = Push Pull Output)
    PRT0CF = 0x08; // Output configuration for P0
    PRT1CF = 0x00; // Output configuration for P1
    PRT2CF = 0x00; // Output configuration for P2
    PRT3CF = 0x00; // Output configuration for P3
    }
    //-----------------------------------------------------------------------------
    // SYSCLK_Init
    //-----------------------------------------------------------------------------
    void SYSCLK_Init (void)
    {
    unsigned int i; // delaynms counter
    OSCXCN = 0x67; // start external oscillator with
    for (i=0; i < 256; i++) ; // XTLVLD blanking interval (>1ms)
    while (!(OSCXCN & 0x80)) ; // Wait for crystal osc. to settle
    OSCICN = 0x88; // select external oscillator as SYSCLK
    }
    //-----------------------------------------------------------------------------
    // PCA_Init
    //-----------------------------------------------------------------------------
    void PCA_Init (void)
    {
    // PCA0CPM0 = 0x42; // PCA Capture/Compare Register 0
    PCA0CN = 0x40;
    PCA0CPM1 = 0x42;
    PCA0CPL0 = 0x00;
    PCA0CPH0 = 0x00;
    // PCA0MD &= 0x40;
    PCA0MD = 0x01;
    }
    //-----------------------------------------------------------------------------
    // PCA_ISR
    //-----------------------------------------------------------------------------
    void PCA_ISR (void) interrupt 9
    { unsigned char a ;
    bitPWM_PAC;
    CF = 0;
    if(PWM_PAC==0) //占空比由0 >>0xfe
    {
    PCA0CPH1=a;
    a++;
    if(a==0xfe){PWM_PAC=1;}
    }
    else //占空比由0xfe >>0
    {
    PCA0CPH1=a;
    a--;
    if(a==0){PWM_PAC=0;}
    }
    }


    關鍵詞: C8051F單片機PW

    評論


    技術專區

    關閉
    主站蜘蛛池模板: 沙田区| 泰宁县| 宜都市| 同德县| 大英县| 青铜峡市| 浦北县| 察雅县| 哈密市| 建平县| 确山县| 庆元县| 尚志市| 定日县| 平顶山市| 元江| 淮南市| 黄骅市| 林口县| 会宁县| 政和县| 辉县市| 华坪县| 石首市| 莱阳市| 通化市| 武强县| 东乌| 永兴县| 当涂县| 廊坊市| 东乌| 英山县| 府谷县| 新巴尔虎左旗| 图片| 历史| 合水县| 红安县| 双桥区| 吴江市|