关闭

举报

  • 提交
    首页 > 城乡供需 > 致富项目 > 我有项目 > 正文
    购物车
    0

    姬家寨牌单片机RGB全彩花样流水灯

    姬学瑞     2018-09-06 16:21:22     浏览:2    回复:0    点赞:0
    发帖人:姬学瑞
    级 别
    贡献值
    免费发布 注册会员 点击查看电话号码

    /*********************************************************************************************

    硬件设计:姬学瑞;程序编写:姬学瑞

    程序名:姬家寨牌单片机RGB全彩花样流水灯

    硬件支持:所有的51单片机均可驱动(晶振频率随意)

    元件:5050RGB灯珠8+PNP三极管8+单片机+电阻8个(470R-4.7K均可)+电阻2个(220R左右)+电阻1个(330R左右)

     

    /*********************************************************************************************/

    #include <REG51.h> //单片机头文件

    #include <intrins.h>      //51基本运算(包括_nop_空函数)

      

    sbit BB=P1^0;//blue蓝灯

    sbit RR=P1^1;//red红灯

    sbit GG=P1^2;//green绿灯

    unsigned int N=100;//定义每个灯亮的时间、单位为毫秒、修改此值可改变流动速度

    /*********************************************************************************************

    函数名:毫秒级CPU延时函数

    /*********************************************************************************************/

    void DELAY_MS (unsigned int a){

           unsigned int i;

           while( a-- != 0){

                  for(i = 0; i < 630; i++);

           }

    }

    /*********************************************************************************************/

    /*********************************************************************************************/

    void main (void)

    {    

           unsigned char i;            

        while(1){

    /***************各种颜色灯单个点亮左右流动**************************/

                  RR=0;GG=1;BB=1;//红灯亮

                  for(i=0;i<8;i++){ //低位向高位流动 

                         P3 = ~(1<<i);

                         DELAY_MS(N);

                                }           

                  for(i=0;i<8;i++){//高位向低位流动  

                         P3 = ~(1<<7-i);

                         DELAY_MS(N);

                                }           

                  RR=1;GG=0;BB=1;//绿灯亮

                  for(i=0;i<8;i++){ //低位向高位流动 

                         P3 = ~(1<<i);

                         DELAY_MS(N);

                                }           

                  for(i=0;i<8;i++){//高位向低位流动  

                         P3 = ~(1<<7-i);

                         DELAY_MS(N);

                                }

                  RR=1;GG=1;BB=0;//蓝灯点亮

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<i);

                         DELAY_MS(N);

                                }           

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<7-i);

                         DELAY_MS(N);

                                }

                  RR=0;GG=0;BB=1;//红绿灯亮(黄色光)

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<i);

                         DELAY_MS(N);

                                }           

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<7-i);

                         DELAY_MS(N);

                                }           

                  RR=0;GG=1;BB=0;//红蓝灯亮(粉红光)

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<i);

                         DELAY_MS(N);

                                }           

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<7-i);

                         DELAY_MS(N);

                                }

                  RR=1;GG=0;BB=0;//蓝绿灯亮(青色光)

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<i);

                         DELAY_MS(N);

                                }           

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<7-i);

                         DELAY_MS(N);

                                }

                  RR=0;GG=0;BB=0;//红蓝绿灯亮(白色光)

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<i);

                         DELAY_MS(N);

                                }           

                  for(i=0;i<8;i++){  

                         P3 = ~(1<<7-i);

                         DELAY_MS(N);

                                }                                                            

    /********各种颜色灯逐个点亮左右流动****************************/

                  RR=0;GG=1;BB=1;//红灯亮

                  for(i=0;i<8;i++){  

                         P3 = 0xfe<<i;

                         DELAY_MS(N);

                                }

                  for(i=0;i<8;i++){  

                         P3 = 0x7f>>i;

                         DELAY_MS(N);

                                }

                  RR=1;GG=0;BB=1;//绿灯亮

                  for(i=0;i<8;i++){  

                         P3 = 0xfe<<i;

                         DELAY_MS(N);

                                }

                  for(i=0;i<8;i++){  

                         P3 = 0x7f>>i;

                         DELAY_MS(N);

                                }

                  RR=1;GG=1;BB=0;//蓝灯点亮

                  for(i=0;i<8;i++){  

                         P3 = 0xfe<<i;

                         DELAY_MS(N);

                                }

                  for(i=0;i<8;i++){  

                         P3 = 0x7f>>i;

                         DELAY_MS(N);

                                }

                  RR=0;GG=0;BB=1;//红绿灯亮

                  for(i=0;i<8;i++){  

                         P3 = 0xfe<<i;

                         DELAY_MS(N);

                                }

                  for(i=0;i<8;i++){  

                         P3 = 0x7f>>i;

                         DELAY_MS(N);

                                }

                  RR=0;GG=1;BB=0;//红蓝灯亮

                  for(i=0;i<8;i++){  

                         P3 = 0xfe<<i;

                         DELAY_MS(N);

                                }

                  for(i=0;i<8;i++){   

                         P3 = 0x7f>>i;

                         DELAY_MS(N);

                                }

                  RR=1;GG=0;BB=0;//蓝绿灯亮

                  for(i=0;i<8;i++){  

                         P3 = 0xfe<<i;

                         DELAY_MS(N);

                                }

                  for(i=0;i<8;i++){  

                         P3 = 0x7f>>i;

                         DELAY_MS(N);

                                }

                  RR=0;GG=0;BB=0;//红蓝绿灯亮

                  for(i=0;i<8;i++){  

                         P3 = 0xfe<<i;

                         DELAY_MS(N);

                                }

                  for(i=0;i<8;i++){  

                         P3 = 0x7f>>i;

                         DELAY_MS(N);

                                }

    /********各种颜色灯全部点亮一个熄灭的灯左右流动*************************/

                  RR=0;GG=1;BB=1;//红灯亮

                  for(i=0;i<8;i++){  

                         P3 = 1<<i;

                         DELAY_MS(N);

                                }

                 

                  for(i=0;i<8;i++){  

                         P3 = 0x80>>i;

                         DELAY_MS(N);

                                }

                  RR=1;GG=0;BB=1;//绿灯亮

                  for(i=0;i<8;i++){  

                         P3 = 1<<i;

                         DELAY_MS(N);

                                }

                 

                  for(i=0;i<8;i++){  

                         P3 = 0x80>>i;

                         DELAY_MS(N);

                                }

                  RR=1;GG=1;BB=0;//蓝灯点亮

                  for(i=0;i<8;i++){  

                         P3 = 1<<i;

                         DELAY_MS(N);

                                }

                 

                  for(i=0;i<8;i++){  

                         P3 = 0x80>>i;

                         DELAY_MS(N);

                                }

                  RR=0;GG=0;BB=1;//红绿灯亮

                  for(i=0;i<8;i++){  

                         P3 = 1<<i;

                         DELAY_MS(N);

                                }

                 

                  for(i=0;i<8;i++){  

                         P3 = 0x80>>i;

                         DELAY_MS(N);

                                }

                  RR=0;GG=1;BB=0;//红蓝灯亮

                  for(i=0;i<8;i++){  

                         P3 = 1<<i;

                         DELAY_MS(N);

                                }

                 

                  for(i=0;i<8;i++){  

                         P3 = 0x80>>i;

                         DELAY_MS(N);

                                }                  

                 

                  RR=1;GG=0;BB=0;//蓝绿灯亮

                  for(i=0;i<8;i++){  

                         P3 = 1<<i;

                         DELAY_MS(N);

                                }

                 

                  for(i=0;i<8;i++){  

                         P3 = 0x80>>i;

                         DELAY_MS(N);

                                }

                  RR=0;GG=0;BB=0;//红蓝绿灯亮

                  for(i=0;i<8;i++){  

                         P3 = 1<<i;

                         DELAY_MS(N);

                                }

                 

                  for(i=0;i<8;i++){  

                         P3 = 0x80>>i;

                         DELAY_MS(N);

                                }                                                                                                                                                                                                                                                                              

           }                                 

    }

    /************************************END*********************************************************/

     


    打赏捐赠
    0
    !我要举报这篇文章
    声明 本文由村网通注册会员上传并发布,村网通仅提供信息发布平台。文章仅代表作者个人观点,不代表村网通立场。本文如涉及侵权请及时联系我们,我们将在24小时内予以删除!