Wednesday, February 3, 2016

PUSH BUTTON INTERFACING WITH MICROCONTROLLER

Hi Friend's Today we interface a push button with PIC microcontroller 16F886 .




Circuit Diagram of Push Button with Microcontroller

In this circuit we connect a PUSH BUTTON at PORTA.F0 and we connect a LED at RORTB.F0 for indication. in this circuit we connect a 10K Ohm Resistance with PUSH BUTTON for PULL DOWN the Floating input of Microcontroller. 

CODE of mikroC for PIC

PROGRAM 1:-

void main()
{
 ANSEL = 0x00;                                          // all input are Digital
 TRISA.F0 = 1;                                     //make PORTA 0th bit as input
 TRISB.F0 = 0;                                    //make PORTB 0th bit as output

 while(1)                                                        // infinit loop
 {
  if(PORTA.F0 == 1)                                          //chack Push button
  {
   PORTB.F0 = 1;                                        //if pressed than on LED
   Delay_ms(10);                         //delay of 10 ms to stabilize the output
  }
  else
  {
   PORTB.F0 = 0;                               //if not pressed than off the LED
   Delay_ms(10);                         //delay of 10 ms to stablise the output
  }
 }
}

OUTPUT
In this code if we press the PUSH BUTTON than the LED connect at portb.f0 is on but if we realise
the PUSH BUTTON than the led is off.

PROGRAM 2:-

bit LED_STATUS;                            // define bit variable LED_STATUS

sbit LED at RB0_bit;                                      // LED at PORTB.F0

void main()

 ANSEL = 0x00;                             // confingure ansel as digital i/p
 ANSELH = 0x00;                           // confingure anselh as digital i/p
 TRISA = 0x01;                                // SELECT PORTA.F0 bit as input
 TRISB = 0x00;                               // select PORTB.F0 bit as output

 LED_STATUS = 1;                                          // initially LED ON

 while(1)                                                         // inf loop
 {
  if(PORTA.F0 == 1)                                // check input high or not
  {
   LED_STATUS = ~LED_STATUS;                         // invert LED_STATUS bit
   Delay_ms(200);                           // delay of 200ms to stablise i/p
  }
  LED = LED_STATUS;                               // LED output is LED_STATUS
 }
}

output:- Output of this program is initially LED on than we need press Button only one time than LED continues ON or OFF. We press Button again and again to ON or OFF LED. 


Note:- We need to use Pull Down or Pull up Resistance All time. 

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);
  }
 }
}

Saturday, December 26, 2015

PIC MICROCONTROLLER based traffic light control

Hi friends today we make a traffic light control based on PIC 12F675.to make this project we need electronic components given blow.

ELECTRONIC COMPONENTS

1. PIC 12F675 microcontroller 
2. power supply 5V
3.3 Resistance (100 - 1K ohm)
4.3 LEDs (Red,Yallow and Green)
PIC 12F675 based traffic light control circuit diagram

microc code for project

" void main()
{
TRISIO = 0x00;          // pins select as o/p

 while(1)               // infinit loop
 {
 GPIO.F0 = 1;           // active RED LED
 delay_ms(5000);        //for 5sec.
 GPIO.F1 = 1;           // active YELLOW LED
 delay_ms(2000);        //for 2sec.
 GPIO.F2 = 1;           // active GREEN LED
 delay_ms(5000);        //for 5sec.
 }
} "

by using this code the red led active for 5sec. and yellow led for 2sec and green led for 5sec.

Saturday, December 12, 2015

7805 Regulator Based power supply

HI Friends,Now We make a power supply for PIC microcontrollers using 7805 regulator.for making power supply we need some components given blow.




                    1.General purpose PCB.
                    2.Transformer (center tap) 12-0-12.
                    3.2 Diode 1N4007.
                    4.Regulator 7805.
                    5.Capacitor (220uF ,0 . 01 uF )
CIRCUIT DIAGRAM OF POWER SUPPLY

working:- 
The Transformer and rectifier circuit give output 12V DC and than the regulator 7805 ( i/p 7-24V, o/p is 5V) give output 5V. now we can use this circuit as power supply for micontroller.