?? bianma.c
字號:
// Target : 8515
// Crystal: 8.0000Mhz
// 更新日期: 2003.03.18
// 接上遙控器,按動"A","B","C","D"會有LED燈指示
// 程序中每按鍵4次,認為一次輸入,
//4個一組,根據按鍵的不同執(zhí)行相應程序
//按四次"A",運行懸崖車程序
//按四次"B",運行遙控車程序
//無鍵按下----------前行
//"A", 按住---------右轉
//"B", 按住---------后退
//"C", 按住---------停止
//"D", 按住---------左轉
//按四次"C",運行音樂車程序
//按四次"D",運行霓虹車程序
#include <io8515v.h>
#include <macros.h>
#include <sl3010.c>
//#define A 0x04 //0b0000,0100
//#define B 0x02 //0b0000,0010
//#define C 0x08 //0b0000,1000
//#define D 0x01 //0b0000,0001
#define delaytime 300
unsigned char bianma;
unsigned char pa,pb,pc,pd,sl,remote,bianma_count;
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GIMSK = 0x00;
TIMSK = 0x00;
SEI(); //re-enable interrupts
//all peripherals are now initialised
}
void remote_car()
{
unsigned char stop_rst,temp;
DDRB = 0x00;PORTB = 0xFF;
DDRA = 0xff;PORTA = 0xff;
while(1)
{
remote = pb = PINB & 0x0F;
PORTA = ~pb;
if(pb == 0x04)
{
PORTD = 0x60; //右轉//0110 0000
PORTA = 0xCC; //1100,1100
stop_rst=0x00;
}
if(pb == 0x02)
{
PORTD = 0x50; //后退//0101 0000
PORTA = 0x3C; //0011,1100
stop_rst=0x00;
}
if(pb == 0x08)
{
PORTD = 0xff; //stop
PORTA = 0xff; //
stop_rst++;
}
if(pb == 0x01)
{
PORTD = 0x90; //左轉//1001 0000
PORTA = 0x33; //0011,0011
stop_rst=0x00;
}
if(pb == 0x00)
{
PORTD = 0xA0; //前行//1010 0000
PORTA = 0xC3; //1100,0011
}
/*
while(1)
{
temp = PINB & 0x0f;
if(temp != remote)
{break;}
}
if(stop_rst == 0x04)
{
PORTD = 0xff; //stop
PORTA=0xff; //
break;
}
*/
delay_ms(100);
}
}
void xuanya_car(void)
{
DDRC=0x01;PORTC=0xFF;
DDRA=0xFF;PORTA=0xFF;
DDRD=0xFF;PORTD=0xFF;
while(1)
{//左(pc7) 中(pc6) 右(pc5)
pc = PINC & 0x10;
if(pc==0x00)
{
PORTD = 0x50;
PORTA=0x3C;//后退
delay_ms(delaytime);
PORTD = 0x60;
PORTA=0xCC;//右轉
delay_ms(delaytime/2);
}
pc = PINC & 0xE0;
if(pc==0x40)
{
PORTD = 0xFF;//剎車
PORTA = 0xFF;
//后退,右轉
PORTD = 0x50;
PORTA=0x3C;//后退
delay_ms(delaytime);
PORTD = 0x60;
PORTA=0xCC;//右轉
delay_ms(delaytime/2);
}
if(pc==0x80)
{
stop();
//往右轉彎
PORTD = 0x50;
PORTA=0x3C;//后退
delay_ms(delaytime);
PORTD = 0x60;//右轉
PORTA=0xCC;
delay_ms(delaytime);
}
if(pc==0x20)
{
stop();
//往右轉彎
PORTD = 0x50;//后退
PORTA=0x3C;
delay_ms(delaytime);
PORTD = 0x60;//右轉
PORTA=0xCC;
delay_ms(delaytime);
}
if(pc==0xc0)
{
stop();
//后退,往右轉彎
PORTD = 0x50;//后退
PORTA=0x3C;
delay_ms(delaytime);
PORTD = 0x60;//右轉
PORTA=0xCC;
delay_ms(delaytime);
}
if(pc==0x60)
{
stop();
//后退,往右轉彎
PORTD = 0x50;
PORTA=0x3C;//后退
delay_ms(delaytime);
PORTD = 0x60;//右轉
PORTA=0xCC;
delay_ms(delaytime);
}
if(pc==0xE0)
{
//剎車
PORTD = 0xF0;
PORTA = 0xFF;
}
else
{
PORTD = 0xA0;//前行
PORTA=0xC3;
}
}
}
void music_car()
{
DDRA = 0xFF; PORTA = 0xFF;
PORTA = 0xCC;
while (1)
;
}
void led_car()
{
DDRA = 0xFF; PORTA = 0xFF;
PORTA = 0x0F;
while (1)
;
}
void main(void)
{
unsigned temp;
port_init(); //PA,PB,PC,PD 初始化
loop:
PORTA = 0x00;delay_ms(500);
PORTA = 0xff;delay_ms(500);
bianma = 0x0000;
while(1)
{
remote = PINB & 0x0f;
PORTA = ~remote;
switch (remote)
{//按鍵檢查
case 0x04 :
{
bianma=bianma | 0xA000;
bianma_count = bianma_count+1;
}
break;
case 0x02 :
{
bianma=bianma | 0x0B00;
bianma_count = bianma_count+1;
}
break;
case 0x08 :
{
bianma=bianma | 0x00C0;
bianma_count = bianma_count+1;
}
break;
case 0x01 :
{
bianma=bianma | 0x000D;
bianma_count = bianma_count+1;
}
break;
}
while(1)
{//釋鍵檢查
temp = PINB & 0x0f;
if(temp != remote)
{break;}
}
if(bianma_count == 4)
{//按鍵四次,認為 一次有效輸入結束
bianma_count=0;break;
}
}
delay_ms(200);
PORTA = 0xaa;delay_ms(500);
PORTA = 0x55;delay_ms(500);
if(bianma == 0xa000)
{xuanya_car();}
if(bianma == 0x0b00)
{remote_car();}
if(bianma == 0x00c0)
{music_car();}
if(bianma == 0x000d)
{led_car();}
else goto loop;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -