⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 水果分级
💻 C
字号:
#include <at89x51.h>

#define uchar unsigned char
#define uint unsigned int

uchar  r=0;
uchar  t=0;
uchar ge=0;
uchar  shi=0;	
uchar  count=0;
uchar  n=0;
bit  state=0;

sbit  motoA1=P2^0;
sbit  motoA2=P2^1;
sbit  motoB1=P2^2;
sbit  motoB2=P2^3;

const unsigned char LED7Code[]={	0x7E,		// 0
	0x48,		// 1
	0x3D,		// 2
	0x6D,		// 3
	0x4B,		// 4
	0x67,		// 5
	0x77,		// 6
	0x4C,		// 7
	0x7F,		// 8
	0x6F,		// 9
	0x5F,		// A
	0x73,		// B
	0x36,		// C
	0x79,		// D
	0x37,		// E
	0x17		// F
};
void delay(uchar t)// 延时的子程序
{
uchar i;
uint j;
for (i=0;i<t;i++)
for (j=0;j<900;j++);
}  
 
 void initTimer(void)
{
 TMOD=0x1;
 TH0=0x3c;
 TL0=0xb0;
}

void timer0(void) interrupt 1
{
 TH0=0x3c;
 TL0=0xb0;
 //add your code here.
 n++;
 if(n==10)
   {
	    n=0;
		if(count>0)
		count--;
		else 
		{   EA=0;
	     	for(t=0;t<8;t++) 
				{  for(r=0;r<4;r++) 	
					{P1_1=1 ;
					 delay(10);
				 	 P1_1=0 ;
					 delay(10);
					 }
				  delay(20);
				 }
		}
 	}
}

	
void int0(void) interrupt 0
{
 IE0=0;
 count++;
 
    delay(10);
	if(P3_2==0)
	  {	delay(5);
	     if(P3_2==0)
		    {delay(5);
			   if(P3_2==0)
			     {delay(5);
				   if(P3_2==0)		 
					 { delay(5);
					  if(P3_2==0)	
					   {
			           TR0=1;
				       ET0=1;
					   state=1;
					   EX0=0;
						}

					  }
				  }
			 }
	  }
}







void main(void)
{
initTimer();
TR0=0;
ET0=0;

EA=1;
P1_1=0 ;
P2=0;
 
IT0=0;	  //open  it0
EX0=1; 
 
 
 while(1)
     {  ge=count%10	  ;
	    shi=count/10;
	 
	 
	    P2_7=0;				 //disp
		P0=LED7Code[ge];
		delay(1);
		P2_7=1;
		P2_6=0;
		P0=LED7Code[shi];
		delay(1);
		P2_6=1;
	  }	
}
































⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -