0% found this document useful (0 votes)
225 views142 pages

01 PDF - Introduction - To - Firebird - V - ATmega2560 - Robot

This document discusses input/output ports in the ATmega2560 microcontroller and writing an embedded C program. It begins with an overview of ports, including that ports are junctions for connecting peripherals like sensors and actuators. It describes the 10 8-bit and 1 6-bit ports on the ATmega2560. It discusses how each port has associated DDR, PORT, and PIN registers to configure the pins as inputs or outputs and access their logic levels. Finally, it mentions writing a C program to interface with a buzzer as an example of using ports.
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)
225 views142 pages

01 PDF - Introduction - To - Firebird - V - ATmega2560 - Robot

This document discusses input/output ports in the ATmega2560 microcontroller and writing an embedded C program. It begins with an overview of ports, including that ports are junctions for connecting peripherals like sensors and actuators. It describes the 10 8-bit and 1 6-bit ports on the ATmega2560. It discusses how each port has associated DDR, PORT, and PIN registers to configure the pins as inputs or outputs and access their logic levels. Finally, it mentions writing a C program to interface with a buzzer as an example of using ports.
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/ 142

Outline

Input-Output Ports in ATmega2560


Write Your First Embedded C Program

Basic IO Interfacing on Firebird-V

E-Yantra Team
Embedded Real-Time Systems Lab
Indian Institute of Technology-Bombay

IIT Bombay
August 3, 2012

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 1/18


Outline
Input-Output Ports in ATmega2560
Write Your First Embedded C Program

Agenda for Discussion

1 Input-Output Ports in ATmega2560


Overview of Ports
Acessing Ports
Examples

2 Write Your First Embedded C Program


Buzzer Interfacing
Programming Tools
C-code

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 2/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

What are Ports?

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

What are Ports?

1 Junctions where peripherals devices are connected.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

What are Ports?

1 Junctions where peripherals devices are connected.

2 Peripheral devices can be

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

What are Ports?

1 Junctions where peripherals devices are connected.

2 Peripheral devices can be

1 Input Device

Example: Switch, Sensors, etc...

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

What are Ports?

1 Junctions where peripherals devices are connected.

2 Peripheral devices can be

1 Input Device

Example: Switch, Sensors, etc...

2 output Device

Example: Buzzer,LCD,Motors,LED, etc...

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

PORTS in ATmega 2560

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

PORTS in ATmega 2560

1 ATmega2560 is 100 pin controller

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

PORTS in ATmega 2560

1 ATmega2560 is 100 pin controller

2 86 pins can be used as Input/Output Pins

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

PORTS in ATmega 2560

1 ATmega2560 is 100 pin controller

2 86 pins can be used as Input/Output Pins

3 Pins are grouped together and called as PORT

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

PORTS in ATmega 2560

1 ATmega2560 is 100 pin controller

2 86 pins can be used as Input/Output Pins

3 Pins are grouped together and called as PORT

1 ATmega2560 has Ten 8-bit ports

PORTx; x = A-to-F and H,J,K,L

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

PORTS in ATmega 2560

1 ATmega2560 is 100 pin controller

2 86 pins can be used as Input/Output Pins

3 Pins are grouped together and called as PORT

1 ATmega2560 has Ten 8-bit ports

PORTx; x = A-to-F and H,J,K,L

2 ATmega2560 has One 6-bit port

PORTG

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

PORTS in ATmega 2560

1 ATmega2560 is 100 pin controller

2 86 pins can be used as Input/Output Pins

3 Pins are grouped together and called as PORT

1 ATmega2560 has Ten 8-bit ports

PORTx; x = A-to-F and H,J,K,L

2 ATmega2560 has One 6-bit port

PORTG

4 All Port pins can be configured individually as input/output.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Accessing PORTS

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Accessing PORTS

1 Each Ports has three associated registers with it.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Accessing PORTS

1 Each Ports has three associated registers with it.

1 DDRx x = A-to-H and J,K,L

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Accessing PORTS

1 Each Ports has three associated registers with it.

1 DDRx x = A-to-H and J,K,L

2 PORTx x = A-to-H and J,K,L

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Accessing PORTS

