欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 發一個單片機紅外測速、調速程序 [打印本頁]

作者: dpj555    時間: 2015-4-23 13:42
標題: 發一個單片機紅外測速、調速程序
采用80c51單片機進行測速調速。
nclude <reg51.h>
#include <intrins.h>
unsigned char code lcd[]={"speed0k"};  
unsigned char code table[]= {"0123456789"};
unsigned char code pin[]={"Hz"};
unsigned char zhuan[5];
unsigned char shi=20;
unsigned int  y,jia;
sbit rd=P2^7;
sbit rw=P2^6;
sbit e=P2^5;
sbit kong=P3^0;
void delay1(unsigned char ms)  //延時函數
{
        unsigned char j;
        while(ms--)
        {
                for(j=0;j<125;j++);
        }
}
void delay()//延時函數
{        
        _nop_();
        _nop_();
        _nop_();
}
bit du()//LCD讀忙狀態
{
        bit s;
        rw=1;
        rd=0;
        delay();
        e=1;
        delay();
        s=(bit)(P0&0x80);
        e=0;
        return  s;
}
void xie(unsigned char com)//LCD寫命令
{
        while (du());
        rd=0;
        rw=0;
        delay();
        e=0;
        P0=com;
        e=1;
        delay();
//        delay1(20);
}
void xieshuju(unsigned char dat)//LCD寫數據
{
        while (du());
        rw=0;
        rd=1;
        delay();
        e=0;
        P0=dat;
        e=1;
        delay();
        e=0;
}
void chushihua()//LCD初始化
{
        xie(0x38);
        xie(0x0c);
        xie(0x01);
        xie(0x06);
}

void delayms (unsigned char time)//延時函數
{
        unsigned char  i,j;
        for(i=0;i<time;i++)        ;
        e=0;
        for(j=100;j>1;j--) ;
}
void tiaosu(unsigned int shi1)//電機調速
{
        kong=0;
        delayms(5);
        kong=1;
        delayms(shi1);
}
unsigned char keycan()//按鍵返回值函數
{               
        
                static         unsigned char key;
                if(P3!=0xff)
                {
                delay1(10);
                if(P3!=0xff)
                key=P3&0Xff;
                if(P3==0xfd)
                jia=jia+5;
                if(P3==0xfb)
                jia=jia-5;
                if(jia<=5)
                jia=3;
                }
        while(P3!=0xff);
    return(key);
}
void zhuanhuan()  //電機轉速數據處理   
{
        zhuan[0]=table[y/1000%10];
    zhuan[1]=table[y/100%10];
    zhuan[2]=table[y/10%10];
           zhuan[3]=table[y%10];
}
void main ()
{
        unsigned char  wei;
        unsigned char w=0;
        EA=1;
        TR0=1;
        ET0=1;
        TR1=1;
        ET1=1;
        TH0=0x3c;
        TL0=0xb0;
        TH1=0x00;
        TL1=0x00;
        TMOD=0x51;
        chushihua();
        delay1(20);      //在這里如果時間不過長的話 控制位置無用
        xie(0x84);  
        delay();
        while (lcd[w]!='\0')//LCD顯示cesuji
        {
                xieshuju(lcd[w]);
                w++;
         delay();
        }
        w=0;
        xie(0xca);
        while (pin[w]!='\0')//LCD顯示hz
        {
                xieshuju(pin[w]);
                w++;
                delay();
        }
    while (1)
        {
                wei=keycan();
                switch (wei)
                {
                        case 0xfe:  kong=0;        break;//電機全速啟動
                        case 0xfd:
                        case 0xfb:  tiaosu(jia);break;
                        case 0xf7:  kong=1;        break;//電機停止
                }
        }
}
void zhongduan()  interrupt 1   //中斷  刷新數據
{
        unsigned char i;
          TH0=0x3c;
          TL0=0xb0;  //50ms中斷一次
          shi--;
        if(shi<1)//1s取數據一次
        {
          shi=20;
          y=(TH1*256+TL1);//紅外對管中斷次數
          TH1=0x00;
          TL1=0x00;
          zhuanhuan();//數據轉換
          xie(0xc6);
        for(i=0;i<4;i++)//LCD數據處理顯示
        {
           xieshuju(zhuan[ i]);
           delay();
        }
        }
}
void zhongd()  interrupt 3//紅外對管中斷次數
{
        TH1=0x00;
        TL1=0x00;
}


電路圖


作者: mybigapple    時間: 2015-4-23 19:52
感謝分享。
作者: dpj555    時間: 2015-4-24 08:09
謝謝版主加分;謝謝關注。
作者: 我愛吃烤肉    時間: 2017-5-29 11:28
感謝分享
作者: fggko    時間: 2017-7-8 17:28
謝謝版主,正好需要,學習中
作者: 5000322    時間: 2017-8-4 22:43
這個程序很巧妙,頂了




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1