单片机程序这段代码看不懂,求解释
uchardx1,dx2,dy1,dy2;//1正2负0中ucharxy1,xy2;//1:0到22.5度2:22.5度到67.5度3:67.5度到90度voidmain...
uchar dx1,dx2,dy1,dy2; //1正2负0中
uchar xy1,xy2; //1:0到22.5度 2:22.5度到67.5度 3:67.5度到90度
void main (void)
{
//uchar zhix1,zhix2,zhiy1,zhiy2;
P1M0=0x00;
P1M1=0xff;//P2M0=255;P2M1=0;P3M0=255;P3M1=0;
InitADC(); //初始化ADC
InitTimer0();
while (1) //主循环
{
if(dx1&&dy1) //左摇杆 while(dx1==1&&dy1==1&&xy1=1);
{
if(dx1==1&&dy1==1&&xy1==1){P31=P30=0;_delay_ms(500);P31=P30=1;}
if(dx1==1&&dy1==1&&xy1==2){P31=P30=0;P32=P33=0;_delay_ms(500);P31=P30=1;P32=P33=1;}//
if(dx1==1&&dy1==1&&xy1==3){P32=P33=0;_delay_ms(500);P32=P33=1;}
if(dx1==1&&dy1==2&&xy1==1){P31=P30=0;_delay_ms(500);P31=P30=1;}
if(dx1==1&&dy1==2&&xy1==2){P34=P35=0;P31=P30=0;_delay_ms(500);P34=P35=1;P31=P30=0;}//
if(dx1==1&&dy1==2&&xy1==3){P34=P35=0;_delay_ms(500);P34=P35=1;}
if(dx1==2&&dy1==1&&xy1==1){P36=P37=0;_delay_ms(500);P36=P37=1;}
if(dx1==2&&dy1==1&&xy1==2){P32=P33=0;P36=P37=0;_delay_ms(500);P32=P33=1;P36=P37=1;}//
if(dx1==2&&dy1==1&&xy1==3){P32=P33=0;_delay_ms(500);P32=P33=1;}
if(dx1==2&&dy1==2&&xy1==1){P36=P37=0;_delay_ms(500);P36=P37=1;}
if(dx1==2&&dy1==2&&xy1==2){P34=P35=0;P36=P37=0;_delay_ms(500);P34=P35=1;P36=P37=1;}//
if(dx1==2&&dy1==2&&xy1==3){P34=P35=0;_delay_ms(500);P34=P35=1;}
}
if(dx2&&dy2) //摇杆 while(dx1==1&&dy1==1&&xy1=1);
{
if(dx2==1&&dy2==1&&xy2==1){P21=P20=0;_delay_ms(500);P21=P20=1;}
if(dx2==1&&dy2==1&&xy2==2){P21=P20=0;P22=P23=0;_delay_ms(500);P21=P20=1;P22=P23=1;}//
if(dx2==1&&dy2==1&&xy2==3){P22=P23=0;_delay_ms(500);P22=P23=1;}
if(dx2==1&&dy2==2&&xy2==1){P21=P20=0;_delay_ms(500);P21=P20=1;}
if(dx2==1&&dy2==2&&xy2==2){P24=P25=0;P21=P20=0;_delay_ms(500);P24=P25=1;P21=P20=0;}//
if(dx2==1&&dy2==2&&xy2==3){P24=P25=0;_delay_ms(500);P24=P25=1;}
if(dx2==2&&dy2==1&&xy2==1){P26=P27=0;_delay_ms(500);P26=P27=1;}
if(dx2==2&&dy2==1&&xy2==2){P22=P23=0;P26=P27=0;_delay_ms(500);P22=P23=1;P26=P27=1;}//
if(dx2==2&&dy2==1&&xy2==3){P22=P23=0;_delay_ms(500);P22=P23=1;}
if(dx2==2&&dy2==2&&xy2==1){P26=P27=0;_delay_ms(500);P26=P27=1;}
if(dx2==2&&dy2==2&&xy2==2){P24=P25=0;P26=P27=0;_delay_ms(500);P24=P25=1;P26=P27=1;}//
if(dx2==2&&dy2==2&&xy2==3){P24=P25=0;_delay_ms(500);P24=P25=1;}
}
}
}
void Timer0Interrupt() interrupt 1
{
// TH0 =(65535-1000)/256;
// TL0 =(65535-1000)%256;
chuli(255-zhADC(2),zhADC(3),&dx1,&dy1,&xy1);
chuli(255-zhADC(1),zhADC(0),&dx2,&dy2,&xy2);
} 展开
uchar xy1,xy2; //1:0到22.5度 2:22.5度到67.5度 3:67.5度到90度
void main (void)
{
//uchar zhix1,zhix2,zhiy1,zhiy2;
P1M0=0x00;
P1M1=0xff;//P2M0=255;P2M1=0;P3M0=255;P3M1=0;
InitADC(); //初始化ADC
InitTimer0();
while (1) //主循环
{
if(dx1&&dy1) //左摇杆 while(dx1==1&&dy1==1&&xy1=1);
{
if(dx1==1&&dy1==1&&xy1==1){P31=P30=0;_delay_ms(500);P31=P30=1;}
if(dx1==1&&dy1==1&&xy1==2){P31=P30=0;P32=P33=0;_delay_ms(500);P31=P30=1;P32=P33=1;}//
if(dx1==1&&dy1==1&&xy1==3){P32=P33=0;_delay_ms(500);P32=P33=1;}
if(dx1==1&&dy1==2&&xy1==1){P31=P30=0;_delay_ms(500);P31=P30=1;}
if(dx1==1&&dy1==2&&xy1==2){P34=P35=0;P31=P30=0;_delay_ms(500);P34=P35=1;P31=P30=0;}//
if(dx1==1&&dy1==2&&xy1==3){P34=P35=0;_delay_ms(500);P34=P35=1;}
if(dx1==2&&dy1==1&&xy1==1){P36=P37=0;_delay_ms(500);P36=P37=1;}
if(dx1==2&&dy1==1&&xy1==2){P32=P33=0;P36=P37=0;_delay_ms(500);P32=P33=1;P36=P37=1;}//
if(dx1==2&&dy1==1&&xy1==3){P32=P33=0;_delay_ms(500);P32=P33=1;}
if(dx1==2&&dy1==2&&xy1==1){P36=P37=0;_delay_ms(500);P36=P37=1;}
if(dx1==2&&dy1==2&&xy1==2){P34=P35=0;P36=P37=0;_delay_ms(500);P34=P35=1;P36=P37=1;}//
if(dx1==2&&dy1==2&&xy1==3){P34=P35=0;_delay_ms(500);P34=P35=1;}
}
if(dx2&&dy2) //摇杆 while(dx1==1&&dy1==1&&xy1=1);
{
if(dx2==1&&dy2==1&&xy2==1){P21=P20=0;_delay_ms(500);P21=P20=1;}
if(dx2==1&&dy2==1&&xy2==2){P21=P20=0;P22=P23=0;_delay_ms(500);P21=P20=1;P22=P23=1;}//
if(dx2==1&&dy2==1&&xy2==3){P22=P23=0;_delay_ms(500);P22=P23=1;}
if(dx2==1&&dy2==2&&xy2==1){P21=P20=0;_delay_ms(500);P21=P20=1;}
if(dx2==1&&dy2==2&&xy2==2){P24=P25=0;P21=P20=0;_delay_ms(500);P24=P25=1;P21=P20=0;}//
if(dx2==1&&dy2==2&&xy2==3){P24=P25=0;_delay_ms(500);P24=P25=1;}
if(dx2==2&&dy2==1&&xy2==1){P26=P27=0;_delay_ms(500);P26=P27=1;}
if(dx2==2&&dy2==1&&xy2==2){P22=P23=0;P26=P27=0;_delay_ms(500);P22=P23=1;P26=P27=1;}//
if(dx2==2&&dy2==1&&xy2==3){P22=P23=0;_delay_ms(500);P22=P23=1;}
if(dx2==2&&dy2==2&&xy2==1){P26=P27=0;_delay_ms(500);P26=P27=1;}
if(dx2==2&&dy2==2&&xy2==2){P24=P25=0;P26=P27=0;_delay_ms(500);P24=P25=1;P26=P27=1;}//
if(dx2==2&&dy2==2&&xy2==3){P24=P25=0;_delay_ms(500);P24=P25=1;}
}
}
}
void Timer0Interrupt() interrupt 1
{
// TH0 =(65535-1000)/256;
// TL0 =(65535-1000)%256;
chuli(255-zhADC(2),zhADC(3),&dx1,&dy1,&xy1);
chuli(255-zhADC(1),zhADC(0),&dx2,&dy2,&xy2);
} 展开
1个回答
展开全部
注释如下:
uchar dx1,dx2,dy1,dy2; //1正2负0中
uchar xy1,xy2; //1:0到22.5度 2:22.5度到67.5度 3:67.5度到90度
void main (void)
{
//uchar zhix1,zhix2,zhiy1,zhiy2;
P1M0=0x00;
P1M1=0xff;//P1设为输入口,AD用的话必须如此
InitADC(); //初始化ADC
InitTimer0(); //初始化定时器
while (1) //主循环
{
if(dx1&&dy1) //左摇杆 while(dx1==1&&dy1==1&&xy1=1);
{ //以下根据变量dx1,dy1,xy1的值决定执行动作,也就是某些IO口产生周期为1秒的脉冲
if(dx1==1&&dy1==1&&xy1==1){P31=P30=0;_delay_ms(500);P31=P30=1;}
if(dx1==1&&dy1==1&&xy1==2){P31=P30=0;P32=P33=0;_delay_ms(500);P31=P30=1;P32=P33=1;}//
if(dx1==1&&dy1==1&&xy1==3){P32=P33=0;_delay_ms(500);P32=P33=1;}
if(dx1==1&&dy1==2&&xy1==1){P31=P30=0;_delay_ms(500);P31=P30=1;}
if(dx1==1&&dy1==2&&xy1==2){P34=P35=0;P31=P30=0;_delay_ms(500);P34=P35=1;P31=P30=0;}//
if(dx1==1&&dy1==2&&xy1==3){P34=P35=0;_delay_ms(500);P34=P35=1;}
if(dx1==2&&dy1==1&&xy1==1){P36=P37=0;_delay_ms(500);P36=P37=1;}
if(dx1==2&&dy1==1&&xy1==2){P32=P33=0;P36=P37=0;_delay_ms(500);P32=P33=1;P36=P37=1;}//
if(dx1==2&&dy1==1&&xy1==3){P32=P33=0;_delay_ms(500);P32=P33=1;}
if(dx1==2&&dy1==2&&xy1==1){P36=P37=0;_delay_ms(500);P36=P37=1;}
if(dx1==2&&dy1==2&&xy1==2){P34=P35=0;P36=P37=0;_delay_ms(500);P34=P35=1;P36=P37=1;}//
if(dx1==2&&dy1==2&&xy1==3){P34=P35=0;_delay_ms(500);P34=P35=1;}
}
if(dx2&&dy2) //摇杆 while(dx1==1&&dy1==1&&xy1=1);
{
if(dx2==1&&dy2==1&&xy2==1){P21=P20=0;_delay_ms(500);P21=P20=1;}
if(dx2==1&&dy2==1&&xy2==2){P21=P20=0;P22=P23=0;_delay_ms(500);P21=P20=1;P22=P23=1;}//
if(dx2==1&&dy2==1&&xy2==3){P22=P23=0;_delay_ms(500);P22=P23=1;}
if(dx2==1&&dy2==2&&xy2==1){P21=P20=0;_delay_ms(500);P21=P20=1;}
if(dx2==1&&dy2==2&&xy2==2){P24=P25=0;P21=P20=0;_delay_ms(500);P24=P25=1;P21=P20=0;}//
if(dx2==1&&dy2==2&&xy2==3){P24=P25=0;_delay_ms(500);P24=P25=1;}
if(dx2==2&&dy2==1&&xy2==1){P26=P27=0;_delay_ms(500);P26=P27=1;}
if(dx2==2&&dy2==1&&xy2==2){P22=P23=0;P26=P27=0;_delay_ms(500);P22=P23=1;P26=P27=1;}//
if(dx2==2&&dy2==1&&xy2==3){P22=P23=0;_delay_ms(500);P22=P23=1;}
if(dx2==2&&dy2==2&&xy2==1){P26=P27=0;_delay_ms(500);P26=P27=1;}
if(dx2==2&&dy2==2&&xy2==2){P24=P25=0;P26=P27=0;_delay_ms(500);P24=P25=1;P26=P27=1;}//
if(dx2==2&&dy2==2&&xy2==3){P24=P25=0;_delay_ms(500);P24=P25=1;}
}
}
}
void Timer0Interrupt() interrupt 1
{
// TH0 =(65535-1000)/256;
// TL0 =(65535-1000)%256;
chuli(255-zhADC(2),zhADC(3),&dx1,&dy1,&xy1);//没有这个函数原型,所以不明所以
chuli(255-zhADC(1),zhADC(0),&dx2,&dy2,&xy2);//猜测应该是将AD转换结果转换为后面三个
} //变量的值
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询