You are on page 1of 37

PRESENTATION

ON

INTRODUCTION TO EMBEDDED
SYSTEM AND
EMBEDDED C

BY :UDIT GUPTA
(1209122092)

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
Example:
microwave oven, AC etc.

Characteristics:

Embedded systems are designed to do some


specific
task, rather than be a general-purpose computer
for
multiple tasks.
Embedded systems are not always standalone
devices.
The program instructions written for embedded
systems are referred to as firmware, and are
stored in read-only memory or Flash memory
chips. They run with limited computer hardware
resources.

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.
Control structures remain the same like
if-statement, for loop, do-while etc.

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 cable
Once programmed, the chip runs the
program in your circuit.

Embedded C
program
Simulation
and
debugging

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

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

28-pin PDIP (Plastic Dual In-line


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

8K Bytes of Flash program memory


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

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

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

1
Ex:
DDRB1= 0xff;1//configured as o/p
PORTB = 0xff; //output high
give delay
PORTB = 0x00;//output low

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 }

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

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)

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 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

Then Click On Next. And Make sure that Create folder


check box is always checked.

Then click on Finish.

Click On Built from the menu bar or press F7.

If there is no error in the code the Build


succeeded without any error.

#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);
}
}

#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
}
}
}

You might also like