Tuesday, January 19, 2016

Running LED for Lighting using Microcontroller 16F886

Hi Friends, Now we make a Project to blink LED in alternate sequence. In this project the LED blink one by one at PORTB of Microcontroller 16F886. to make this project make circuit given blow.





use all resistance (100-1K) ohm.

PROGRAM CODE in C

unsigned short a,b,x,y,k;                                 //variable initilation
void main()
{
 TRISB=0x00;                                              //make portb as output
 PORTB=0X00;                                                  //clear all output

 while(1)                                                             //inf loop
 {
  for(a=1,b=8;a<=8,b>=1;a=a*2,b=b/2)              //for loop of two variable a,b
  {
   x = a;                                                         //store a in x
   y = b;                                                         //store b in y
   k = x << 4;                                  //mask 4 bit of x and store in k
   k = k | y;                 //applying logic "or" in k,y and store result in k
   PORTB = k;                                           // k as output at port b
   delay_ms(300);                                              //delay of 300 ms
  }
 }
}

OUTPUT of this PROJECT





        ......

An another code for an different lighting

unsigned int i,j;

void main()
{
 TRISB = 0;

 while(1)
 {
  for(i=1;i<=256;i=i*2)
  {
   j = i-1;
   PORTB = j;
   Delay_ms(10);
  }
  for(i=1;i<=256;i=i*2)
  {
   j = 256-i;
   PORTB = j;
   Delay_ms(10);
  }
  for(i=256;i>0;i=i/2)
  {
   j = 256-i;
   PORTB = j;
   Delay_ms(10);
  }
  for(i=256;i>0;i=i/2)
  {
   j = i-1;
   PORTB = j;
   Delay_ms(10);
  }
 }
}