專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

單片機(jī)電機(jī)測速程序(有霍爾+磁鋼或紅外反射對管+黑白碼盤做該實(shí)驗(yàn))

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時間:2013年07月07日   【字體:

這個51單片機(jī)+電機(jī)霍爾測速程序是從一個制作成功的智能小車?yán)锩嫣崛〕鰜淼?br />

原理圖及其源代碼壓縮包的下載地址:http://www.torrancerestoration.com/bbs/dpj-19526-1.html

下面是主要的程序文件預(yù)覽:
#include<reg52.h>
unsigned int i=0;
sbit P36=P3^6;
unsigned char j;
unsigned int kop;
unsigned char a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char b[8]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
void delaym(unsigned int t)
{ unsigned char p;      
while(t--)
{
for(p=0; p<125; p++);  
}
}

void main()
{
    EA = 1;
    TH0=0x00;
 TL0=0x00;
 ET0=1;
 ET1=1;  
   TMOD = 0x15;// 打開定時器和計(jì)數(shù)器T0,因此矩形脈沖輸入端接P3.4
 TH1=0x3C; //50ms
 TL1=0xB0;  
    TR0 = 1;
 TR1 = 1;
while(1)
{
  for(j=0;j<3;j++) //顯示個數(shù)
  {
  P0=b[j];
  P2=j;
  delaym(2);
   }
  }
}
timer3() interrupt 3  //定時器中斷時間到,就讀取計(jì)數(shù)器值
{ TH1=0X3C;
 TL1=0XB0;
 i++;
if(i==20) //1s才進(jìn)行技術(shù)脈沖值顯示,即每秒更新一次速度
{
   kop=TH0;//計(jì)數(shù)器計(jì)入脈沖,每來一個矩形脈沖計(jì)數(shù)值加1
   kop=kop<<8;
   kop=kop+TL0;

b[2]=a[kop/100];       //顯示計(jì)數(shù)器的值即實(shí)際測得速度
b[1]=a[kop%100/10];
b[0]=a[kop%100%10];
i=0;
TH0=0;//計(jì)數(shù)器速度獲取后清零,進(jìn)行下次獲取
TL0=0;
}
}

關(guān)閉窗口

相關(guān)文章