欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標(biāo)題:
基于stc89c52單片機(jī)的小車直線行駛源碼
[打印本頁(yè)]
作者:
1754232
時(shí)間:
2024-8-9 22:00
標(biāo)題:
基于stc89c52單片機(jī)的小車直線行駛源碼
小車使用PWM調(diào)節(jié)頻率使得能夠進(jìn)行直線行駛并且可以采用藍(lán)牙進(jìn)行調(diào)控
#include <REGX52.H>
sbit IN1 = P1^1;
sbit IN2 = P1^2;
sbit IN3 = P1^3;
sbit IN4 = P1^4;
sbit ENA = P1^0;
sbit ENB = P1^5;
sbit LED1 = P1^6;
unsigned char counter,compare = 0;
void car_go()
{
IN1 = 1;
IN2 = 0;
IN3 = 0;
IN4 = 1;
}
void Timer0_Init() //100微秒@11.0592MHz
{
TMOD &= 0xF0; //設(shè)置定時(shí)器模式
TMOD |= 0X01; //設(shè)置定時(shí)器模式
TL0 = 0xA4; //設(shè)置定時(shí)初始值
TH0 = 0xFF; //設(shè)置定時(shí)初始值
TF0 = 0; //清除TF0標(biāo)志
TR0 = 1; //定時(shí)器0開始計(jì)時(shí)
ET0 = 1;
EA = 1;
PT0 = 0;
}
void Timer_Init() interrupt 1
{
TL0 = 0xA4; //設(shè)置定時(shí)初始值
TH0 = 0xFF; //設(shè)置定時(shí)初始值
counter = 32;
compare ++ ;
if(compare <= counter)
{
IN1 = 0;
IN2 = 1;
}
else
{
IN1 = 1;
IN2 = 0;
}
if(compare == 100)
{
compare = 0;
}
}
void main()
{
Timer0_Init();
ENA = 1;
ENB = 1;
while(1)
{
car_go();
}
}
復(fù)制代碼
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1