1个回答
展开全部
#include<reg52.h>
#define uchar unsigned signed
sbit jia_key=P3^6;
sbit jian_key=P3^7;
sbit zf_key=P3^5;
bit flag=0;
uchar codetable[]={0x01,0x02,0x04,0x08,0x08,0x04,0x02,0x01};
uchar num,qidong,PWM,table_begin;
void delay(uchar 1)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void key()
{
if(jia_key==0)
{
delay(5);
if(jia_key==0)
{
num++;
if(num==4)num=3;
while(jia_key==0);
}
}
if(jian_key==0)
{
delay(5);
if(jian_key==0)
if(num!=0)
num--;
else
num=0;
while(jian_key==0);
}
}
if(zf_key==0)
{
delay(5);
if(zf_key==0)
{
flag=-flag;
while(zf_key==0);
}
}
}
void qidong()
{
uchar i,j;
switch(num)
{
case 0:PWM=5;break;
case 1:PWM=4;break;
case 2:PWM=3;break;
case 3:PWM=2;break;
}
if(flag==0)
table_begin=0;
else
table_begin=4;
for(i=table_begin;i<4+table_begin;i++)
{
P1=table[i];
for(j=0;j<PWM;j++)
delay(10);
}
}
void main()
{
while(1)
{
key();
qidong();
}
}
#define uchar unsigned signed
sbit jia_key=P3^6;
sbit jian_key=P3^7;
sbit zf_key=P3^5;
bit flag=0;
uchar codetable[]={0x01,0x02,0x04,0x08,0x08,0x04,0x02,0x01};
uchar num,qidong,PWM,table_begin;
void delay(uchar 1)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void key()
{
if(jia_key==0)
{
delay(5);
if(jia_key==0)
{
num++;
if(num==4)num=3;
while(jia_key==0);
}
}
if(jian_key==0)
{
delay(5);
if(jian_key==0)
if(num!=0)
num--;
else
num=0;
while(jian_key==0);
}
}
if(zf_key==0)
{
delay(5);
if(zf_key==0)
{
flag=-flag;
while(zf_key==0);
}
}
}
void qidong()
{
uchar i,j;
switch(num)
{
case 0:PWM=5;break;
case 1:PWM=4;break;
case 2:PWM=3;break;
case 3:PWM=2;break;
}
if(flag==0)
table_begin=0;
else
table_begin=4;
for(i=table_begin;i<4+table_begin;i++)
{
P1=table[i];
for(j=0;j<PWM;j++)
delay(10);
}
}
void main()
{
while(1)
{
key();
qidong();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询