飞思卡尔智能车程序汇总(5)

2019-06-11 16:19

if(FALSE==open) {

PORTB_PB0=1; PWMDTY67=0;

pwm_motor=(setnum[4]-cur_speed/3)*20;

if(pwm_motor>PWMPER45) PWMDTY45=PWMPER45; else if(pwm_motor>0) PWMDTY45=pwm_motor; else

PWMDTY45=0; }

else if(TRUE==open) {

PORTB_PB0=0; PWMDTY45=0;

pwm_motor=(setnum[4]-cur_speed/3)*20;

if(pwm_motor>PWMPER67) PWMDTY67=PWMPER45; else if(pwm_motor>0) PWMDTY67=pwm_motor;

else

PWMDTY67=0; } } } /*

for(;;)

{

disply_number(16,5,cur_speed/5,5);

pwm_motor=(setnum[4]-cur_speed/5)*25;

if(pwm_motor>PWMPER45) PWMDTY45=PWMPER45; else if(pwm_motor>0) PWMDTY45=pwm_motor; else

PWMDTY45=0; } } */

5.电磁车程序

#include /* common defines and macros */ #include

#include \

#include \#include \#include \

///延迟函数///

void delay(unsigned int ms) {

unsigned int i; unsigned char j; for(i=0;i

for(j=0;j<100;j++); }

}

///延迟函数///

#define servo_period 20 //ms #define motor_pwm_frequ 1 //khz

//#define distance 10000

unsigned int SERVO_MID; //=3078

int SERVO_LIMIT=1000; //

/** PWM初始化***/ void Init_PWMout(void) {

PWME = 0x00; //禁止输出 0b00000000

PWMPOL = 0xff;//极性寄存器,1 先输出高电平 后为低电平 0 先输出低电平 后为高电平 0b11111111

PWMCTL = 0xf0; //01 23 45 67 通道级联 0b11110000 PWMPRCLK=0x55; //Clock A=Bus Clock/32 ; Clock B=Bus Clock/32; 0b01010101

PWMCLK=0b00000000; //选择clock:7B,6B,5A,4A,3B,2B,1A,0A

PWME = 0xaa; //pp1,pp3,pp5,pp7口输出 0b10101010

PWMPER67 = 80/4*125/motor_pwm_frequ; PWMPER45 = 80/4*125/motor_pwm_frequ; PWMPER23 = 80/4*servo_period*125; PWMPER01 = 80/4*servo_period*125;

PWMDTY67 =0; PWMDTY45 =0; PWMDTY23 =0; PWMDTY01 =0; }

/** PWM初始化***/

///舵机函数///

void set_servo(int servo) {

if(servo>SERVO_LIMIT)servo=SERVO_LIMIT; if(servo<0-SERVO_LIMIT)servo=0-SERVO_LIMIT; PWMDTY01=SERVO_MID-servo; }


飞思卡尔智能车程序汇总(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017上海各区二模18题(含解析)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: