標(biāo)題:
藍(lán)牙舵機(jī)小車單片機(jī)程序
[打印本頁]
作者:
孫小偉
時(shí)間:
2019-2-25 18:24
標(biāo)題:
藍(lán)牙舵機(jī)小車單片機(jī)程序
藍(lán)牙舵機(jī)小車
關(guān)于這個(gè)程序有什么問題盡管提問
#include <reg51.h>
typedef unsigned int u16; //對(duì)數(shù)據(jù)類型進(jìn)行聲明定義
typedef unsigned char u8;
sbit IRIN=P3^2;
sbit IN1=P1^0;
sbit IN2=P1^1;
sbit ENA=P0^2;
sbit pwm=P2^1;//輸出PWM信號(hào)
sbit k1=P3^2;
u8 a,b,c;
void delay(int i)
{
while(i--);
}
void uart_init()
{
TMOD|=0x20;
PCON =0x00;
SCON = 0x50;
TH1 = 0xFd; //設(shè)置波特率 9600
TL1 = 0xFd;
TR1 = 1; //啟動(dòng)定時(shí)器1
ES = 1; //開串口中斷
EA = 1; //開總中斷
}
void uart() interrupt 4
{
if(RI==1)
RI=0;
a=SBUF;
}
void InitTimer()
{
TMOD|=0x01;//開定時(shí)器0,1
TH0=0xff;//定時(shí)1.5MS,這時(shí)舵機(jī)處于0度
TL0=0xf6;
EA=1;//開總斷
ET0=1;
TR0=0;
}
void timer0() interrupt 1//定時(shí)器0中斷函數(shù)
{
TH0=0xff;//定時(shí)1.5MS,這時(shí)舵機(jī)處于0度
TL0=0xf6;
b++;
if(b==1) pwm=0;
else if(b==2) pwm=1;
else if(b==c) b=0;
TR0=0;
}
void Int0Init()
{
EX0=0;
IT0=0;
EA=1;
}
void Int0() interrupt 0
{
while(k1==0)
{
if(a==0x03)
{
c=26;
k1=1;
EX0=0;
}
else if(a==0x04)
{
c=37;
k1=1;
EX0=0;
}
else if(a==0x01)
{
c=31;
k1=1;
EX0=0;
}
}
}
void main()
{
InitTimer();
uart_init();
Int0Init();
TR0=0;
while(1)
{
if(a==0x01)
{
IN1=0;
IN2=1;
EX0=1;
TR0=1;
k1=0;
} //左轉(zhuǎn) 28 2
else if(a==0x02)
{
EX0=1;
TR0=0;
IN1=1;
IN2=0;
}
//else if(a==0x00)
else if(a==0x03)
{
EX0=1;
TR0=1;
k1=0;
}
else if(a==0x04)
{
EX0=1;
TR0=1;
k1=0;
}
else if(a==0x05)
{
IN1=0;
IN2=0;
}
}
}
作者:
admin
時(shí)間:
2019-2-25 22:54
本帖需要重新編輯補(bǔ)全電路原理圖,源碼,詳細(xì)說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
作者:
AZybz
時(shí)間:
2019-9-13 18:30
為啥連接了兩個(gè)P32口
作者:
畢達(dá)哥拉斯1.1
時(shí)間:
2019-12-19 11:17
燒錄后腫么沒有反應(yīng)呢
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1