两数调换

#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code f[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit wela=P1^1;
sbit dula=P1^0;
sbit jian=P2^4;
void swap(uchar x,uchar y); 
uchar number1,number2;
void delay(uint z)
{
 uint x,y;
 for(x=z;x>0;x--)
  for(y=150;y>0;y--);

void main()
{
 uchar a=3,b=8;
 while(1)
 {
    if(jian==0)
    {
        delay(10);
      if(jian==0)
       {
      swap(a,b);
      dula=1;
   P0=f[number1];
   dula=0;
   P0=0xff;
   wela=1;
   P0=0xfd;
   wela=0;
   delay(5);

   dula=1;
   P0=f[number2];
   dula=0;
   P0=0xff;
   wela=1;
   P0=0xfe;
   wela=0;
   delay(5);
            }
  }
  else
  {
   number1=a;
   number2=b;
      dula=1;
   P0=f[number1];
   dula=0;
   P0=0xff;
   wela=1;
   P0=0xfd;
   wela=0;
   delay(5);

   dula=1;
   P0=f[number2];
   dula=0;
   P0=0xff;
   wela=1;
   P0=0xfe;
   wela=0;
   delay(5);
   }
   }
}
void swap(uchar x,uchar y)
{
 number1=y;
 number2=x;
}

 

你可能感兴趣的:(两数调换)