1 Each Ports has three associated registers with it.

1 DDRx x = A-to-H and J,K,L

2 PORTx x = A-to-H and J,K,L

3 PINx x = A-to-H and J,K,L

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding DDRx Register

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding DDRx Register

1 Data Direction Register

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding DDRx Register

1 Data Direction Register

2 Purpose: To set PORT Pins as input or Output

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding DDRx Register

1 Data Direction Register

2 Purpose: To set PORT Pins as input or Output

a. DDRx = 0 : PORTx is defined as INPUT

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding DDRx Register

1 Data Direction Register

2 Purpose: To set PORT Pins as input or Output

a. DDRx = 0 : PORTx is defined as INPUT

b. DDRx = 1 : PORTx is defined as OUTPUT

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding DDRx Register

1 Data Direction Register

2 Purpose: To set PORT Pins as input or Output

a. DDRx = 0 : PORTx is defined as INPUT

b. DDRx = 1 : PORTx is defined as OUTPUT

3 Example: For PortB make lower nibble as input and upper nibble as
output

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding DDRx Register

1 Data Direction Register

2 Purpose: To set PORT Pins as input or Output

a. DDRx = 0 : PORTx is defined as INPUT

b. DDRx = 1 : PORTx is defined as OUTPUT

3 Example: For PortB make lower nibble as input and upper nibble as
output

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding DDRx Register

1 Data Direction Register

2 Purpose: To set PORT Pins as input or Output

a. DDRx = 0 : PORTx is defined as INPUT

b. DDRx = 1 : PORTx is defined as OUTPUT

3 Example: For PortB make lower nibble as input and upper nibble as
output

D7 D6 D5 D4 D3 D2 D1 D0
1 1 1 1 0 0 0 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding DDRx Register

1 Data Direction Register

2 Purpose: To set PORT Pins as input or Output

a. DDRx = 0 : PORTx is defined as INPUT

b. DDRx = 1 : PORTx is defined as OUTPUT

3 Example: For PortB make lower nibble as input and upper nibble as
output

D7 D6 D5 D4 D3 D2 D1 D0
1 1 1 1 0 0 0 0

DDRB = 0xF0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PINx Register

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PINx Register

1 Purpose: To Read data present on PORTx

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PINx Register

1 Purpose: To Read data present on PORTx

2 save value of register in a variable

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PINx Register

1 Purpose: To Read data present on PORTx

2 save value of register in a variable

3 Example:

Read Data from PORTC

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PINx Register

1 Purpose: To Read data present on PORTx

2 save value of register in a variable

3 Example:

Read Data from PORTC

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PINx Register

1 Purpose: To Read data present on PORTx

2 save value of register in a variable

3 Example:

Read Data from PORTC

D7 D6 D5 D4 D3 D2 D1 D0
PORTC =
1 1 1 1 0 0 0 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PINx Register

1 Purpose: To Read data present on PORTx

2 save value of register in a variable

3 Example:

Read Data from PORTC

D7 D6 D5 D4 D3 D2 D1 D0
PORTC =
1 1 1 1 0 0 0 0

x = PINC

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PINx Register

1 Purpose: To Read data present on PORTx

2 save value of register in a variable

3 Example:

Read Data from PORTC

D7 D6 D5 D4 D3 D2 D1 D0
PORTC =
1 1 1 1 0 0 0 0

x = PINC

x=0xF0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register

Case:1 When portx is defined as Output

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register

Case:1 When portx is defined as Output


1 Purpose: Output data present on PORTx pin

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register

Case:1 When portx is defined as Output


1 Purpose: Output data present on PORTx pin

2 Example:

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register

Case:1 When portx is defined as Output


1 Purpose: Output data present on PORTx pin

2 Example:

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register

Case:1 When portx is defined as Output


1 Purpose: Output data present on PORTx pin

2 Example:

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
1 1 1 1 1 1 1 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register

Case:1 When portx is defined as Output


1 Purpose: Output data present on PORTx pin

2 Example:

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
1 1 1 1 1 1 1 1

DDRA = 0xFF

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register

Case:1 When portx is defined as Output


1 Purpose: Output data present on PORTx pin

