这是我刚刚写的,我也是新手,看到你出题目我就自我练习了下!论坛的大神们看了别笑,多多指点!
P1控制8个共阳极LED!
#include"reg52.h"
#include"intrins.h"
#define uint unsigned int
#define uchar unsigned char
void delay(uint z)
{ uint i,j;
for( i=z; i>0; i--)
for(j=110; j>0; j--);
}
void shuma_1()
{
uchar temp;
uint a;
a=6;
temp=0xfe;
P1=temp;
delay(100);
do
{
temp=_crol_(temp,1);
P1=temp;
delay(100);
}
while(a--);
}
void shuma_2()
{
char temp_1;
uint a_1;
a_1=6;
temp_1=0x7f;
P1=temp_1;
delay(100);
do
{
temp_1=_cror_(temp_1,1);
P1=temp_1;
delay(100);
}
while(a_1--);
}
void main()
{
uint w,m;
w=2;
m=10;
while(w--)
{ shuma_1();
shuma_2();
}
P1=0xff;
delay(500);
while(m--)
{
P1=~P1;
delay(1000);
}
}
|