选择法数组排序显示实验
#include <REG51.H>
#define uchar unsigned char
#define uint unsigned int
sbit KEY_S1=P3^2;
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar code ACT[5]={0xfe,0xfd,0xfb,0xf7,0xef};
uint data a[10]={23,58,123,54,63,589,888,19,333,220};
//-------------------------------------------------------------------
void delay(uint k)
{
uint i,j;
for (i=0;i<k;i++)
{
for (j=0;j<121;j++)
{;}
}
}
//-----------------------------------
void sort(uint array[],uint n)
{
uint i,j,k,t;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(array[j]<array[k])k=j;
}
t=array[k];
array[k]=array;
array=t;
}
}
//-----------------------------------
void dis(uint array[],uint n)
{
uint m,t;
for(m=0;m<n;m++)
{
for(t=0;t<300;t++)
{
P0=SEG7[array[m]%10];
P2=ACT[0];
delay(2);
//-------------------------
P0=SEG7[(array[m]/10)%10];
P2=ACT[1];
delay(2);
//-------------------------
P0=SEG7[array[m]/100];
P2=ACT[2];
delay(2);
//-------------------------
P0=SEG7[m];
P2=ACT[4];
delay(2);
//-------------------------
}
}
}
//============================================
void main(void)
{
while(1)
{
dis(a,10);
while(KEY_S1);
sort(a,10);
dis(a,10);
while(1);
}
} |