欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
單片機循跡小車 PWM 紅外
[打印本頁]
作者:
啥也不會丶
時間:
2019-8-7 15:31
標題:
單片機循跡小車 PWM 紅外
#include <REGX51.H>
sbit out1 = P1^0;
sbit out2 = P1^1;
sbit PWMA = P2^0;
sbit PWMB = P2^1;
sbit AIN1 = P2^2;
sbit AIN2 = P2^3;
sbit BIN1 = P2^4;
sbit BIN2 = P2^5;
sbit STBY = P2^6;
unsigned char flag;
unsigned char model;
void init()
{
TMOD = 0X01;
TH0 = (65535 - 10) / 256;
TL0 = (65535 - 10) % 256;
TR0 = 1;
EA = 1;
ET0 = 1;
}
void main()
{
init();
while(1)
{
STBY = 1;
AIN1 = 1;
AIN2 = 0;
BIN1 = 1;
BIN2 = 0;
if(out1 == 0 && out2 == 0)
{
flag = 50;
model = 0;
}
if(out1 == 0 && out2 == 1)
{
flag =30;
model = 1;
}
if(out1 == 1 && out2 == 0)
{
flag = 30;
model = 2;
}
if(out1 == 1 && out2 == 1)
{
PWMA = 0;
PWMB = 0;
}
}
}
void timer0() interrupt 1
{
static unsigned char PWMflag = 0;
static int time;
TH0 = (65535 - 200) / 256;
TL0 = (65535 - 200) % 256;
time ++;
if(time == 1000)
{
time = 0;
PWMflag ++;
if(PWMflag == 100)PWMflag = 0;
}
if(model == 0)
{
if(PWMflag<flag)
{
PWMA = 1;
PWMB = 1;
}
else
{
PWMA = 0;
PWMB = 0;
}
}
if(model == 1)
{
if(PWMflag<flag)
{
PWMA = 1;
PWMB = 0;
}
else
{
PWMA = 0;
PWMB = 0;
}
}
if(model == 2)
{
if(PWMflag<flag)
{
PWMA = 0;
PWMB = 1;
}
else
{
PWMA = 0;
PWMB = 0;
}
}
}
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1