#include /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define East PORTB_PB0 // I/O
#define West PORTB_PB1 // I/O
#define Shang PORTB_PB2 // I/O
#define Xia PORTB_PB3 // I/O
#define East_switch PORTB_PB4 // ,,
#define West_switch PORTB_PB5 // ,,
#define Shang_switch PORTB_PB6 // ,,
#define Xia_switch PORTB_PB7 // ,,
//#define Shuchu_5V PORTC_PC8 // ,,
#define ENA PORTA_PA0 //HMotor1ENA
#define A1 PORTA_PA1 //HMotor1A1
#define A2 PORTA_PA2 //HMotor1A2
#define ENB PORTA_PA3 //HMotor1ENB
#define B1 PORTA_PA4 //HMotor1B1
#define B2 PORTA_PA5 //HMotor1B2
unsigned char East0=0,West0=0,Shang0=0,Xia0=0,East0_switch=0,West0_switch=0,Shang0_switch=0,Xia0_switch=0; //
void yanshihanshu(); //
void main(void)
{
DDRA_DDRA0=1; //PA0
DDRA_DDRA1=1; //PA1
DDRA_DDRA2=1; //PA2
DDRA_DDRA3=1; //PA3
DDRA_DDRA4=1; //PA4
DDRA_DDRA5=1; //PA5
DDRB=0; //PB
DDRA_DDRA6=1; //PA3
PORTA_PA6=1;
for(;;)
{
East0=East; //
West0=West; //
Shang0=Shang; //
Xia0=Xia; //
East0_switch=East_switch; //
West0_switch=West_switch; //
Shang0_switch=Shang_switch; //
Xia0_switch=Xia_switch; //
if(East0==1) // ,,,,,
{ ENA=1;A1=1;A2=0;}
yanshihanshu();
if(Shang0==1) // ,,,,,
{ ENB=1;B1=0;B2=1;}
yanshihanshu();
if(West0==1) // ,,,,,
{ ENA=1;A1=0;A2=1; }
yanshihanshu();
if(Xia0==1) // ,,,,,
{ ENB=1;B1=1;B2=0; }
yanshihanshu();
if(East0_switch==1) //,
{ ENA=0;
}
if(Xia0_switch==1) // ,
{
ENB=0;
}
if(West0_switch==1) // ,
{
ENA=0;
}
if(Shang0_switch==1) // ,
{
ENB=0;
}
if(East0==0Shang0==0West0==0Xia0==0) //,
{ ENA=0;ENB=0;}
}
EnableInterrupts;
}
void yanshihanshu()
{ int i,j;
for(i=0;i<100;i++)
for(j=0;j<100;j++)
{ ; }
}