at89c51用c语言开发板完成秒表的编程和调试 写的越详细越好 最好把每一步的程序都写出来谢谢各位大虾!

2024-07-04 13:53发布

呵呵,路过,给你贴个时钟的程序,或可以借鉴 #include #define u来自char unsigned char #define uint unsig
1条回答
1楼 · 2024-07-04 14:27.采纳回答
呵呵,路过,给你贴个时钟的程序,或可以借鉴
#include
#define u来自char unsigned char
#define uint unsigned int
sbit ge_wei=P3^7;
sbit shi_wei=P3^6;
sbit bai_wei=P3^5;
sbit qian_wei=P3^4;
sbit wan_wei=P3^3;
sbit shiwan_wei=P3^2;
sbit baiwan_wei=P3^1;
sbit qianwan_wei=P3^0;
sbit K1=P1^0;
sbit K2=P1^1;
sbit K3=P1^2;
sbit K4=P1^3;
sbit K5=P1^6;
uchar t,a,b,c,d,e,f,miao,fenzhong,shiz后以hong;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void delay(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);


}
//void display(uchar ge,s孙低离权hi,bai,qian,wan,shiwan,baiwan,qianwan)
//void di发注喜斯要宗压使法splay(uchar ge,shi,bai,qian,wan,shiwan)
void display()
{

uchar ge,shi,bai,qian,wan,shiwan;
ge = miao % 10;
shi = miao /10;
bai = fenzhong % 10;
qian = fenzhong / 10;
wan = shizhong % 10;
shiwan = shizhong / 10;

P0=table[ge];
ge_wei=1;
delay(5);
ge_wei=0;


P0=table[shi];
shi_wei=1;
delay(5);
shi_wei=0;


P0=table[bai];
bai_wei=1;
delay(5);
bai_wei=0;



P0=table[qian];
qian_wei=1;
delay(5)战济交真造;
qian_wei=0;


P0=table[wan];
wan_wei=1;
delay(5);
wan_wei=0;


P0体欢觉田=table[shiwan];
shiwan_wei=1;
delay(5);
shiwan_wei=0;


/*P0=table[baiwan];
baiwan_wei=1;
delay(5);
baiwan_w林乙ei=0;


P0=table[qianw式程杀味装今抗an];
qianwan_wei=1;
delay(5);
qianwan_wei=0; */

}
void keyscan()
{
if(K1==0)
{
delay(8);
if(K1==0)
{
shizhong++;
while(!K1);
if(shizhong==24)
{
shizhong=0;

}

}
}
if(K2==0)
{
delay(8);
if(K2==0)
{
fenzhong++;
if(fenzhong==61)
{
fenzhong=1;
}
while(!K2);

}

}
if(K3==0)
{
delay(8);
if(K3==0)
{ shizhong--;
while(!K3);
if(shizhong<=0)
{
shizhong=24;

}

}

}
if(K4==0)
{
delay(8);
if(K4==0)
{
fenzhong--;
while(!K4);

if(fenzhong<=0)
{
fenzhong=60;
}

}
}


}
void init()
{

TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
TR0=1;
}
void main()
{
init();
baiwan_wei=0;
qianwan_wei=0;
while(1)
{
display();
keyscan();

}
}


void time0()interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
t++;
if(t==20)
{
t=0;
miao++;
// a=miao%10;
// b=miao/10;
if(miao==59)
{
miao=0;
fenzhong++;
// c=fenzhong%10;
// d=fenzhong/10;
if(fenzhong==61)
{
fenzhong=1;
shizhong++;
// e=shizhong%10;
// f=shizhong/10;
if(shizhong==24)
{
shizhong=0;

}

}
}
}
}

    相关问题

    相关文章