LED color guardrail tube program---1 IO port to get it done!

Publisher:Harmonious222Latest update time:2015-07-20 Source: 51heiKeywords:LED Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/*************************************
MCU: STC12C56 Crystal: 12MHZ
*************************************/
#include
#include
#define uchar unsigned char
#define uint  unsigned int

#define RGB_count  20
#define RGB_speed  30

sbit DIN=P1^2;
/*************0 code***********************/
void DIN_bit_0()
{
 flying i;
 DIN=1;
 for(i=1;i>0;i--); //Low speed mode 1+3+4*3+1
 _nop_();
 DIN=0; //1+3+4*7
 for(i=3;i>0;i--); 
}
/*************1 code********************/
void DIN_bit_1()
{
 flying i;
 DIN=1; //1+3+4*7+1
 for(i=3;i>0;i--);
 _nop_();
 DIN=0;
 for(i=1;i>0;i--);   //1+3+4*3
  
}
/*************reset code***********************/
void reset()
{
 uint i;
 DIN=0;
 for(i=250;i>0;i--);   
}
/*************data transmission******************/
void send_dat(uchar dat) //high bit first
{
    flying i;
    for(i=8;i>0;i--)
    {
        if(dat & 0x80)  DIN_bit_1();
            else DIN_bit_0();
        dat <<=1;
    }
}
/***************Delay******************/
void delay(uchar t)
{
 unsigned long j;
    while(t--)   for(j=0;j<1000;j++);
}
/*************Main program******************/
void main()
{
 uchar i,n,num,t;
 while(1)
 {
 /*************R gradually brightens********************/
  for(i=0;i<255;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(i);
    send_dat(0);
    send_dat(0);
   }
   reset();
   delay(1);
  }
  /*************R gradually disappears***********************/
  for(i=255;i>0;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(i);
    send_dat(0);
    send_dat(0);
   }
   reset();
   delay(1);
  }
  /****************G gradually brightens********************/
  for(i=0;i<255;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(0);
    send_dat(i);
    send_dat(0);
   }
   reset();
   delay(1);
  }
  /****************G gradually disappears********************/
  for(i=255;i>0;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(0);
    send_dat(i);
    send_dat(0);
   }
   reset();
   delay(1);
  }
  /****************B gradually brightens********************/
  for(i=0;i<255;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(0);
    send_dat(0);
    send_dat(i);
   }
   reset();
   delay(1);
  }
  /************B gradually disappears********************/
  for(i=255;i>0;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(0);
    send_dat(0);
    send_dat(i);
   }
   reset();
   delay(1);
  }
  /*************RG gradually brightens********************/
  for(i=0;i<255;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(i);
    send_dat(i);
    send_dat(0);
   }
   reset();
   delay(1);
  }
  /*************RG gradually disappears***********************/
  for(i=255;i>0;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(i);
    send_dat(i);
    send_dat(0);
   }
   reset();
   delay(1);
  }
  /*************GB gradually brightens***********************/
  for(i=0;i<255;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(0);
    send_dat(i);
    send_dat(i);
   }
   reset();
   delay(1);
  }
  /*************GB gradually disappears*******************/
  for(i=255;i>0;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(0);
    send_dat(i);
    send_dat(i);
   }
   reset();
   delay(1);
  }
  /*************RB gradually brightens***********************/
  for(i=0;i<255;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(i);
    send_dat(0);
    send_dat(i);
   }
   reset();
   delay(1);
  }
  /*************RB gradually disappears*******************/
  for(i=255;i>0;i++)
  {
   for(n=RGB_count;n>0;n--)
   {
    send_dat(i);
    send_dat(0);
    send_dat(i);
   }
   reset();
   delay(1);
  }
  /*************RGB all destroyed***********************/
  for(num=RGB_count;num>0;num--)
        {
            send_dat(0);
            send_dat(0);
            send_dat(0);
        }
        reset();
  /****************B Marquee Added********************/
  for(i=0;i0;t--)  delay(1);
        }
  /****************B Marquee reduction********************/
        for(i=RGB_count;i>0;i--) 
        {
            for(num=0;num0;t--)  delay(1);
   /*************RGB all destroyed***********************/
   for(num=RGB_count;num>0;num--)
            {
                send_dat(0);
                send_dat(0);
                send_dat(0);
            }
            reset();
  }
  /****************G Marquee added********************/
  for(i=0;i0;t--)  delay(1);
        }
        /****************G Marquee reduction********************/           
        for(i=RGB_count;i>0;i--)
        {
            for(num=0;num0;t--)  delay(1);
   /*************RGB all destroyed***********************/
   for(num=RGB_count;num>0;num--)
            {
                send_dat(0);
                send_dat(0);
                send_dat(0);
            }
            reset();
  }
  /*************R Marquee added***********************/
  for(i=0;i0;t--)  delay(1);
        }
  /*************R Marquee reduction********************/
        for(i=RGB_count;i>0;i--)
        {
            for(num=0;num0;t--)  delay(1);
    /*************RGB all destroyed***********************/
            for(num=RGB_count;num>0;num--)
            {
                send_dat(0);
                send_dat(0);
                send_dat(0);
            }
            reset();
        }
  /*************RG Marquee Added***********************/
  for(i=0;i0;t--)  delay(1);
        }
        /*************RG Marquee Reduction***********************/           
        for(i=RGB_count;i>0;i--)
        {
            for(num=0;num0;t--)  delay(1);
   /*************RGB all destroyed***********************/
   for(num=RGB_count;num>0;num--)
            {
                send_dat(0);
                send_dat(0);
                send_dat(0);
            }
            reset();
  }
  /*************GB Marquee Added***********************/
  for(i=0;i0;t--)  delay(1);
        }
        /*************GB Marquee Reduce********************/           
        for(i=RGB_count;i>0;i--) 
        {
            for(num=0;num0;t--)  delay(1);
   /*************RGB all destroyed***********************/
   for(num=RGB_count;num>0;num--)
            {
                send_dat(0);
                send_dat(0);
                send_dat(0);
            }
            reset();
  }
  /*************RB marquee added*******************/
  for(i=0;i0;t--)  delay(1);
        }
        /*************RB Marquee Reduce***********************/           
        for(i=RGB_count;i>0;i--)
        {
            for(num=0;num0;t--)  delay(1);
   /*************RGB all destroyed***********************/
   for(num=RGB_count;num>0;num--)
            {
                send_dat(0);
                send_dat(0);
                send_dat(0);
            }
            reset();
  }
     /*************RGB marquee added*******************/
  for(i=0;i0;t--)  delay(1);
        }
  /*************RGB marquee reduction***********************/
        for(i=RGB_count;i>0;i--)
        {
            for(num=0;num0;t--)  delay(1);
   /*************RGB all destroyed***********************/
            for(num=RGB_count;num>0;num--)
            {
                send_dat(0);
                send_dat(0);
                send_dat(0);
            }
            reset();
        }  
 }
}
Keywords:LED Reference address:LED color guardrail tube program---1 IO port to get it done!

