0% found this document useful (0 votes)
33 views

Tutorial 2 (Push Button)

Make 3xLED turn on when the push button is pressed . Tutorial outcome: 1-You learn how to set the data direction using 'DDRx' . 2-You learn how to set the OUTPUT on Port pins using 'PORTx' . 3-You learn how to Check the INPUT on Port pins using 'PINx' . 4-You learn how to make delay using '_delay_ms()'.

Uploaded by

M.Sadat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Tutorial 2 (Push Button)

Make 3xLED turn on when the push button is pressed . Tutorial outcome: 1-You learn how to set the data direction using 'DDRx' . 2-You learn how to set the OUTPUT on Port pins using 'PORTx' . 3-You learn how to Check the INPUT on Port pins using 'PINx' . 4-You learn how to make delay using '_delay_ms()'.

Uploaded by

M.Sadat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Tutorial No.

: 2
Tutorial Name: Push Button



Content: page
1. Bill of Materials --------------------------------------------------- 3
2. Circuit connection------------------------------------------------- 4
2.1 Proteus components------------------------------------------4
3. Code----------------------------------------------------------------- 5

1-Bill of Materials:
# Name Quantity
1 ATmega16A-pu 40pin 1
2 Crystal Oscillator 8MHz 1
3 Resistance 10K 1
4 Resistance 330 3
5 LED (any color) 3
6 22pF Capacitor 2
7 Push Button 1















2- Circuit Connection:












2.1 Proteus components:
1. ATmega16.
2. Resistance.
3. Capacitor.
4. Crystal.
5. LED.
6. Push Button.



3- Code:

#ifndef F_CPU
#define F_CPU 8000000UL // "set the clock to 8MHz"
#endif


#include <avr/io.h> //io.h is AVR ports Header file
#include <util/delay.h> //delay.h is Delay Function Header file
#include <avr/iom16.h> //iom16.h is atmega16 ports Header file


int main(void)
{
DDRC=0xff; // SET ALL PORTC pins as Output
PORTC=0x00; // Initialize PORTC to zero
DDRB=0x00; // SET ALL PORTB pins as Input
PINB=0x00; // Initialize PORTC to zero


while(1){

if (PINB==0b0000001) //test the pinB0 to control PORTC
// if the input on pinB0 is one(high)

{
PORTC=0xff; // Assign one to portc => portc=0b11111111

_delay_ms(30); //This delay to eliminate the denouncing effect
}

else // else the input on pinB0 is zero(low)

PORTC=0x00; // Assign zero to portc => portc=0b00000000

}
}

You might also like