⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dfhfgh.txt

📁 03年全国大学生电子设计竞赛智能小车mega16源代码
💻 TXT
📖 第 1 页 / 共 2 页
字号:
p_to_flash=X13; dis_one_zi(0,6,p_to_flash); 
delay(200); 
p_to_flash=X14; dis_one_zi(1,4,p_to_flash); 
p_to_flash=X15; dis_one_zi(1,5,p_to_flash); 
p_to_flash=X16; dis_one_zi(1,6,p_to_flash); 
p_to_flash=X17; dis_one_zi(1,7,p_to_flash); 

for(n=0;n<5;n++) 
{ 
PORTB.7=1; 
p_to_flash=X18; dis_one_zi(3,2,p_to_flash); //欢迎您! 
p_to_flash=X19; dis_one_zi(3,3,p_to_flash); 
p_to_flash=X20; dis_one_zi(3,4,p_to_flash); 
p_to_flash=X27; dis_one_ban_zi(3,5,0,p_to_flash); 
delay(200);delay(200); 
PORTB.7=0; 
p_to_flash=X26; dis_one_zi(3,2,p_to_flash); //清除欢迎您! 
p_to_flash=X26; dis_one_zi(3,3,p_to_flash); 
p_to_flash=X26; dis_one_zi(3,4,p_to_flash); 
p_to_flash=X26; dis_one_zi(3,5,p_to_flash); 
delay(200);delay(200); 
} 

p_to_flash=X25; //黑屏 
for(n=0;n<4;n++){ 
for(m=0;m<8;m++) 
{dis_one_zi(n,m,p_to_flash);}} 
delay(20); 
CLRLCD(); //清屏 
} 

void display_second_st() 
{ 
p_to_flash=X29; dis_one_zi(0,0,p_to_flash); //行车时间:*秒 
p_to_flash=X30; dis_one_zi(0,1,p_to_flash); 
p_to_flash=X23; dis_one_zi(0,2,p_to_flash); 
p_to_flash=X24; dis_one_zi(0,3,p_to_flash); 
p_to_flash=X28; dis_one_ban_zi(0,4,0,p_to_flash); 
p_to_flash=X36; dis_one_zi(0,7,p_to_flash); 

p_to_flash=X29; dis_one_zi(1,0,p_to_flash); //行驶路程:*厘米 
p_to_flash=X31; dis_one_zi(1,1,p_to_flash); 
p_to_flash=X32; dis_one_zi(1,2,p_to_flash); 
p_to_flash=X33; dis_one_zi(1,3,p_to_flash); 
p_to_flash=X28; dis_one_ban_zi(0,4,0,p_to_flash); 
p_to_flash=X34; dis_one_zi(1,6,p_to_flash); 
p_to_flash=X35; dis_one_zi(1,7,p_to_flash); 

p_to_flash=X37; dis_one_zi(2,0,p_to_flash); //检测铁片数:*块 
p_to_flash=X38; dis_one_zi(2,1,p_to_flash); 
p_to_flash=X39; dis_one_zi(2,2,p_to_flash); 
p_to_flash=X40; dis_one_zi(2,3,p_to_flash); 
p_to_flash=X41; dis_one_zi(2,4,p_to_flash); 
p_to_flash=X28; dis_one_ban_zi(2,5,0,p_to_flash); 
p_to_flash=X42; dis_one_zi(2,7,p_to_flash); 

p_to_flash=X43; dis_one_zi(3,0,p_to_flash); //距离: 
p_to_flash=X44; dis_one_zi(3,1,p_to_flash); 
p_to_flash=X28; dis_one_ban_zi(3,2,0,p_to_flash); 
p_to_flash=X21; dis_one_ban_zi(3,4,0,p_to_flash); 
p_to_flash=X21; dis_one_ban_zi(3,6,0,p_to_flash); 
} 

