You are on page 1of 37

PRESENTATION

ON

INTRODUCTION TO EMBEDDED
SYSTEM AND
EMBEDDED C

BY :UDIT GUPTA
(1209122092)

Embedded system

An Embedded system is combination


of computer hardware and software,
and perhaps additional mechanical or
others parts, designed to perform a
specific task.
An embedded system is a computer
system designed to do one or a few
dedicated and/or specific functions
often with real-time computing
constraints

Continued..
Characteristics:

Embedded systems are designed to


do some specific
task, rather than be a generalpurpose computer for
multiple tasks.
Embedded systems are not always
standalone devices.
The program instructions written for
embedded systems are referred to as

What is embedded c?

Embedded C is nothing but a subset


of C language which is compatible
with certain microcontrollers.
Some features are added using
header files like <avr/io.h>,
<util/delay.h>.
scanf() and printf() are removed as
the inputs are scanned from the
sensors and outputs are given to the
ports.

Development process of
Embedded C projects

Write C programs in AVR Studio


IDE(Integrated Development
Environment)
Compile them into a .hex file using the
AVR-GCC compiler (which integrates
into AVR Studio)
Simulate the target AVR program and
debug the code within AVR Studio
Program the actual chip using the
USBasp device, which is attached to
our target board with a special 6-pin

continued
Editor
Program

Embedded C
program
Simulation
and
debugging

Advantages

It is a mid-level, with high-level features


(such as support for functions and
modules), and low-level features (such as
good access to hardware via pointers)
C is the most common Embedded
language 85%, of embedded applications
are
coded in C.
C , when used correctly is as safe and
robust as any other high level language.
It directly manipulates the hardware and
memory addresses.
It is very efficient, It is popular and well
understood
Good, well proven compilers are available

INTRODUCTION

ATmega8 is a 8-bit microcontroller


based on the AVR RISC architecture
By executing powerful instructions in
a single clock cycle, the ATmega8
achieves throughput approaching 1
MIPS per MHz

FEATURES

High-performance 8 bit
Microcontroller
Up to 16 MIPS Throughput at 16 MHz
32 x 8 General Purpose Working
Registers
Six ADC channels in PDIP package
Internal Calibrated Oscillator

TYPES OF PACKAGES

28-pin PDIP (Plastic Dual In-line


Package)
32-pin TQFP (Thin Quad film Package)

MEMORY SEGMENTS

8K Bytes of Flash program memory


512 Bytes EEPROM (Electrically
Erasable Programmable Read Only
Memory)
1K Byte Internal RAM (Random
Access Memory)

PIN OUT

PORTS
Three ports i.e PortB, PortC, PortD
Three registers associated with every port
DDRx Data Direction Register
PINx Port input
PORTx- Port output

*Note x is subscript and could be either of


B, C, D

DDRx

If DDRx is configured as logic high, the pin


is configured as output pin.
If DDRx is configured as logic low, the pin
is configured as input pin.
DDRx = 0xff; // configuring as o/p
DDRx = 0x00; // configuring as i/p

If PORTx is written logic one when the pin


is configured as an output pin, the port
pin is driven high (one).
If PORTx is written logic zero when the pin
is configured as an output pin, the port
pin is driven low (zero).
DDRx

PORTx

Output

Ex: DDRB = 0xff; //configured as o/p


PORTB = 0xff; //output high
give delay
PORTB = 0x00;//output low

PORTx

PINx

PINx is used to read the data


Ex: Say a sensor is connected to LSB
of Port D.
To read the status of the sensor, we
use PIND
i.e., x=PIND;//x acquires the status
of portD
if(x&0b00000001)
{ sensor is ON }
else
{ sensor is OFF }

ex: Blinking LED


Program:
main()
{
DDRB=0XFF;
while(1)
{
PORTB=0XFF;
_delay_ms(255);
PORTB=0X00;
_delay_ms(255);
}
}

Alternate functions of Port


B.

Alternate Functions of Port


D.

Port B (PB7..PB0)

Port B is an 8-bit bi-directional I/O


port

Can be used either as a input port or


as output port ( direction must be
specified in programming)

REGISTER DESCRIPTION OF I/O PORTS

Port C (PC6..PC0)

Port C is an 7-bit bi-directional I/O


port

Can be used either as a input port or


as output port ( direction must be
specified in programming)

Port D (PD7..PD0)

Port D is an 8-bit bi-directional I/O


port

Can be used either as a input port or


as output port ( direction must be
specified in coding)

Creation of AVR Projects


with AVR studio

Home screen of avr studio

New project window

Naming the projects

Then Click On Next. And Make sure that Create folder


check box is always checked.

Selecting platform & device

Then click on Finish.

Coding window

Building the code

Click On Built from the menu bar or press F7.

Build status

If there is no error in the code the Build


succeeded without any error.

FIRST
PROGRAM
BLINKING
LED

#include<avr/io.h>
#include<util/delay.h>
#define F_CPU 1000000UL
void wait(float x)
{
for(int i=0;i<(int)(x*1302);i++)
_delay_loop_1(0);
}
main()
{
DDRB=0xFF;// PORT B as output port
while(1)
{
PORTB=0b11111111;
wait(.5);
PORTB=0b00000000;
wait(.5);
}
}

LINE
FOLLOWER
ROBOT
CODING

#include <avr/io.h>
// includes input/output header file
#include <util/delay.h> // includes delay header file
int main(void)
{
DDRB=0b11111111; //PORTB as output Port connected to motors
DDRC=0b0000000; //PORTC Input port connected to Sensors
int left_sensor=0, right_sensor=0;
while(1) // infinite loop
{
left_sensor=PINC&0b0000001; // mask PC4 bit of Port C
right_sensor=PINC&0b0000010;// mask PC5 bit of Port C
if((left_sensor==0b0000000) && (right_sensor==0b0000000)) //if both sensors "off"
{ PORTB=0b00000000; // stop}
if((left_sensor==0b0000001) && (right_sensor==0b0000010)) //if both sensors "on"
{
PORTB=0b00010010; // move straight
}
if((left_sensor==0b0000000)&&(right_sensor==0b0000010))
{
PORTB=0b00000010; // turn left
}
if((left_sensor==0b0000001)&&(right_sensor==0b0000000))
{
PORTB=0b00010000; // turn right
}
}
}

THANK YOU

You might also like