Monday 23 July 2018

Interface a Switch with ARM Microcontroller (LPC2148)

Aim:

The main aim of this project is how to interface a single switch to atmega8 micro-controller.
10pcs-each-x-12-font-b-models-b-font-Push-button-font-b-switch-b-font

Description:


We are already know about how Switch works and atmega8 micro-controller. Here atmega8 has 3 PORTS. In the programming first you have to set the direction of PORT.
1st step:
The first step is set the direction of PORT. We already know atmega8 micro-controller has 3 PORTS, there are PORTB, PORTC, PORTD.if you select PORTB set the direction of PORTB as DDRB.
if DDRB=0x01 that is PORTB 0th PIN is output and remaining pins are input
if DDRB=0x02 that is PORTB 1st PIN is output and remaining pins are input
if DDRB=0x03 that is PORTB 0th and  1st PINs are output and remaining pins are input.
similarly you have to select which pin is out and which pin is in.
2nd step:
The second step is set the PORT. We already know atmega8 micro-controller has 3 PORTS, there are PORTB, PORTC, PORTD.if you select PORTB set the PORT as PORT
if PORTB=0x01 that is PORTB 0th PIN is high and remaining pins are low
if PORTB=0x02 that is PORTB 1st PIN is high and remaining pins are low
if DDRB=0x03 that is PORTB 0th and  1st PINs are high and remaining pins are low.
similarly you have to select which pin is high and which pin is low.
Here i am selecting PORTC 0th pin as input and PORTB 0th pin as output. Here i am connected switch to PC0 pin and LED is connected to PB0 pin. if switch is pressed then LED is on else LED is off.

Block Diagram

3 switch

Schematic


Code

// ****************************************************
// Project: Interfacing single switch to LPC2148
// Author: Hack Projects India
// Module description: Operate array of LED's
// ****************************************************
#include<lpc214x.h>
int main()
{
 PINSEL0= 0X00000000; 
 PINSEL1= 0X00000000;
 PINSEL2= 0X00000000;
 IO1DIR = 0xffff0000;
 IO0DIR = 0x00000000;
 while(1)
 {
  if((IO0PIN & 0x01)==0x01)
  {
   IO1SET =0xffff0000;
  }
  else
  {
   IO1CLR =0xffff0000;
  }
 }
}


Downloads:

The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.

Further Reading suggestions:

No comments:

Post a Comment