void display_second() 
{ 
o=time_now/10;p=time_now-(10*o); 
switch_p(o); dis_one_ban_zi(0,5,0,p_to_flash); 
switch_p(p); dis_one_ban_zi(0,5,1,p_to_flash); 

o=distance/100;p=(distance-(100*o))/10;q=distance%10; 
switch_p(o); dis_one_ban_zi(1,4,1,p_to_flash); 
switch_p(p); dis_one_ban_zi(1,5,0,p_to_flash); 
switch_p(q); dis_one_ban_zi(1,5,1,p_to_flash); 

switch_p(t); dis_one_ban_zi(2,6,0,p_to_flash); 

o=distance_fe[0]/100;p=(distance_fe[0]-(100*o))/10;q=distance_fe[0]%10; 
switch_p(o); dis_one_ban_zi(3,2,1,p_to_flash); 
switch_p(p); dis_one_ban_zi(3,3,0,p_to_flash); 
switch_p(q); dis_one_ban_zi(3,3,1,p_to_flash); 
o=distance_fe[1]/100;p=(distance_fe[1]-(100*o))/10;q=distance_fe[1]%10; 
switch_p(o); dis_one_ban_zi(3,4,1,p_to_flash); 
switch_p(p); dis_one_ban_zi(3,5,0,p_to_flash); 
switch_p(q); dis_one_ban_zi(3,5,1,p_to_flash); 
o=distance_fe[2]/100;p=(distance_fe[2]-(100*o))/10;q=distance_fe[2]%10; 
switch_p(o); dis_one_ban_zi(3,6,1,p_to_flash); 
switch_p(p); dis_one_ban_zi(3,7,0,p_to_flash); 
switch_p(q); dis_one_ban_zi(3,7,1,p_to_flash); 


} 
void car_stop(void) 
{ 
b=0; 
PORTD.6=0; 
PORTD.7=0; 
PORTD.4=0; 
PORTD.5=0; 
display_second(); 
} 
void car_stop_c(void) 
{ 
b=0; 
PORTD.6=0; 
PORTD.7=0; 
PORTD.4=0; 
PORTD.5=0; 
temp=time_now; 
for(u=0;u<5;u++) 
{ 
PORTB.7=1; 
delay(200);delay(200); 
PORTB.7=0; 
delay(200);delay(200); 
display_second(); 
} //蜂鸣器开。蜂鸣器关 
//do{display_second();} 
//while(time_now>temp+5); 
} 

void pwm_moto2_back(void) 
{ 
b=3; 
PORTD.6=0; 
} 

void pwm_moto2_go(void) 
{ 
b=1; 
PORTD.6=1; 
} 

void pwm_moto2_godown(void) 
{ 
b=2; 
PORTD.6=1; 
} 

void direction_moto1(void) 
{ 
if(PINB.2==1){PORTD.4=0;PORTD.5=1;} 
if(PINB.3==1){PORTD.4=0;PORTD.5=1;} 
if(PIND.1==1){PORTD.4=1;PORTD.5=0;} 
if(PIND.0==1){PORTD.4=1;PORTD.5=0;} 
if(PIND.0==0&&PIND.1==0&&PINB.3==0&&PINB.2==0){PORTD.4=0;PORTD.5=0;} 
} 

void avoid_block(void) 
{ 
for(u=0;u<950;u++) 
{ 
pwm_moto2_go(); 
PORTD.4=0;PORTD.5=1;//左转 
if(PIND.3==0) 
{ 
b=0;PORTD.6=0; 
PORTD.4=1;PORTD.5=0;//右转 
pwm_moto2_back(); 
delay(1600); 
} 
delay(2); 
} 
for(u=0;u<800;u++) 
{ 
pwm_moto2_go(); 
PORTD.4=1;PORTD.5=0; 
if(PIND.3==0) 
{ 
b=0;PORTD.6=0; 
PORTD.4=0;PORTD.5=1; 
pwm_moto2_back(); 
delay(1600); 
} 
delay(2); 
} 
} 
void search_way(void) 
{ 
PORTD.4=1;PORTD.5=0; 
pwm_moto2_godown(); 
//delay(100); 
while(1) 
{ 
if(PINB.0==0) 
{ 
nop(); 
if(PINB.0==0) 
{ 
PORTD.4=1;PORTD.5=0;delay(40); 
//PORTD.4=1;PORTD.5=0;delay(50); 
} 
} 
if(PINB.0==1) 
{ 
nop(); 
if(PINB.0==1) 
{ 
PORTD.4=0;PORTD.5=1;delay(40); 
//PORTD.4=0;PORTD.5=1;delay(50); 
} 
} 
if(PIND.3==0)break; 
} 
} 

