大神们帮我看看为什么按键的延时不能实现长短按?哪里出现了错误,而且不能保存显示
#include<stc15.h>
#include<intrins.h>
#define uchar unsigned char
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code WeiMa[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar temp[8]={0,1,2,3,4,5,6,7};
sbit key1=P3^2;
void delay(uchar x) //@11.0592MHz
{
uchar i,j;
for(i=x;i>0;i--)
for (j=125;j>0;j--);
}
void Delay500ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 22;
j = 3;
k = 227;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
main()
{
uchar i=0,court=0,j;
P0=0xc0;
P2=0x01;
while(1)
{
if(key1==0)
{
delay(20);
if(key1==0)
{
while(1)
{
delay(20);
court++;
}
if(key1==0&&court<4)
{
i++;
P0=table[i];
switch (i)
{
case 0: P0=table[0]; break;
case 1: P0=table[1]; break;
case 2: P0=table[2]; break;
case 3: P0=table[3]; break;
case 4: P0=table[4]; break;
case 5: P0=table[5]; break;
case 6: P0=table[6]; break;
case 7: P0=table[7]; break;
case 8: P0=table[8]; break;
case 9: P0=table[9]; break;
case 10: P0=table[10]; break;
default: break;
}
}
if(key1==0&&court>=4)
j++ ;
P2=WeiMa[j];
P0=temp[table[i]] ;
}
}
;
}
}
-
-
原理图.pdf
下载积分: 积分 -1 分
60.48 KB, 下载次数: 15, 下载积分: 积分 -1 分
#include<stc15.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code WeiMa[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar temp[8]={0,1,2,3,4,5,6,7};
sbit key1=P3^2;
void delay()
{
uint i=200;
while(i--);
}
void Delay500ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
_nop_();
i = 22;
j = 3;
k = 227;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
bit bit1=0; uchar i;j=0,count=0;
main()
{
P0=0xc0;
P2=0x01;
while(1)
{
if(!key1)
{
delay();
if(!key1)
{
Delay500ms();
if(key1==0)
{
i++;
P0=table[temp[j]];
switch (i)
{
case 0: P0=table[0]; break;
case 1: P0=table[1]; break;
case 2: P0=table[2]; break;
case 3: P0=table[3]; break;
case 4: P0=table[4]; break;
case 5: P0=table[5]; break;
case 6: P0=table[6]; break;
case 7: P0=table[7]; break;
case 8: P0=table[8]; break;
case 9: P0=table[9]; break;
default: break;
} while(!key1);
delay();
temp[j]=table;
if(i==9)
i=0;
}
else
{
i=0; j++;
P2=WeiMa[j];
switch(j) {
case 0: P2= (1 << 0); break; // 打开第0个数码管
case 1: P2 = (1 << 1); break; // 打开第1个数码管
case 2: P2= (1 << 2); break; // 打开第2个数码管
case 3: P2 = (1 << 3); break; // 打开第3个数码管
case 4: P2 = (1 << 4); break; // 打开第4个数码管
case 5: P2 = (1 << 5); break; // 打开第5个数码管
case 6: P2 = (1 << 6); break; // 打开第6个数码管
case 7: P2 = (1 << 7); break; // 打开第7个数码管
}
if(j==8)
{
j=0;
delay();
}
}
}
}
}
}
一周热门 更多>