2 Example:

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
1 1 1 1 1 1 1 1

DDRA = 0xFF

PORTA= 0xFF

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input
1 Purpose: Activate/deactivate pull-up resistor

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input
1 Purpose: Activate/deactivate pull-up resistor

a. PORTx = 1 : Activate Pull-Up

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input
1 Purpose: Activate/deactivate pull-up resistor

a. PORTx = 1 : Activate Pull-Up

b. PORTx = 0 : Deactivate Pull-Up

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input
1 Purpose: Activate/deactivate pull-up resistor

a. PORTx = 1 : Activate Pull-Up

b. PORTx = 0 : Deactivate Pull-Up

2 Example:

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input
1 Purpose: Activate/deactivate pull-up resistor

a. PORTx = 1 : Activate Pull-Up

b. PORTx = 0 : Deactivate Pull-Up

2 Example:

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input
1 Purpose: Activate/deactivate pull-up resistor

a. PORTx = 1 : Activate Pull-Up

b. PORTx = 0 : Deactivate Pull-Up

2 Example:

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input
1 Purpose: Activate/deactivate pull-up resistor

a. PORTx = 1 : Activate Pull-Up

b. PORTx = 0 : Deactivate Pull-Up

2 Example:

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

DDRA = 0x00

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input
1 Purpose: Activate/deactivate pull-up resistor

a. PORTx = 1 : Activate Pull-Up

b. PORTx = 0 : Deactivate Pull-Up

2 Example:

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

DDRA = 0x00

PORTA= 0xFF

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Understanding PORTx Register


case:2 When portx is defined as Input
1 Purpose: Activate/deactivate pull-up resistor

a. PORTx = 1 : Activate Pull-Up

b. PORTx = 0 : Deactivate Pull-Up

2 Example:

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

DDRA = 0x00

PORTA= 0xFF

Pull-Up is activated for Pins of PORTA.


www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/18
Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

DDRD =

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 1 1 1 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 1 1 1 1

DDRD = 0xFF

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 1 1 1 1

DDRD = 0xFF

3 Step 2: Put data on the Port D

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 1 1 1 1

DDRD = 0xFF

3 Step 2: Put data on the Port D

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 1 1 1 1

DDRD = 0xFF

3 Step 2: Put data on the Port D

PORTD =

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 1 1 1 1

DDRD = 0xFF

3 Step 2: Put data on the Port D

D7 D6 D5 D4 D3 D2 D1 D0
PORTD =
1 1 0 1 0 1 0 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples

1 Example 1: Make PORTD as output port and send bit pattern of D5

2 Step 1: Make Port D as Output port

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 1 1 1 1

DDRD = 0xFF

3 Step 2: Put data on the Port D

D7 D6 D5 D4 D3 D2 D1 D0
PORTD =
1 1 0 1 0 1 0 1

PORTD = 0xD5

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

DDRA =

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

DDRA = 0x00

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

DDRA = 0x00

3 Step 2: To activate Pull-up Resistor send data on Port A

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

DDRA = 0x00

3 Step 2: To activate Pull-up Resistor send data on Port A

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

DDRA = 0x00

3 Step 2: To activate Pull-up Resistor send data on Port A

PORTA =

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

DDRA = 0x00

3 Step 2: To activate Pull-up Resistor send data on Port A

D7 D6 D5 D4 D3 D2 D1 D0
PORTA =
1 1 1 1 1 1 1 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)

1 Example 2: Make PORTA input port with pull-up activated on all


pin

2 Step 1: Make Port A as Input port

D7 D6 D5 D4 D3 D2 D1 D0
DDRA =
0 0 0 0 0 0 0 0

DDRA = 0x00

3 Step 2: To activate Pull-up Resistor send data on Port A

D7 D6 D5 D4 D3 D2 D1 D0
PORTA =
1 1 1 1 1 1 1 1

PORTA = 0xFF

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

DDRD =

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

3 Step 2: Put data on Port Ds Pin7 to Pin4 and enable pullup for Pin3 to
Pin0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

3 Step 2: Put data on Port Ds Pin7 to Pin4 and enable pullup for Pin3 to
Pin0

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