void main(void) 
{ 
// Declare your local variables here 

// Input/Output Ports initialization 
// Port A initialization 
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out 
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0 
PORTA=0x00; 
DDRA=0xFF; 

// Port B initialization 
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=Out 
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=0 
PORTB=0x00; 
DDRB=0x80; 

// Port C initialization 
// Func0=Out Func1=Out Func2=Out Func3=Out Func4=Out Func5=Out Func6=Out Func7=Out 
// State0=0 State1=0 State2=0 State3=0 State4=0 State5=0 State6=0 State7=0 
PORTC=0x00; 
DDRC=0xFF; 

// Port D initialization 
// Func0=In Func1=In Func2=In Func3=In Func4=Out Func5=Out Func6=Out Func7=Out 
// State0=T State1=T State2=T State3=T State4=0 State5=0 State6=0 State7=0 
PORTD=0x00; 
DDRD=0xF0; 

// Timer/Counter 0 initialization 
// Clock source: System Clock 
// Clock value: 31.250 kHz 
// Mode: Normal top=FFh 
// OC0 output: Disconnected 
TCCR0=0x04; 
TCNT0=0xFB; 
OCR0=0x00; 

// Timer/Counter 1 initialization 
// Clock source: T1 pin Rising Edge 
// Mode: Normal top=FFFFh 
// OC1A output: Discon. 
// OC1B output: Discon. 
// Noise Canceler: Off 
// Input Capture on Falling Edge 
TCCR1A=0x00; 
TCCR1B=0x07; 
TCNT1H=0x00; 
TCNT1L=0x00; 
OCR1AH=0x00; 
OCR1AL=0x00; 
OCR1BH=0x00; 
OCR1BL=0x00; 

// Timer/Counter 2 initialization 
// Clock source: System Clock 
// Clock value: Timer 2 Stopped 
// Mode: Normal top=FFh 
// OC2 output: Disconnected 
ASSR=0x00; 
TCCR2=0x00; 
TCNT2=0x00; 
OCR2=0x00; 

// External Interrupt(s) initialization 
// INT0: On 
// INT0 Mode: Falling Edge 
// INT1: Off 
// INT2: Off 
GICR|=0x40; 
MCUCR=0x02; 
MCUCSR=0x00; 
GIFR=0x40; 

// Analog Comparator initialization 
// Analog Comparator: Off 
// Analog Comparator Input Capture by Timer/Counter 1: Off 
// Analog Comparator Output: Off 
ACSR=0x80; 
SFIOR=0x00; 



// Global enable interrupts 
#asm("sei") 

t=0;e=0;k=0;time_now=0;b=0;c=0; 
display_frist(); 

// Timer(s)/Counter(s) Interrupt(s) initialization 
TIMSK=0x01; 

pwm_moto2_go(); 
display_second_st(); 

while (1) 
{ 
direction_moto1(); 
display_second(); 
if(distance>240&&time_now<90){break;} 
}; 
a=0;c=1; 
while(1) 
{ 
if(distance>230||PINB.2==1||PINB.3==1) 
{ 
PORTD.4=0; 
PORTD.5=1; 
display_second(); 
if(a==1)break; 
} 
} 
car_stop_c(); 
avoid_block(); 
search_way(); 
car_stop(); 
// Timer(s)/Counter(s) Interrupt(s) initialization 
TIMSK=0x00; 
display_second_st(); 
display_second(); 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -