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 atmega8
// Author: Hack Projects India
// Module description: Operate array of LED's
// ****************************************************
#define F_CPU 8000000UL // Set 8 MHz frequency
#include <avr/io.h> // Including IO header files
#include<util/delay.h> // Including Delay header file
int main(void)
{
DDRB=0x01; // PB0 pin direction set as output
DDRC=0x00; // PC0 direction set as input
while(1)
{
if((PINC&0x01)==0x01)
PORTB=0x01;
else
PORTB=0x00;
}
}
Downloads:
The code was compiled in Atmel Studio 6 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 AVR
- nterfacing DAC with AVR
- Interfacing with UART of AVR controller
- Interfacing SPI communication with AVR
- AVR Displaying Custom Characters on LCD
- AVR Graphical LCD
- RTC interfacing using I2C in AVR
- Interfacing ultrasonic sensor with AVR
- Interfacing GPS Modu with AVR
- Interfacing GSM Module with AVR
- Interfacing PWM in AVR
- Interfacing ADC with AVR
- Scrolling string on LCD using AVR
- Interfacing keypad with AVR
- nterfacing DAC with AVR
- Interfacing with UART of AVR controller
- Interfacing SPI communication with AVR
- AVR Displaying Custom Characters on LCD
- AVR Graphical LCD
- RTC interfacing using I2C in AVR
- Interfacing ultrasonic sensor with AVR
- Interfacing GPS Modu with AVR
- Interfacing GSM Module with AVR
- Interfacing PWM in AVR
- Interfacing ADC with AVR
- Scrolling string on LCD using AVR
No comments:
Post a Comment