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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2141|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

單片機(jī)+紅外模塊控制小車定點(diǎn)停車和轉(zhuǎn)向

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:605843 發(fā)表于 2019-12-6 19:49 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
20黑幣
在用紅外模塊TCRT5000使小車定點(diǎn)停車,變向,小車用l298n驅(qū)動(dòng),外加PT2262遙控調(diào)速,仿真已經(jīng)實(shí)現(xiàn)了,為啥弄實(shí)物的時(shí)候電機(jī)不動(dòng)呢?l298n的電機(jī)工作狀態(tài)一直顯示不工作,但電機(jī)驅(qū)動(dòng)模塊是新的,沒問題,請大佬們指導(dǎo)一下,程序應(yīng)該沒問題吧。
#include <reg52.h>

typedef unsigned char u8;
typedef unsigned int u16;


sbit in1= P2^0;           //L298N引腳定義
sbit in2= P2^1;
sbit in3= P2^2;
sbit in4= P2^3;
sbit en1=P3^0;
sbit en2=P3^5;                                                                                                                                                                                                                                                                                                                                                                                    
//sbit key1=P3^1;//前進(jìn)  ,遙控器引腳定義
//sbit key2=P3^2;//后退
sbit key3=P3^3;//加速
sbit key4=P3^4;//減速

sbit chetou=P2^4; //紅外傳感器引腳定義
sbit chewei=P2^5;
sbit cheshen=P2^6;

u16 M;//改變占空,一共有240
u16 Z;//用于中斷程序,實(shí)時(shí)紅外檢測

void delay_us(u16 aa) //延時(shí)函數(shù)
{
        while(aa--);
}



void main()
{
        u16 a;
        a=120;//初始的速度
        en1=0;
        en2=0;
        TMOD = 0x01;  // T0定時(shí)器為工作方式一
        TH0 = 0x0FF;                    //設(shè)置初值
        TL0 = 0x09C;          //設(shè)置初值
        TR0 = 1; //開啟定時(shí)器T0
        ET0 = 1;//開放定時(shí)器T0中斷
        EA = 1;//開放總中斷
    //key1 = 0;
        //key2 = 0;
        key3 = 1;//用于仿真工程,真正寫入程序板的時(shí)候要改為0
        key4 = 1;

        while(1)
        {
           if(Z==240)
           {
           Z=0;
           if((chetou==0&&chewei==1&&cheshen==1)||(chewei==0&&chetou==1&&cheshen==1)||(chetou==1&&chewei==0&&cheshen==0)||(chetou==0&&chewei==1&&cheshen==0))
                {
                        delay_us(2);
           if((chetou==0&&chewei==1&&cheshen==1)||(chewei==0&&chetou==1&&cheshen==1)||(chetou==1&&chewei==0&&cheshen==0)||(chetou==0&&chewei==1&&cheshen==0))
                        {
                                en1=0;
                                en2=0;
                                in1=0;
                                in2=0;
                                in3=0;
                                in4=0;

                        }
                }
                if((chetou==0)&&(chewei==0)&&(cheshen==1))
                {
                        delay_us(2);
                if((chetou==0)&&(chewei==0)&&(cheshen==1))
                        {
                                in1=1;
                                in2=0;
                                in3=0;
                                in4=1;
                        }
                }
                if((chetou==0)&&(chewei==0)&&(cheshen==0))
                {
                        delay_us(2);
                if((chetou==0)&&(chewei==0)&&(cheshen==0))
                        {
                                in1=0;
                                in2=1;
                                in3=1;
                                in4=0;
                        }
                }               
           }

               
                if(key3==0)
                {
                        delay_us(2);
                        if(key3==0)
                        {
                                a+=40;
                                if(a>=240)
                                        a=240;
                        }
                        while(!key3);
                        delay_us(2);
                        while(!key3);
                }
                if(key4==0)
                {
                        delay_us(2);
                        if(key4==0)
                        {
                                a-=40;
                                if(a<=40)
                                        a=40;
                        }
                        while(!key4);
                        delay_us(2);
                        while(!key4);


                }
                if(M==0)
                {
                        en1=1;

                        en2=1;

                }
                if(M==a)
                {
                        en1=0;
                        en2=0;

                }

        }
}

void time0_int() interrupt 1   //T = 0.1ms * 240 = 24ms
{  
TR0 = 0;      
TH0 = 0x0FF;
TL0 = 0x09C; //0.1ms
M++;
Z++;
if(M>=240)
{
        M=0;               
}
TR0 = 1;
}

用的開關(guān)代替的PT2262個(gè)TCRT5000因?yàn)檐浖餂]有這倆元件



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表