<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        STC單片機PCA產生PWM程序

        作者:佚名   來源:本站原創   點擊數:  更新時間:2014年08月19日   【字體:

        stc12  15單片機的pca模塊產生pwm的完整例程,測試成功。完整代碼下載:http://www.thefapper.com/f/stcpcaPWM.zip

        #include <reg51.h>

        #include "PCA.h"
        void PWM(unsigned int num,int cex);
        void main()
        {
        CMOD=0x02;
        CL=0x00;
        CH=0x00;
        PWM(10,0);
        PWM(20,1);
        PWM(50,2);
        PWM(70,3);
        PWM(90,4);
        CR=1;
        while(1);
        }
         
        void PWM(unsigned int num,int cex)
        {
        double i=256*(100-num)/100;
        switch(cex)
        {
        case 0: CCAP0L=i; CCAP0H=i; CCAPM0=0x42; break;
        case 1: CCAP1L=i; CCAP1H=i; CCAPM1=0x42; break;
        case 2: CCAP2L=i; CCAP2H=i; CCAPM2=0x42; break;
        case 3: CCAP3L=i; CCAP3H=i; CCAPM3=0x42; break;
        case 4: CCAP4L=i; CCAP4H=i; CCAPM4=0x42; break;
        }
        }
         
         
        頭文件:
        #ifndef _SST_PCA_H_
        #define _SST_PCA_H_

        sfr CH =0xF9;
        sfr CL =0xE9;
        sfr CMOD =0xD9;
        sfr CCON =0xD8;

        sfr CCAPM0 =0xDA;
        sfr CCAPM1 =0xDB;
        sfr CCAPM2 =0xDC;
        sfr CCAPM3 =0xDD;
        sfr CCAPM4 =0xDE;

        sfr CCAP0H =0xFA;
        sfr CCAP1H =0xFB;
        sfr CCAP2H =0xFC;
        sfr CCAP3H =0xFD;
        sfr CCAP4H =0xFE;

        sfr CCAP0L =0xEA;
        sfr CCAP1L =0xEB;
        sfr CCAP2L =0xEC;
        sfr CCAP3L =0xED;
        sfr CCAP4L =0xEE;

        /*CCON*/
        sbit CF =CCON^7;
        sbit CR =CCON^6;
        sbit CCF4 =CCON^4;
        sbit CCF3 =CCON^3;
        sbit CCF2 =CCON^2;
        sbit CCF1 =CCON^1;
        sbit CCF0 =CCON^0;

        #endif
         
         
        關閉窗口
        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