www.pudn.com > cycle.rar > cycle.c, change:2007-10-25,size:1243b


#include<reg51.h> 
#define uchar unsigned char 
#define uint unsigned int 
 
uchar rrc(uchar a,n);//循环右移 
uchar rlc(uchar a,n);//循环左移 
uchar rjc(uchar n);  //两端向中间 
uchar rsc(uchar n);  //中间向两端 
 
uchar rrc(uchar a,n)//循环右移 
{ 
  uchar b,c; 
  b=a>>n; 
  c=a<<(8-n); 
  a=b|c; 
  return(a); 
} 
 
uchar rlc(uchar a,n)//循环左移 
{ 
  uchar b,c; 
  b=a<<n; 
  c=a>>(8-n); 
  a=b|c; 
  return(a); 
} 
 
uchar rjc(uchar n) //两端向中间 
{ 
  uchar a,b,c; 
  b=rlc(0xfe,n); 
  b=b&0x0f; 
  c=rrc(0x7f,n); 
  c=c&0xf0; 
  a=b|c; 
  return(a); 
} 
 
uchar rsc(uchar n) //中间向两端 
{ 
  uchar a,b,c; 
  b=rrc(0xf7,n); 
  b=b&0x0f; 
  c=rlc(0xef,n); 
  c=c&0xf0; 
  a=c|b; 
  return(a); 
} 
 
void main() 
{ 
  uchar i,temp; 
  uint j; 
  P1=0xff;                     //共阴极,灭灯处理 
  loop: 
    temp=0x7f;                 //右移 
	for(i=0;i<8;i++) 
	{ 
	   P1=rrc(temp,i); 
	   for(j=0;j<3000;j++); 
	} 
	temp=0xfe;                 //左移 
	for(i=0;i<8;i++) 
	{ 
	   P1=rlc(temp,i); 
	   for(j=0;j<3000;j++); 
	} 
	for(i=0;i<4;i++)           //中间向两端 
	{ 
	   P1=rjc(i); 
	   for(j=0;j<3000;j++); 
	} 
	for(i=0;i<4;i++)           //两端向中间 
	{ 
	   P1=rsc(i); 
	   for(j=0;j<3000;j++); 
	} 
	goto loop; 
}