找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

求救!!!我这有个程序想请高手帮我讲解一下!

[复制链接]
admin 发表于 2012-9-2 10:29:22 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
#include <AVR/io.h>

#include <avr/interrupt.h>

#include <avr/signal.h>

#include <avrbit.h>

#include <delay.h>

#define uchar unsigned char

#define uint unsigned int

#define MaxSpeed 0x0000

#define MidSpeed 0x0040 //中速 行驶

#define StopSpeed 0x03ff

#define no_obj 0x00

#define right_bigobj 0x06

#define double_obj 0x05

#define left_bigobj 0x03

#define front_bigobj 0x07



#define TurnSpeed_RQQQ 0x0014 //右轮快 做了调整

#define TurnSpeed_QQQ 0x0000

#define TurnSpeed_D 0x03ff //大弯

#define TurnSpeed_Z 0x02ff //中弯

#define TurnSpeed_X 0x0052 //小弯



void delay(uint ms)

{

uint i;

for(ms;ms>0;ms--)

for(i=0;i<1141;i++){;}

}

void Timer1Init( )

{

uint sreg;



sreg = SREG;

cli();



TCCR1A = (1<<WGM11) | (1<<WGM10) | ( 1<<COM1A1) | ( 1<<COM1A0) | ( 1<<COM1B1) | ( 1<<COM1B0);

TCCR1B = (1<<CS10);





SREG = sreg;

}

void SetOutputComReg1A(uint tempocr)

{

OCR1A = tempocr;

}



/**************************OCR1B寄存器*********************************/

void SetOutputComReg1B(uint tempocr)

{

OCR1B = tempocr;

}

uchar duij()

{

uchar j;

DDRB&=0xf8;

PORTB|=0x03;

j=PINB&0x03;

j=PINB&0x03;

return j;

}

void front_car()//黑路白线

{

BIT_PA2 = 0;

BIT_PA3 = 1;

BIT_PA4 = 0;

BIT_PA5 = 1;

SetOutputComReg1A(MidSpeed+400);

SetOutputComReg1B(MidSpeed+500);

}

void X_right_car()

{

BIT_PA2 = 0;

BIT_PA3 = 1;

BIT_PA4 = 0;

BIT_PA5 = 1;

SetOutputComReg1A(TurnSpeed_X);

SetOutputComReg1B(TurnSpeed_RQQQ);

}

void D_right_car()

{

BIT_PA2 = 0;

BIT_PA3 = 1;

BIT_PA4 = 0;

BIT_PA5 = 1;

SetOutputComReg1A(TurnSpeed_D);

SetOutputComReg1B(TurnSpeed_RQQQ);

}

void X_left_car()

{

BIT_PA2 = 0;

BIT_PA3 = 1;

BIT_PA4 = 0;

BIT_PA5 = 1;

SetOutputComReg1A(TurnSpeed_RQQQ);

SetOutputComReg1B(TurnSpeed_X);

}

void D_left_car()

{

BIT_PA2 = 0;

BIT_PA3 = 1;

BIT_PA4 = 0;

BIT_PA5 = 1;

SetOutputComReg1A(TurnSpeed_RQQQ);

SetOutputComReg1B(TurnSpeed_D);

}

void Stop_car()

{

BIT_PA2 = 0;

BIT_PA3 = 0;

BIT_PA4 = 0;

BIT_PA5 = 0;

SetOutputComReg1A(0x0000);

SetOutputComReg1B(0x0000);

}

int main()

{

uchar i;

DDRA = 0xff;

DDRD = 0x30;

PORTD = 0x00;

Timer1Init();

asm("sei");

while(1)

{

i=duij();

switch(i)

{

case no_obj:front_car();break;

case right_bigobj:D_left_car();break;

case left_bigobj:D_right_car();break;

case front_bigobj:D_right_car();break;

case double_obj:front_car();break;

}
这是一个壁障小车的程序,我想请哪位高手可以帮我讲解一下,越详细越好!多谢了!
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 18:58 , Processed in 0.056388 second(s), 9 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表