PW 碉速+循迹-智能小车程序〃T0 产生双路 PWM 信号,L298N 为直流电机调速,接 L298N 时相应的管脚上最好接上 10K 的上拉电阻
/晶振采纳 12M,产生的 PWM 的频率约为1Hz */#include#include#define uchar unsigned char#define uint unsigned intsbit en1=P3A4; /* L29 的 Enable A */sbit en2=P3A5; /* L298 的 Enable B */sbit s1=P1A0 ;/* L298 的 Input 1 */sbit s2=P1A1 ;/* L298 的 Input 2 */sbit s3=P1A3; /* L298 的 Input 3 */sbit s4=P1A2; /* L298 的 Input 4 */sbit R=P2A0 ;sbit C=P2A1 ;sbit L=P2A2;sbit key=P1A4;uchar t=0;伸断计数器*/uchar m 仁 0; /电机 1 速度值*/uchar m2=0; /*电机 2 速度值*/uchar tmp1,tmp2; /*电机当前速度值*/电机控制函数index-电机号(1,2); speed 电机 速度(0-1) */void motor(uchar index, char speed){if(speedv=1){if(index==1) / 电机 1 的处理 */{m1=abs(speed); /* 取速度的绝对值*/s1=1;s2=0;}if(index==2) / 电机 2 的处理 */(m2=abs (speed); /* 电机 2 的速度控制*/s3=1;s4=0;}void Back(void) (s1=0;s2=1;s3=1;s4=0;}void GO(void){