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

Tutorial 1 (Blink LED)

Make 3xLED turn on for 100ms and turn off for another 100ms (Blinking). 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 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)
51 views

Tutorial 1 (Blink LED)

Make 3xLED turn on for 100ms and turn off for another 100ms (Blinking). 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 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.

: 1
Tutorial Name: Blink LED



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















2- Circuit Connection:
















2.1 Proteus components:
1. ATmega16.
2. Resistance.
3. Capacitor.
4. Crystal.
5. LED.
6. Dc power (Vcc).


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

while(1) // Endless Loop
{
PORTC=(1<<PC0); // Assign one to pin0 in portc == portc=0b00000001
_delay_ms(100); // Delay this operation for 100ms=.001sec (to control delay time
change value )

PORTC=(0<<PC0); // Assign zero to pin0 in portc == portc=0b00000000
_delay_ms(100);

PORTC=(1<<PC1); // Assign one to pin1 in portc == portc=0b00000010
_delay_ms(100);
PORTC=(0<<PC1); // Assign zero to pin1 in portc == portc=0b00000000
_delay_ms(100);

PORTC=(1<<PC2); // Assign one to pin2 in portc == portc=0b00000100
_delay_ms(100);
PORTC=(0<<PC2); // Assign zero to pin2 in portc == portc=0b00000000
_delay_ms(100);
}
}

You might also like