<var id="fnfpo"><source id="fnfpo"></source></var>
<rp id="fnfpo"></rp>

<em id="fnfpo"><object id="fnfpo"><input id="fnfpo"></input></object></em>
<em id="fnfpo"><acronym id="fnfpo"></acronym></em>
  • <th id="fnfpo"><track id="fnfpo"></track></th>
  • <progress id="fnfpo"><track id="fnfpo"></track></progress>
  • <tbody id="fnfpo"><pre id="fnfpo"></pre></tbody>

  • x
    x

    AT89C2051驅動步進電機的電路和源碼

    發布時間:2011-6-22 11:46    發布者:circuit_share
    關鍵詞: AT89C2051 , 步進電機


    程序

    stepper.c
    stepper.hex

    /*
    * STEPPER.C
    * sweeping stepper's rotor cw and cww 400 steps
    * Copyright (c) 1999 by W.Sirichote
    */

    #include c:\mc51\8051io.h /* include i/o header file */
    #include c:\mc51\8051reg.h

    register unsigned char j,flag1,temp;
    register unsigned int cw_n,ccw_n;

    unsigned char step[8]={0x80,0xc0,0x40,0x60,0x20,0x30,0x10,0x90}
    #define n 400

    /* flag1 mask byte
    0x01 run cw()
    0x02 run ccw()
    */

    main()

    {
    flag1=0;
    serinit(9600);
    disable(); /* no need timer interrupt */
    cw_n = n; /* initial step number for cw */
    flag1 |=0x01; /* initial enable cw() */

    while(1){
    {
    tick_wait(); /* wait for 10ms elapsed */

    energize(); /* round-robin execution the following tasks every 10ms */
    cw();
    ccw();
    }
    }

    }

    cw(){
    if((flag1&0x01)!=0)
    {
    cw_n--; /* decrement cw step number */
    if (cw_n !=0)
    j  ; /* if not zero increment index j */
    else
    {flag1&="0x01; /* disable cw() execution */
    ccw_n = n; /* reload step number to ccw counter */
    flag1 |=0x02; /* enable cww() execution */
    }
    }

    }

    ccw(){
    if((flag1&0x02)!=0)
    {
    ccw_n--; /* decremnent ccw step number */
    if (ccw_n !=0)
    j--; /* if not zero decrement index j */
    else
    {flag1&="0x02; /* disable ccw() execution */
    cw_n = n; /* reload step number to cw counter */
    flag1 |=0x01; /* enable cw() execution */
    }
    }

    }

    tick_wait(){ /* cputick was replaced by simpler ASM code 10ms wait */

    asm' JNB TCON.5,*'; /* wait for TF0 set */
    asm' CLR TCON.5'; /* clear TF0 for further set */
    asm' ORL TH0,#$DC'; /* reload TH0 with $DC, TL0 = 0 */
    }

    energize(){

    P1 = step[(j&0x07)]; /* only step 0-7 needed */
    }
    本文地址:http://www.portaltwn.com/thread-69274-1-1.html     【打印本頁】

    本站部分文章為轉載或網友發布,目的在于傳遞和分享信息,并不代表本網贊同其觀點和對其真實性負責;文章版權歸原作者及原出處所有,如涉及作品內容、版權和其它問題,我們將根據著作權人的要求,第一時間更正或刪除。
    lsx435372 發表于 2011-10-31 15:04:02
    怎么沒人評價啊
    hjhand 發表于 2013-3-9 11:13:24
    程序可讀性不強啊
    您需要登錄后才可以發表評論 登錄 | 立即注冊

    廠商推薦

    • Microchip視頻專區
    • 我們是Microchip
    • 想要避免發生災難,就用MPLAB SiC電源仿真器!
    • 利用模擬開發工具生態系統進行安全電路設計
    • 你仿真過嗎?使用免費的MPLAB Mindi模擬仿真器降低設計風險
    • 貿澤電子(Mouser)專區

    相關視頻

    關于我們  -  服務條款  -  使用指南  -  站點地圖  -  友情鏈接  -  聯系我們
    電子工程網 © 版權所有   京ICP備16069177號 | 京公網安備11010502021702
    快速回復 返回頂部 返回列表
    精品一区二区三区自拍图片区_国产成人亚洲精品_亚洲Va欧美va国产综合888_久久亚洲国产精品五月天婷