# Learn Embedded Programming [Step by Step]

## Push Button Interfacing with PIC Microcontroller [Step by Step]

Basically computer system works on 0 and 1. Here 0 for GND and 1  for VDD. Consider, we have a resistor which is connected with vdd. So at this stage the resistor gets '1'. Now connect a push button's one end at the point of resistor connected with vdd and another end with ground. In this condition if we press the button , the resistor will achieve 0. It is the main thing.
Now we are going to interface push button with Microcontroller and in this tutorial  I am going to use microcontroller PIC18F2550 .

### Proteus Circuit :

Create a new project  in Proteus and follow the instructions .I am just trying to make easy for every one  .

If  you completed those steps, then pick from library  ' pic18f2550' , crystal, 22pf capacitor, 10kohm resistor,5Kohm variable resistor ,power, ground , push button and LCD display( "LM016L" Model  ) according to the instructions given below .

If you got all parts , you can complete the circuit as given below :

#### [Note : If you don't know how to interface LCD  with microcontroller , please follow this tutorial  ]

In this circuit , we added resistors one end with PORTC and another end added with VDD. Push button's one end connected with PORTC and atother with GND. In this condition pressing the button will make enable 0 state .

Now we need the Source code for this microcontroller .So Create a new Project in MikroC  and follow the instructions :

### MikroC Code :

Source Code :

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

sbit LCD_RS at LATB7_bit;
sbit LCD_EN at LATB6_bit;
sbit LCD_D4 at LATB5_bit;
sbit LCD_D5 at LATB4_bit;
sbit LCD_D6 at LATB3_bit;
sbit LCD_D7 at LATB2_bit;

sbit LCD_RS_Direction at TRISB7_bit;
sbit LCD_EN_Direction at TRISB6_bit;
sbit LCD_D4_Direction at TRISB5_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB3_bit;
sbit LCD_D7_Direction at TRISB2_bit;
// End Lcd module connections

void main(){
TRISC.F0=1;
TRISC.F1=1;
ADCON1=0x0F;              //Disable Analog to Digital Converter
CMCON=7;                    // Disable Comperator

Lcd_Init();                        // Initialize Lcd
while(1){
Lcd_Cmd(_LCD_CLEAR);               // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
Lcd_Out(1,1,"Microcontroller");
Lcd_Out(2,4,"Tutorial");                         // Write text in first row
delay_ms(400);
if(PORTC.F0==0){
Lcd_Cmd(_LCD_CLEAR);               // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
Lcd_Out(1,1,"Button_1");
Lcd_Out(2,4,"PORTC.F0");                         // Write text in first row
delay_ms(400);
}
if(PORTC.F1==0){
Lcd_Cmd(_LCD_CLEAR);               // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
Lcd_Out(1,1,"Button_2");
Lcd_Out(2,4,"PORTC.F1");                         // Write text in first row
delay_ms(400);
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Look at Here :
TRISC.F0=1;
TRISC.F1=1;
Here we selected the RESISTER for PORTC. We are using button that means we are providing input for the Microcontroller. As we like to get input from button, we have to define  TRISC.F0=1. Here 1 for input and 0 for output. If we consider TRISC.F0=0, the RC0 pin of Port C will be initialized as output.

if(PORTC.F0==0)
if(PORTC.F1==0)
Here  PORTC.F0 or RC0 and PORTC.F0 or RC1 pin is always remaining with +5v. If you press  button, the current pass through the button. Because the current will get easy way to meet ground. At this situation the RC port pins will get 0. So when we press button, the RC port pins get 0. As it gets 0, we can  use this in programming logic and we did it.

Now write the source code in C and create .hex file according to the instructions given below :
Now go to Proteus circuit and make a double click on microcontroller to load the .hex file .Please look at the picture given below :

See  result here :

 For Button_1
 For Button_2

### Thank You!

Ain't getting any visitors!

## Tags

: (1) 18F2550 (1) 36KHz (3) and (1) arduino (1) Based (1) battery (1) Bipolar (1) Blinking (1) blinks (1) Bluetooth (1) button (1) circuit (1) clock (1) control (1) Db9 (1) DC Motor (2) digital (2) display (2) DS1307 (1) electronic (1) flash (1) flashing (1) HC-06 (1) home (1) how (1) How to (10) i2c tutorial (1) in (1) indicator (1) interface (8) interfacing (3) Interrupt (3) Introduction (1) IR Receiver (4) key pad (1) keyboard (1) keypad (1) lavel (1) Lcd 16x2 (2) lcd 2x16 (2) led (1) lm35 (2) LPG (1) machine (1) make (1) making (1) matrix (1) max232 (1) meter (2) microchip (4) microchips (3) mikroC (5) musical (1) NEC Protocol (4) pcb (5) PIC (3) pic controller (11) pic proteus (1) Pic Tutorial (12) pic18 (2) pic18f2550 (11) picRFモジュール (1) proteus (6) push (1) push button (1) PWM (1) real (1) Rs 232 (1) Rs232 (1) scroll (1) scrolling (1) Serial Port (1) simulation (2) step by step (7) step bystep (1) text (2) time (1) timer (4) timer0 (4) tone (1) tutorial (2) Unipolar (1) USB (1) usb 1.0 (1) USB HID (1) using (9) voltmeter (1) voting (1) with (2) work (1)

## Live Traffic Feed

Live Traffic Feed
Visitor Tracking