找回密码
 注册会员
搜索附件  

复件_t1.txt

 

新人菜鸟做的篮球积分(非完整版) 希望老鸟指点下~:
希望老鸟能够帮助我改进~~~我也想从中学习到更多的~~~
谢谢~~~~~
以后还有改进的话~~我会上传的~~
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
void delay(uint z);
void time_init ();
void time_24 ();
void display ();
void fenshu ();
void contr_team();
void jisuan ();
void contr_t ();

uchar conter = 0 ;
uchar temp = 240 ;
uchar wel = 0 ;
uchar fen ;
uchar miao ;
uchar ms ;
uchar startup= 0 ;
uchar t_startup=0 ;


uchar fenshu1= 0 ;
uchar fenshu2= 0 ;
uchar ge1 = 0 ;
uchar shi1 = 0 ;
uchar bai1 = 0 ;
uchar ge2 = 0 ;
uchar shi2 = 0 ;
uchar bai2 = 0 ;
sbit key = P3^0;
sbit key_t = P3^3;
sbit LED = P1^1;
sbit jia1 = P3^1;
sbit jia2 = P3^2;
sbit A_LED = P1^3;
sbit B_LED = P1^4;

uchar code tab []={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67};
//yanshi******************************
void delay(uint z)
{
uint i;
for ( ; z > 0; z--)
{
for ( i = 0;i < 124; i++)
{
;
}
}
}

//time chushihua ****************************
void time_init ()
{
TMOD = 0x11;
EA = 1;
ET0 = 1;
TH0 = ( 65536 - 10000 ) / 256;
TL0 = ( 65536 - 10000 ) % 256;
TR0 = 1;
ET1 = 1;
TH1 = ( 65536 - 2000 ) / 256;
TL1 = ( 65536 - 2000 ) % 256;
TR1 = 1;
}

//T1 zhongduan ********************************
void time_1 () interrupt 3
{
TH1 = ( 65536 - 2000 ) / 256;
TL1 = ( 65536 - 2000 ) % 256;
wel ++ ;
if (wel == 8)
{
wel = 0;
}
display () ;

}

//T0 zhongduan *******************************************
void time_0 () interrupt 1
{
TH0 = ( 655536 - 10000 ) / 256;
TL0 = ( 655536 - 10000 ) % 256;
conter ++ ;
time_24 () ;
}

//dispaly *****************************************
void display ()
{
P2 = wel ;

switch ( wel )
{
case 0: P0 = tab [ fen ]; break;
case 1: P0 = ( tab [ miao] | 0x80 ); break;
case 2: P0 = tab [ ms ]; break;
case 3: P0 = 0x40 ; break;
case 4: P0 = tab [ shi1]; break;
case 5: P0 = tab [ ge1 ]; break;
case 6: P0 = tab [ shi2]; break;
case 7: P0 = tab [ ge2 ]; break;
}
}

//team xuanzhe ***************************************
void contr_team ()
{
uchar contr ;
if ( key_t == 0 )
{
delay (100);
if ( key_t == 0 )
{
contr ++ ;
if ( contr % 2 == 1 )
{
t_startup = 1 ;
temp = 0 ;
}
else
{
t_startup = 0 ;
temp = 0 ;
}
}
}
switch ( t_startup )
{
case 0:A_LED = 1 ; B_LED = 0 ; break;
case 1:A_LED = 0 ; B_LED = 1 ; break;
}
}

// control time **********************************
void contr_t ()
{
uchar start;
if ( key == 0 )
{
delay ( 100 );
if ( key == 0 )
{
start ++ ;
if ( start % 2 == 1)
startup = 0 ;
else
startup = 1 ;
}
}

}
//jishi 24s ******************************************
void time_24 ()
{
fen = temp / 100 ;
miao = (temp % 100) / 10 ;
ms = temp % 10 ;
if ( conter == 10 )
{
conter = 0 ;
if ( temp == 0 )
{
temp = 240 ;
startup = 0 ;
LED = 0 ;
}
if ( startup == 1)
{
LED = 1 ;
temp -- ;
}
}
}
// fenshu ****************************************
void fenshu ()
{
if ( jia1 == 0 )
{
delay (100);
if ( jia1 == 0 && startup == 1 && t_startup == 1 )
{
fenshu1 ++;
temp = 0 ;
}
if ( jia1 == 0 && startup == 1 && t_startup == 0 )
{
fenshu2 ++;
temp = 0 ;
}
}
if ( jia2 == 0 )
{
delay (100);
if ( jia2 == 0 && startup == 1 && t_startup == 1 )
{
fenshu1 = fenshu1 + 2 ;
temp = 0 ;
}
if ( jia2 == 0 && startup == 1 && t_startup == 0 )
{
fenshu2 = fenshu2 + 2 ;
temp = 0 ;
}
}
}
// fenshujisuan************************
void jisuan ()
{
ge1 = fenshu1 % 10 ;
shi1 = (fenshu1 % 100) / 10 ;
bai1 = fenshu1 /100 ;

ge2 = fenshu2 % 10 ;
shi2 = (fenshu2 % 100) / 10 ;
bai2 = fenshu2 /100 ;
}

//main***************************************
void main()
{
time_init ();
while (1)
{
contr_t () ;
contr_team() ;
jisuan () ;
fenshu () ;
}
}




QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-23 22:40 , Processed in 0.038033 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部