Aim:
The main aim of this project is how to interface a single switch to atmega8 micro-controller.
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
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:
You may also like,
- Interfacing keypad with ARM(LPC2148)
- nterfacing DAC with ARM(LPC2148)
- Interfacing with UART of ARM(LPC2148) controller
- Interfacing SPI communication with PIC
- ARM(LPC2148) Displaying Custom Characters on LCD
- RTC interfacing using I2C in ARM(LPC2148)
- Interfacing Graphical LCD with ARM(LPC2148)
- Interfacing ultrasonic sensor with ARM(LPC2148)
- Interfacing GPS Modu with ARM(LPC2148)
- Interfacing GSM Module with ARM(LPC2148)
- Interfacing PWM in ARM(LPC2148)
- Interfacing ADC with ARM(LPC2148)
- Scrolling string on LCD using ARM(LPC2148)
- Interfacing keypad with ARM(LPC2148)
- nterfacing DAC with ARM(LPC2148)
- Interfacing with UART of ARM(LPC2148) controller
- Interfacing SPI communication with PIC
- ARM(LPC2148) Displaying Custom Characters on LCD
- RTC interfacing using I2C in ARM(LPC2148)
- Interfacing Graphical LCD with ARM(LPC2148)
- Interfacing ultrasonic sensor with ARM(LPC2148)
- Interfacing GPS Modu with ARM(LPC2148)
- Interfacing GSM Module with ARM(LPC2148)
- Interfacing PWM in ARM(LPC2148)
- Interfacing ADC with ARM(LPC2148)
- Scrolling string on LCD using ARM(LPC2148)
No comments:
Post a Comment