ATmega16主芯片小车巡线程序,7个红外传感器
/*--------------------search line car v9 ---------------------
改用真正的PD算法
可调整参数:
PWM的值;
标准占空比,即直线速度std_left_duty,std_right_duty ;
比例系数Kp 的值;
差分系数Kd 的值;
count的最大值
---------------------------------------------------------------*/
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
#define moto_left_fwd PORTD=(PORTD|(1<
#define moto_left_bck PORTD=(PORTD|(1<
#define moto_right_fwd PORTD=(PORTD|(1<
#define moto_right_bck PORTD=(PORTD|(1<
#define moto_left_off PORTD=PORTD&(~(1<
#define moto_right_off PORTD=PORTD&(~(1<
#define countertop 10000 //这里定义了pwm波的最大计数值,从而得到50HZ的频率 TOP=fclk/(foc*2*N) N为分频因子N=8