高手帮我看下我的程序,是显示秒表的,但是我用按键,在主程序里面的第一个case是想让停下来,第一位一直闪烁的,可是为什么不行啊#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sfr P0M1=0x94;
sfr P0M0=0x93;
sfr P2M1=0x96;
sfr P2M0=0x95;
sfr P1M1=0x92;
sfr P1M0=0x91;uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //0~9数组
uchar buff[4]={0,0,0,0}; //位
uchar code bittab[]={0x01,0x02,0x04,0x08}; //控制位
void dealy(uint); //延时申明
void xs(); //显示申明
uint a,temp1;
uchar fen,miao,haomiao;
uchar key();
void xs() //显示
{
uchar i;
P2=0x00;
for(i=0;i<4;i++)
{
P2=bittab
;
if(i==3) //第三位加点
{ P0=0x7f&table[buff]; }
else P0=table[buff];
dealy(10);
if(i==1) //第?位加点
{ P0=0x7f&table[buff]; }
else P0=table[buff];
dealy(10);
}}void dealy(uint z) //延时
{
uint x,y;
for(x=0;x<124;x++)
for(y=0;y<z;y++);}void et0() interrupt 1 using 2 //中断方式1
{ TH0=(65536-10000)/256; TL0=(65536-10000)%256; //设初值
haomiao++;
if (haomiao>=100)
{haomiao=0; miao++;
if (miao>=60){miao=0;fen++;
} if(fen>=60){fen=0;}
}}
void main()
{
P0M1=0xff;
P0M0=0x00;
P2M1=0xff;
P2M0=0x00;
P1M1=0xff;
P1M0=0x00; //强推挽
P1=0X00;
fen=00;
miao=0;
haomiao=0;
TMOD=0x01; //方式1
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1; // 总开关打开
ET0=1; //定时打开
TR0=1; // while(1)
{
buff[3]=fen%10;
buff[2]=miao/10;
buff[1]=miao%10;
temp1=haomiao%100;
buff[0]=temp1/10;
xs();
switch(key())
{
case 0x06:{EA=0,P0=0xff,dealy(500),P0=0xfe;break; }
case 0x05:EA=0;break;
case 0x03:EA=1;break;
// default:break;
}
}}uchar key()
{
uchar huoqu;
P3|=0x07; if((P3&0x07)==0x07){huoqu=0xff;return(huoqu);}
dealy(5);
P3|=0x07; if((P3&0x07)==0x07){huoqu=0xff;return(huoqu);}
huoqu=P3&0x07; while((P3&0x07)!=0X07)
{
xs();
}
return huoqu}
此帖出自小平头技术问答
一周热门 更多>