在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)控制的步進(jìn)電機(jī)PWM控制程序

            單片機(jī)控制的步進(jìn)電機(jī)PWM控制程序

            作者: 時(shí)間:2016-11-18 來源:網(wǎng)絡(luò) 收藏
            8051單片機(jī)控制步進(jìn)電機(jī)的C51語言編寫的PWM控制程序

            #include
            #include
            #include
            #include "UPSD3200.H"
            #include "upsd_pwm.h"
            #define uint unsigned int
            #define uchar unsigned char
            PSD_REGS PSD8xx_reg _at_ csiop;
            #define KEYIO (~(PSD8xx_reg.DATAIN_A)) & 0x07
            sbit CP=P4^7;
            sbit U_D=P1^1;
            void init_system(); // 系統(tǒng)初始化
            uchar keyboard();
            void uPSD_PWM4_Variable(unsigned char PWM_Period, unsigned char PWM_PulseWidth);
            uchar Adjust_station=NO;
            unsigned char data x,flag;
            unsigned char keyboard() //鍵盤輸入
            {
            unsigned char a=0xff,b=0x01,c=0xf8,d;//有按鍵的位置
            uint i;
            do{
            a=KEYIO|c;
            }while(a==0xff);
            if (a == 0xfe){d = 1;}
            else if (a == 0xfd){d = 2;}
            else if (a == 0xfb){d = 3;}
            else {d = 0;}
            return(d);
            }
            void uPSD_PWM4_Init(void)
            unsigned int PWM_prescaler;
            P4SFS |= 0x80;
            PWM_prescaler = (unsigned int)((FREQ_OSC/2)/PWM4_INPUT_freq);//PWM4輸入脈沖頻率 K

            本文引用地址:http://www.biyoush.com/article/201611/315990.htm

            PSCL1L = PWM_prescaler & 0x00ff;
            PSCL1H = (PWM_prescaler >> 8);
            }
            void StepMotor_GO(bit direction,uint speed) {
            unsigned char PWM_Period, PWM_PulseWidth;
            uint temp_uint;
            U_D = direction;//方向
            temp_uint = (PWM4_INPUT_freq*1000)/speed;
            PWM_Period = (unsigned char)temp_uint;
            PWM_PulseWidth = PWM_Period/2;
            uPSD_PWM4_Variable(PWM_Period,PWM_PulseWidth);
            }
            void StepMotor_STOP(void)
            {
            P4SFS &= 0x7f;
            }
            void uPSD_PWM4_Variable(unsigned char PWM_Period, unsigned char PWM_PulseWidth)
            {
            P4SFS |= 0x80;
            PWMVP = PWM_Period;
            PWMVPW = PWM_PulseWidth;
            PWMCON |= 0x20;
            }
            void initkey(void){
            PSD8xx_reg.DATAOUT_A=0xFF;
            PSD8xx_reg.CONTROL_A=0x00;
            PSD8xx_reg.DIRECTION_A=0x00;
            }
            void init_system() // 系統(tǒng)初始化
            {
            WDKEY=0x55;
            P4SFS = (unsigned char) (0x08 << 3);
            uPSD_PWM_Channel_8bit(3,243);
            問題補(bǔ)充:(接著上面的序)
            void uPSD_PWM_Init_8bit(unsigned char PWM_channel_no, unsigned int PWM_freq8, unsigned char PWMCON_value)
            {
            unsigned int PWM_prescaler;
            unsigned char output_polarity_mode;
            output_polarity_mode = PWMCON_value & 0x8F;
            PWMCON = (PWMCON & 0x70) | output_polarity_mode;
            P4SFS = (unsigned char) (0x08 << PWM_channel_no);
            PWM_prescaler = (unsigned int) ( (((unsigned int) FREQ_OSC) / 2) / PWM_freq8);
            PSCL0L = PWM_prescaler & 0x00ff;
            PSCL0H = (PWM_prescaler >> 8);
            PSCL1L = PWM_prescaler & 0x00ff;
            PSCL1H = (PWM_prescaler >> 8);
            }
            void uPSD_PWM_Disable(void)
            {
            PWMCON &= 0xDF;
            }
            void main(void){
            x=0;
            init_system();
            flag=1;
            while(flag==1){
            x=keyboard();
            if(x==1) {StepMotor_GO(0,100);}
            else if(x==2) {StepMotor_GO(1,500);}
            else if(x==3) { StepMotor_STOP();uPSD_PWM_Disable();}
            else if(x==0) {uPSD_PWM_Disable();}
            }
            }



            評(píng)論


            技術(shù)專區(qū)

            關(guān)閉