3 Step 2: Put data on Port Ds Pin7 to Pin4 and enable pullup for Pin3 to
Pin0

PORTD =

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

3 Step 2: Put data on Port Ds Pin7 to Pin4 and enable pullup for Pin3 to
Pin0

D7 D6 D5 D4 D3 D2 D1 D0
PORTD =
0 0 1 1 1 1 1 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

3 Step 2: Put data on Port Ds Pin7 to Pin4 and enable pullup for Pin3 to
Pin0

D7 D6 D5 D4 D3 D2 D1 D0
PORTD =
0 0 1 1 1 1 1 1

PORTD = 0x3F

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

3 Step 2: Put data on Port Ds Pin7 to Pin4 and enable pullup for Pin3 to
Pin0

D7 D6 D5 D4 D3 D2 D1 D0
PORTD =
0 0 1 1 1 1 1 1

PORTD = 0x3F

4 Step 3: Read the data from Port D

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

3 Step 2: Put data on Port Ds Pin7 to Pin4 and enable pullup for Pin3 to
Pin0

D7 D6 D5 D4 D3 D2 D1 D0
PORTD =
0 0 1 1 1 1 1 1

PORTD = 0x3F

4 Step 3: Read the data from Port D

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

3 Step 2: Put data on Port Ds Pin7 to Pin4 and enable pullup for Pin3 to
Pin0

D7 D6 D5 D4 D3 D2 D1 D0
PORTD =
0 0 1 1 1 1 1 1

PORTD = 0x3F

4 Step 3: Read the data from Port D

x = PIND;

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18


Outline Overview of Ports
Input-Output Ports in ATmega2560 Acessing Ports
Write Your First Embedded C Program Examples

Examples (Cont..)
1 Example 3: Make upper nibble of PORTD as output and lower nibble as
input. Out 3 on upper nibble and read back data using PIND

2 Step 1: Make Port Ds Pin7 to Pin4 as output pins and Pin3 to Pin0 as
input pins

D7 D6 D5 D4 D3 D2 D1 D0
DDRD =
1 1 1 1 0 0 0 0

DDRD = 0xF0

3 Step 2: Put data on Port Ds Pin7 to Pin4 and enable pullup for Pin3 to
Pin0

D7 D6 D5 D4 D3 D2 D1 D0
PORTD =
0 0 1 1 1 1 1 1

PORTD = 0x3F

4 Step 3: Read the data from Port D

x = PIND;

Therefore value of x will be 0x3F


www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/18
Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V


1 Buzzer Connected to PortC pin 3

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V


1 Buzzer Connected to PortC pin 3

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V


1 Buzzer Connected to PortC pin 3

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V


1 Buzzer Connected to PortC pin 3

2 To Turn on buzzer:

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V


1 Buzzer Connected to PortC pin 3

2 To Turn on buzzer:

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V


1 Buzzer Connected to PortC pin 3

2 To Turn on buzzer: send logic HIGH on pin3 of PortC

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V


1 Buzzer Connected to PortC pin 3

2 To Turn on buzzer: send logic HIGH on pin3 of PortC

3 To Turn off buzzer:


www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18
Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V


1 Buzzer Connected to PortC pin 3

2 To Turn on buzzer: send logic HIGH on pin3 of PortC

3 To Turn off buzzer:


www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18
Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Interfacing in Firebird V


1 Buzzer Connected to PortC pin 3

2 To Turn on buzzer: send logic HIGH on pin3 of PortC

3 To Turn off buzzer: send logic LOW on pin3 of PortC


www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/18
Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC=

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

2 To turn ON the buzzer set PC3 output high

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

2 To turn ON the buzzer set PC3 output high

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

2 To turn ON the buzzer set PC3 output high

PORTC =

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

2 To turn ON the buzzer set PC3 output high

PORTC = 0x08; //0000 1000

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

2 To turn ON the buzzer set PC3 output high

PORTC = 0x08; //0000 1000

3 To turn OFF the buzzer set PC3 output low

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

2 To turn ON the buzzer set PC3 output high

PORTC = 0x08; //0000 1000

3 To turn OFF the buzzer set PC3 output low

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

2 To turn ON the buzzer set PC3 output high

