#include<reg51.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar i; //////i=100///////
uchar a;
unsigned char table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xff};///高到低位P0,P2口/////
unsigned char table2[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0X00};////高到低位P0,P2口////
unsigned char table3[]={0x80,0xc0,0xe0,0xf0,0x00,0x00,0x00,0x00};/////高4位依次點亮每個燈P1口//////
unsigned char table4[]={0x01,0x03,0x07,0x0f,0x00,0x00,0x00,0x00};//////低4位依次點亮每個燈P1口///
unsigned char table5[]={0x81,0xc3,0xe7,0xff};//////高和低位往中間亮P1口/////
unsigned char table6[]={0xfe,0xfc,0xf8,0xf0,0x7ff};
unsigned char table7[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};/////依次高位到低位每個點燈亮/////
unsigned char table8[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};/////依次低位到高位每個點燈亮/////
sbit RR=P3^5;
sbit GG=P3^6;/////P0,P1,P2,輸出低電平時////////
sbit BB=P3^7;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);//////Y=110///////
}
void main()
{
while(1)
{
/////////////////P2,P1,P0,高位往低位逐個循環點亮3次////////
for(a=0;a<=2;a++) ///////循環次數(a<=2),3次///////
{
RR=0;
GG=1; ///////紅色/////
BB=1;
P2=0x01;
for(i=0;i<8;i++)
{
P2=_cror_(P2,1);
P1=0x00;
P0=0x00;
delay(100);
}
RR=1;
GG=0; //////綠色///////
BB=1;
P1=0x01;
for(i=0;i<8;i++)
{
P2=0x00;
P1=_cror_(P1,1);
P0=0x00;
delay(100);
}
RR=1;
GG=1; /////////藍色/////
BB=0;
P0=0x01;
for(i=0;i<8;i++)
{
P2=0x00;
P1=0x00;
P0=_cror_(P0,1);
delay(100);
}
}
/////////////////P0,P1,P2低位到高位逐個點亮/////////
RR=0;
GG=1; //////紅色//////
BB=1;
P0=0x80;
for(i=0;i<8;i++)
{
P0=_crol_(P0,1);
P1=0x00;
P2=0x00;
delay(100);
}
RR=1;
GG=0; //////綠色///////
BB=1;
P1=0x80;
for(i=0;i<8;i++)
{
P0=0x00;
P1=_crol_(P1,1);
P2=0x00;
delay(100);
}
RR=1;
GG=1; //////藍色//////
BB=0;
P2=0x80;
for(i=0;i<8;i++)
{
P0=0x00;
P1=0x00;
P2=_crol_(P2,1);
delay(100);
}
////////////////P2,P1,P0,高位到低位逐個滅,變顏色///////
RR=0;
GG=0; ////////黃色/////////
BB=1;
P2=0xfe;
for(i=0;i<8;i++)
{
P2=_cror_(P2,1);
P1=0xff;
P0=0xff;
delay(200);
}
RR=0;
GG=1; ////////紫色/////////
BB=0;
P1=0xfe;
for(i=0;i<8;i++)
{
P2=0xff;
P1=_cror_(P1,1);
P0=0xff;
delay(200);
}
RR=1;
GG=0; /////天藍色//////
BB=0;
P0=0xfe;
for(i=0;i<8;i++)
{
P2=0xff;
P1=0xff;
P0=_cror_(P0,1);
delay(200);
}
/////////P2,P1,P0,高位到低位依次每個點亮,循環2次/////////////
for(a=0;a<=1;a++)//////循環次數程序(a<=1)循環2次//////
{
RR=0;
GG=1; ////////紫色///////
BB=0;
for(i=0;i<8;i++)
{
P2=table7[i];
P1=0x00;
P0=0x00;
delay(50);
}
for(i=0;i<8;i++)
{
P2=0xff;
P1=table7[i];
P0=0x00;
delay(50);
}
for(i=0;i<8;i++)
{
P2=0xff;
P1=0xff;
P0=table7[i];
delay(50);
}
/////////P0,P1,P2,低位到高位依次每個點亮,循環/////////////
RR=0;
GG=0; ////////白色//////////
BB=0;
for(i=0;i<8;i++)
{
P0=table8[i];
P1=0x00;
P2=0x00;
delay(50);
}
for(i=0;i<8;i++)
{
P0=0xff;
P1=table8[i];
P2=0x00;
delay(50);
}
for(i=0;i<8;i++)
{
P0=0xff;
P1=0xff;
P2=table8[i];
delay(50);
}
}
////////////////兩側往下流,先左后右流//////////
RR=0;
GG=0; /////白色
BB=0;
for(i=0;i<8;i++)
{
P0=table8[i];
P1=0x00;
P2=0x00;
delay(200);
}
for(i=0;i<8;i++)
{
P0=0xff;
P1=table4[i];
P1=0x0f;
delay(200);
}
RR=0;
GG=1; //////紫色
BB=0;
for(i=0;i<8;i++)
{
P2=table7[i];
P1=0x00;
P0=0x00;
delay(200);
}
for(i=0;i<8;i++)
{
P2=0xff;
P1=table3[i];
P1=0xf0;
delay(200);
}
/////////////////兩側循環閃爍4次///////////
for(a=0;a<=3;a++)/////循環4次////
{
RR=1;
GG=0; //////天藍色
BB=0;
for(i=0;i<8;i++)
{
P2=0xff;
P1=0xf0;
P0=0x00;
delay(100);
}
RR=0;
GG=0; //////黃色
BB=1;
for(i=0;i<8;i++)
{
P0=0xff;
P1=0x0f;
P2=0x00;
delay(100);
}
}
RR=0;
GG=0; //////白色
BB=0;
for(i=0;i<8;i++)
{
P0=0xff;
P1=0xff;
P2=0xff;
delay(200);
}
}
} |