Previous article:The best LED remote controller---adjust without flickering
Next article:Written for those who are about to get in touch with MCU or those who have just gotten in touch with MCU

Recommended ReadingLatest update time:2024-11-16 20:55

Why should we protect LED?
White LED has many advantages and is increasingly entering people's daily life. Its usage is now very huge. It is a new device with its own characteristics. White LED is a voltage-sensitive device. The current of each LED should not exceed 20mA when it is working. If it exceeds too much, the LED will be easily burne
[Power Management]
Design of a power-efficient LED switch for light intensity regulation
An LED can be used as a photosensor. A previous design idea gave a power-efficient switch that consumed almost no power. However, this structure could not be adjusted to switch according to the required light intensity. The circuit in this design idea can be adjusted to any light intensity threshold level that keeps t
[Analog Electronics]
Design of a power-efficient LED switch for light intensity regulation
Analysis of the characteristics of car LED display
The car-mounted LED display is a product that uses LED technology, GSM/GPRS technology, low temperature technology, anti-static technology, anti-interference technology, and car-mounted electronic technology to display information on mobile cars. It is different from ordinary LED displays installed in fixed places
[Power Management]
LED power supply and its basic driving circuit design
There are three main types of original power sources   for LED power supply : low-voltage batteries, solar cells and AC mains power supply. No matter which original power source is used, it must be converted to meet the working conditions of the LED. This power conversion circuit generally refers to the LED drive cir
[Power Management]
LED power supply and its basic driving circuit design
PIC microcontroller button controls PWM output LED light brightness C language program
#include pic.h //Call the header file. You can go to the PICC software to find the header file of the PIC16F87XA microcontroller. __CONFIG(0x3b31); //Define configuration word, crystal type: XT, enable gate dog, disable low voltage programming //************************************************************************
[Microcontroller]
Application of LED technology on highways
Variable information board and variable speed limit sign As important information release of intelligent transportation system, variable information board and variable speed limit sign are controlled remotely by the computer of monitoring center through communication network, and various graphic information ar
[Power Management]
Analysis of radiation loss during LED use
  Commonly used single chip system RAM test method LED is called the fourth generation lighting source or green light source. It has the characteristics of energy saving, environmental protection, long life and small size. It can be widely used in various indications, displays, decorations, backlight sources, general
[Power Management]
Lumissil Microsystems Launches New LED Driver with Dual Brightness Capability
On October 11, Lumissil Microsystems, a subsidiary of Integrated Silicon Solution, Inc. (ISSI), announced the launch of the new LED driver IS32LT3959 to further expand its automotive exterior lighting solution portfolio. The driver is a single-inductor, multi-topology controller with constant on-time for driving gro
[Automotive Electronics]
Lumissil Microsystems Launches New LED Driver with Dual Brightness Capability
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号