单片机测试程序:
- #include<reg52.h> //头文件
- #define uint unsigned int //宏定义
- #define uchar unsigned char //宏定义
- #include<intrins.h> //循环函数的头文件
- uchar code table0[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//从低位往高位灭一个灯流水
- uchar code table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//从高位往低位灭一个灯流水
- uchar code table2[]={0xfe,0xfa,0xf8,0xf0,0xe0,0xa0,0x80,0x00};//从低位到高位逐步全部熄灭
- uchar code table3[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};//从高位到低位逐步全部熄灭
- uchar code table4[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};//从低位到高位逐步全部点亮
- uchar code table5[]={0x80,0xa0,0xe0,0xf0,0xf8,0xfa,0xfe,0xff};//从高位到低位逐步全部点亮
- uchar code table6[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//从低位到高位,亮一个灯移动
- uchar code table7[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//从高位到低位,亮一个灯移动
- uchar code table8[]={0xfc,0xfe,0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00,0x80,0xc0,0xe0,0xf0,0xf1};
- uchar code table9[]={0x03,0x01,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x7f,0x3f,0x1f,0x0f,0x07};
- uchar code table10[]={0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01};
- uchar code table11[]={0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
- uchar code table12[]={0x1f,0x0f,0x07,0x03,0x01,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x7f,0x3f};
- uchar code table13[]={0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00,0x80,0xc0};
- uchar i,b;
- sbit r1=P3^2; //红色上8层片选
- sbit r2=P3^3; //红色下8层片选
- sbit b1=P3^4; //绿色上8层片选
- sbit b2=P3^5; //绿色下8层片选
- sbit g1=P3^6; //蓝色上8层片选
- sbit g2=P3^7; //蓝色下8层片选
- void delay(uint z) //延时函数
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=314;y>0;y--);
- }
- /******************************************/
- void liushui0()//两列红色逆时针转动
- {
- r1=1; //开红色使能
- r2=1; //开红色使能
- P0=0xff;//
- for(i=0;i<8;i++)
- {
- P1=table6[i];
- P2=table6[i];
- delay(30);
- }
- P1=0x00;P2=0x00;
- P0=0x00;
- r1=0; //关红色使能
- r2=0; //关红色使能
- }
- void rr()//红色亮一会儿
- {
- r1=1;
- r2=1;
- P0=0xff;
- P2=0xff;
- P1=0xff;
- delay(100);
- P0=0x00;
- r1=0;
- r2=0;
- P2=0x00;
- P1=0x00;
- }
- /******************************************/
- void liushui1()//两列绿色逆时针转动
- {
- g1=1; //开绿色使能
- g2=1; //开绿色使能
- P0=0xff;//
- for(i=0;i<8;i++)
- {
- P1=table6[i];
- P2=table6[i];
- delay(30);
- }
- P1=0x00;P2=0x00;
- P0=0x00;
- g1=0; //关绿色使能
- g2=0; //关绿色使能
- }
- void gg()//绿色亮一会儿
- {
- g1=1;
- g2=1;
- P0=0xff;
- P2=0xff;
- P1=0xff;
- delay(100);
- P0=0x00;
- g1=0;
- g2=0;
- P2=0x00;
- P1=0x00;
- }
- /******************************************/
- void liushui2()//两列蓝色逆时针转动
- {
- b1=1; //开蓝色使能
- b2=1; //开蓝色使能
- P0=0xff;//
- for(i=0;i<8;i++)
- {
- P1=table6[i];
- P2=table6[i];
- delay(30);
- }
- P1=0x00;P2=0x00;
- P0=0x00;
- b1=0; //关蓝色使能
- b2=0; //关蓝色使能
- }
- void bb()//蓝色亮一会儿
- {
- b1=1;
- b2=1;
- P0=0xff;
- P2=0xff;
- P1=0xff;
- delay(100);
- P0=0x00;
- b1=0;
- b2=0;
- P2=0x00;
- P1=0x00;
- }
- void liushui3()//红色单层向上移动
- {
- P1=0xff;P2=0xff;
- b2=1;
- for(i=0;i<8;i++)
- {
- P0=table7[i];
- delay(30);
- }
- P0=0x00;
- b2=0;
- /********* **********/
- P1=0xff;P2=0xff;
- b1=1;
- for(i=0;i<8;i++)
- {
- P0=table7[i];
- delay(30);
- }
- P0=0x00;
- b1=0;
- }
- /***********************/
- void liushui4()//红、黄、绿、青、蓝、洋红、白、红,向上流动
- {
- uchar a,b,c;//绿、红、蓝
- a=0x8d;
- b=0x38;
- c=0xe1;
- /////////////
- r1=1;P0=b;r1=0;
- r2=1;P0=b;r2=0;
- g1=1;P0=a;g1=0;
- g2=1;P0=a;g2=0;
- b1=1;P0=c;b1=0;
- b2=1;P0=c;b2=0;
- P1=0xff;P2=0xff;
- for(i=0;i<8;i++)
- {
- a=_cror_(a,1);//循环左移
- b=_cror_(b,1);//循环左移
- c=_cror_(c,1);//循环左移
- delay(80);//延时
- r1=1;P0=b;r1=0;
- r2=1;P0=b;r2=0;
- g1=1;P0=a;g1=0;
- g2=1;P0=a;g2=0;
- b1=1;P0=c;b1=0;
- b2=1;P0=c;b2=0;
- }
- P3=0xff;P0=0x00;P3=0x00;
- P1=0x00;P2=0x00;
- }
- /*************************************************/
- void liushui5()//红、黄、绿、青、蓝、洋红、白、红,向下流动
- {
- uchar a,b,c;//绿、红、蓝
- a=0x8d;
- b=0x38;
- c=0xe1;
- /////////////
- r1=1;P0=b;r1=0;
- r2=1;P0=b;r2=0;
- g1=1;P0=a;g1=0;
- g2=1;P0=a;g2=0;
- b1=1;P0=c;b1=0;
- b2=1;P0=c;b2=0;
- P1=0xff;P2=0xff;
- for(i=0;i<8;i++)
- {
- a=_crol_(a,1);//循环左移
- b=_crol_(b,1);//循环左移
- c=_crol_(c,1);//循环左移
- delay(80);//延时
- r1=1;P0=b;r1=0;
- r2=1;P0=b;r2=0;
- g1=1;P0=a;g1=0;
- g2=1;P0=a;g2=0;
- b1=1;P0=c;b1=0;
- b2=1;P0=c;b2=0;
- }
- P3=0xff;P0=0x00;P3=0x00;
- P1=0x00;P2=0x00;
- }
- void liushui6()//白色单层向上
- {
- uchar a,b,c;//绿、红、蓝
- a=0x80;
- b=0x80;
- c=0x80;
- /////////////
- r2=1;P0=b;r2=0;
- g2=1;P0=a;g2=0;
- b2=1;P0=c;b2=0;
- P1=0xff;P2=0xff;
- for(i=0;i<8;i++)
- {
- a=_cror_(a,1);//循环左移
- b=_cror_(b,1);//循环左移
- c=_cror_(c,1);//循环左移
- delay(25);//延时
- r2=1;P0=b;r2=0;
- g2=1;P0=a;g2=0;
- b2=1;P0=c;b2=0;
- }
- P3=0xff;P0=0x00;P3=0x00;
- P1=0x00;P2=0x00;
- /*****************************************/
- r1=1;P0=b;r1=0;
- g1=1;P0=a;g1=0;
- b1=1;P0=c;b1=0;
- P1=0xff;P2=0xff;
- for(i=0;i<8;i++)
- {
- a=_cror_(a,1);//循环左移
- b=_cror_(b,1);//循环左移
- c=_cror_(c,1);//循环左移
- delay(25);//延时
- r1=1;P0=b;r1=0;
- g1=1;P0=a;g1=0;
- b1=1;P0=c;b1=0;
- }
- P3=0xff;P0=0x00;P3=0x00;
- P1=0x00;P2=0x00;
- }
- /****************************************************/
- void liushui7()//白色单层向下
- {
- uchar a,b,c;//绿、红、蓝
- a=0x01;
- b=0x01;
- c=0x01;
- /////////////
- r1=1;P0=b;r1=0;
- g1=1;P0=a;g1=0;
- b1=1;P0=c;b1=0;
- P1=0xff;P2=0xff;
- for(i=0;i<8;i++)
- {
- a=_crol_(a,1);//循环左移
- b=_crol_(b,1);//循环左移
- c=_crol_(c,1);//循环左移
- delay(25);//延时
- r1=1;P0=b;r1=0;
- g1=1;P0=a;g1=0;
- b1=1;P0=c;b1=0;
- }
- P3=0xff;P0=0x00;P3=0x00;
- P1=0x00;P2=0x00;
- /*****************************************/
- r2=1;P0=b;r2=0;
- g2=1;P0=a;g2=0;
- b2=1;P0=c;b2=0;
- P1=0xff;P2=0xff;
- for(i=0;i<8;i++)
- {
- a=_crol_(a,1);//循环左移
- b=_crol_(b,1);//循环左移
- c=_crol_(c,1);//循环左移
- delay(25);//延时
- r2=1;P0=b;r2=0;
- g2=1;P0=a;g2=0;
- b2=1;P0=c;b2=0;
- }
- P3=0xff;P0=0x00;P3=0x00;
- P1=0x00;P2=0x00;
- }
- /********************************************************************/
- void liushui8()//6色向上流动
- {
- P1=0x00;P2=0x00;
- P1=0xff;P2=0xff;
- for(i=0;i<16;i++)
- {
- r2=1;P0=table8[i];r2=0;
- r1=1;P0=table9[i];r1=0;
- P1=0x00;P2=0x00;
- P1=0xff;P2=0xff;
- /******/
- g2=1;P0=table10[i];g2=0;
- g1=1;P0=table11[i];g1=0;
- P1=0x00;P2=0x00;
- P1=0xff;P2=0xff;
- b2=1;P0=table12[i];b2=0;
- b1=1;P0=table13[i];b1=0;
- delay(25);
- }
- P3=0xff;P0=0x00;P3=0x00;
- }
- /***********************************************************************/
- void liushui9()//6色向下流动
- {
- P1=0x00;P2=0x00;
- P1=0xff;P2=0xff;
- for(i=16;i>0;i--)
- {
- r2=1;P0=table8[i];r2=0;
- r1=1;P0=table9[i];r1=0;
- P1=0x00;P2=0x00;
- P1=0xff;P2=0xff;
- /******/
- g2=1;P0=table10[i];g2=0;
- g1=1;P0=table11[i];g1=0;
- P1=0x00;P2=0x00;
- P1=0xff;P2=0xff;
- b2=1;P0=table12[i];b2=0;
- b1=1;P0=table13[i];b1=0;
- delay(25);
- }
- P3=0xff;P0=0x00;P3=0x00;
- }
- /********************************************************************************
- *********************************************************************************
- *********************************************************************************/
- void main()
- {
- r1=1;P0=0x80;r1=0;
- r2=1;P0=0x80;r2=0;
- g1=1;P0=0x00;g1=0;
- g2=1;P0=0x00;g2=0;
- b1=1;P0=0x00;b1=0;
- b2=1;P0=0x00;b2=0;
- P1=0x00;
- P2=0x00;
- /**************************************/
- while(1)
- {
- /* */
- liushui0();//两列红色逆时针转动
- liushui1();//两列绿色逆时针转动
- liushui2();//两列蓝色逆时针转动
- liushui3();//红色单层向上移动
-
- // gg();//绿色亮一会儿
- // rr();//红色亮一会儿
- // bb();//蓝色亮一会儿
- //
- // liushui4();//红、黄、绿、青、蓝、洋红、白、红,向上流动
- // liushui4();//红、黄、绿、青、蓝、洋红、白、红,向上流动
- // liushui4();//红、黄、绿、青、蓝、洋红、白、红,向上流动
- //
- // liushui5();//红、黄、绿、青、蓝、洋红、白、红,向下流动
- // liushui5();//红、黄、绿、青、蓝、洋红、白、红,向下流动
- // liushui5();//红、黄、绿、青、蓝、洋红、白、红,向下流动
- //
- //
- // liushui6();//白色单层向上
- // liushui7();//白色单层向下
- //
- //
- // liushui8();//6色向上流动
- // liushui8();//6色向上流动
- // liushui8();//6色向上流动
- // liushui9();//6色向下流动
- // liushui9();//6色向下流动
- // liushui9();//6色向下流动
- /******************************************/
- }
-
- }
复制代码
|