PORTC = 0x08; //0000 1000

3 To turn OFF the buzzer set PC3 output low

PORTC =

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

2 To turn ON the buzzer set PC3 output high

PORTC = 0x08; //0000 1000

3 To turn OFF the buzzer set PC3 output low

PORTC = 0x00; //0000 0000

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Buzzer Program

1 Configure PORTC3,pin as output.

DDRC= 0x08; //0000 1000

2 To turn ON the buzzer set PC3 output high

PORTC = 0x08; //0000 1000

3 To turn OFF the buzzer set PC3 output low

PORTC = 0x00; //0000 0000

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

ATMEL STUDIO 6

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

ATMEL STUDIO 6

• Integrated Development Environment (IDE)


• Supports Developing and Debugging of AVR and ARM based
microcontroller application
• Download Link:
www.atmel.com/Microsite/atmel_studio6/default.aspx

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

ATMEL STUDIO 6

• Integrated Development Environment (IDE)


• Supports Developing and Debugging of AVR and ARM based
microcontroller application
• Download Link:
www.atmel.com/Microsite/atmel_studio6/default.aspx

2 Hardware Required

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

ATMEL STUDIO 6

• Integrated Development Environment (IDE)


• Supports Developing and Debugging of AVR and ARM based
microcontroller application
• Download Link:
www.atmel.com/Microsite/atmel_studio6/default.aspx

2 Hardware Required

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

ATMEL STUDIO 6

• Integrated Development Environment (IDE)


• Supports Developing and Debugging of AVR and ARM based
microcontroller application
• Download Link:
www.atmel.com/Microsite/atmel_studio6/default.aspx

2 Hardware Required

• hex file can be loaded into microcontroller using

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

ATMEL STUDIO 6

• Integrated Development Environment (IDE)


• Supports Developing and Debugging of AVR and ARM based
microcontroller application
• Download Link:
www.atmel.com/Microsite/atmel_studio6/default.aspx

2 Hardware Required

• hex file can be loaded into microcontroller using


a. Bootloader

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

ATMEL STUDIO 6

• Integrated Development Environment (IDE)


• Supports Developing and Debugging of AVR and ARM based
microcontroller application
• Download Link:
www.atmel.com/Microsite/atmel_studio6/default.aspx

2 Hardware Required

• hex file can be loaded into microcontroller using


a. Bootloader

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

AVR Programming Tools

1 Software Required.

ATMEL STUDIO 6

• Integrated Development Environment (IDE)


• Supports Developing and Debugging of AVR and ARM based
microcontroller application
• Download Link:
www.atmel.com/Microsite/atmel_studio6/default.aspx

2 Hardware Required

• hex file can be loaded into microcontroller using


a. Bootloader
b. AVR Programmers viz. AVR MKII, AVRDude, Pony-Programmer, etc..

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program


#include

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program


#include
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program


#include
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

Pin Configuration

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program


#include
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

Pin Configuration
void buzzer_pin_config (void)
{
DDRC =
PORTC =
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program


Main-Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program


Main-Program
int main (void)
{
buzzer_pin_config ();
while(1)
{
buzzer_on();
_delay_ms();
buzzer_off();
_delay_ms();
}
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program


Main-Program
int main (void)
{
buzzer_pin_config ();
while(1)
{
buzzer_on();
_delay_ms();
buzzer_off();
_delay_ms();
}
}

Functions

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program


Main-Program
int main (void)
{
buzzer_pin_config ();
while(1)
{
buzzer_on();
_delay_ms();
buzzer_off();
_delay_ms();
}
}

Functions
void buzzer_on (void)
{
PORTC =
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Syntax for C-Program


Main-Program
int main (void)
{
buzzer_pin_config ();
while(1)
{
buzzer_on();
_delay_ms();
buzzer_off();
_delay_ms();
}
}

Functions
void buzzer_on (void)
{
PORTC =
}

void buzzer_off (void)


{
PORTC =
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/18


Outline Buzzer Interfacing
Input-Output Ports in ATmega2560 Programming Tools
Write Your First Embedded C Program C-code

Thank You!
Post your queries on: http://qa.e-yantra.org/

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 18/18

You might also like