最近参加了学校组织的TI小车培训,经过两三天的培训,可算写出来了,此车采用的是八路循迹模块,根据地图实际情况可以稍加修改,我这里采用的是右手法则,十字右转,T型右转直走加左转直行,直走加右转右转。代码如下(需要的头文件在TI官网有,我也会发在资源里)
#include <stdio.h>
#include “msp.h”
#include “…/inc/Clock.h”
#include “…/inc/UART0.h”
#include “…/inc/Reflectance.h”
#include “…/inc/PWM.h”
#include “…/inc/Motor.h”
#include “…/inc/JN_LCD.h”
#define RED 0x01
#define GREEN 0x02
#define BLUE 0x04
#define yellow 0x03
#define sky blue 0x06
#define white 0x07
#define pink 0x05
uint8_t Data;
uint16_t L = 4500;
uint16_t R = 4500;
void Port2_Init(void){
P2->SEL0 = 0x00;
P2->SEL1 = 0x00;
P2->DS = 0x07;
P2->DIR = 0x07;
P2->OUT = 0x00;
}
void Port2_output(uint8_t data){
P2->OUT=data;
}
void main1(void)
{<