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

File (ESD)

Uploaded by

Shubhi Pathak
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

File (ESD)

Uploaded by

Shubhi Pathak
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

EMBEDDED SYSTEM

DESIGN
EAEPC17
PRACTICAL FILE
2024-25
Submitted by: Submitted to:
Name: Aman Singh Dr. C.S. Vinitha
Roll No.: 2022UEA6576
Branch: ECAM
Section: 02

Netaji Subhas University of Technology


Geeta Colony, Delhi - 110031
INDEX

S. No. Topic Date Signature

1 Addition of 10 numbers

2 Transfer of Numbers from One location


to another
3 Blinking of LED Connected at PORTD

4 Blinking of LED Using Embedded C

5 Toggle the Data at PORTB 200 Times

6 Display the Value of z at PORTA

7 Convert Given BCD to ASCII and Display


on Ports
8 Store an ASCII Character in EEPROM

9 Blinking LED with Timer Delay

10 One Second Delay Using Timer1 with


Pre- scaler
11 Timer2 Interrupt with Counter on
PORTB
12 USART Serial Data Transmission
Experiment 1: Addition of Ten Numbers
Aim: To add ten numbers stored in memory and store the result in a specific
register.

Code:

.org 0

.include "m32def.inc"

ldi zl, low (mydata << 1)

ldi zh, high (mydata << 1)

ldi r16, 10

ldi r17, $00

loop: lpm r20, z+

adc r17, r20

dec r16

brne loop

sts 0x0100, r17

mydata: .db $01, $02, $03, $04, $05, $06, $07, $07, $07, $10

Output:

The result of adding these ten values will be stored in the memory location
0x0100.
Experiment 2: Transfer of Numbers from One Location to Another

Aim: To transfer data from one memory location to another.

Code:

.ORG 0
.INCLUDE "M32DEF.INC"
LDI ZH, HIGH(MYDATA<<1)
LDI ZL, LOW(MYDATA<<1)
LDI XH, 0x01
LDI XL, 0x40
L1: LPM R20, Z+
CPI R20, 0
BREQ HERE
ST X+, R20
RJMP L1
HERE: RJMP HERE
MYDATA: .DB "THE WORLD PEACE", 0

Output:

The data will be transferred from the MYDATA location to a new specified
location in memory.
Experiment 3: Blinking of LED Connected at PORTD

Aim: To make an LED blink by outputting data to PORTD.

Code:

.org 0

.include "m32def.inc"
main: ldi r16, high(ramend)
out sph, r16
ldi r16, low(ramend)
out spl, r16
clr r16
ldi r16, 0xff
out ddrd, r16
repeat: out portd, r16
call delay
com r16
out portd, r16
call delay
jmp repeat
delay: ldi r17, 1
loop1: nop
dec r17
brne loop1
Ret

Output:

The LED connected to PORTD will blink with delays controlled by the delay
subroutine.
\

Experiment 4: Blinking of LED Using Embedded C

Aim: To make an LED connected to PORTB blink using C programming.

Code:

#include <avr/io.h>
int main(void)
{
DDRB = 0XFF;
while (1)
{
PORTB = 0X55;
PORTB = 0XAA;
}
return 0;
}

Output:

The LED connected to PORTB will alternate between two states, creating
a blinking effect.
Experiment 5: Toggle the Data at PORTB 200 Times

Aim: To toggle the data output on PORTB 200 times.

Code:

#include <avr/io.h>
int main(void)
{
DDRB = 0XFF;
PORTB = 0XAA;
unsigned char z;
while (1)
for (z = 0; z < 200; z++)
PORTB = ~PORTB;
return 0;
}

Output:

The data at PORTB will toggle 200 times.


Experiment 6: Display the Value of z at PORTA

Aim: To display the variable z value at PORTA.

Code:

#include <avr/io.h>
int main(void)
{
DDRA = 0XFF;
unsigned char z;
while (1)
for (z = 0; z < 200; z++)
PORTA = z;
return 0;
}

Output:

PORTA will display values from 0 to 199 in a loop.


Experiment 7: Convert Given BCD to ASCII and Display on Ports

Aim: To convert a BCD value to ASCII and display it on PORTA and PORTB.

Code:

#include <avr/io.h>
int main(void)
{
DDRB = DDRA = 0XFF;
unsigned char x, y;
unsigned char b = 49;
x = b & 0x0f;
PORTA = x | 0x30;
y = b & 0xf0;
y = y >> 4;
PORTB = y | 0X30;
return 0;
}

Output:

The BCD value 49 will be converted and displayed in ASCII format on PORTA
and PORTB.
Experiment 8: Store an ASCII Character in EEPROM

Aim: To store an ASCII character in a specific EEPROM location.

#include <avr/io.h>
int main(void)

while (EECR &

(1<<EEWE)); EEAR = 0X5F;

EEDR = '6';

EECR = EECR |

(1<<EEMWE); EECR =

EECR | (1<<EEWE);

return 0;

Output:

The ASCII character '6' will be stored at EEPROM address 0x5F.


Experiment 9: Blinking LED with Timer Delay

Aim: To blink an LED connected to PORTB with a custom delay using Timer0 in
normal mode.

Code:

#include <avr/io.h>
void TODelay();
int main(void)
{DDRB = 0XFF;
while (1)
{
PORTB = 0X55;
TODelay();
PORTB = 0XAA;
TODelay();
}
return 0;
}
void TODelay()
{
TCNT0 = 0XFC;
TCCR0 = 0X01;
while ((TIFR & 0x01) == 0);
TCCR0 = 0X00;
TIFR = 0X1;
}

Output:

The LED connected to PORTB will blink with a delay implemented by Timer0 in
normal mode.
Experiment 10: One Second Delay Using Timer1 with Pre-scaler

Aim: To create a one-second delay using Timer1 in normal mode with a pre-scalar
value of 256.

Code:

#include <avr/io.h>
#define F_CPU 8000000UL
void TODelay();
int main(void)
{
DDRB = DDRB | (1 << 4);
while (1)
{
PORTB = PORTB ^ (1 << 4);
TODelay();
}
return 0;
}

void TODelay()
{
TCNT1 = 0X85EE;
TCCR1A = 0X00;
TCCR1B = 0X04;
while ((TIFR & (1 << TOV1)) == 0);
TCCR1B = 0X00;
TIFR = (1 << TOV1);
}

Output:
The LED connected to PORTB toggles every second using a delay controlled by
Timer1 with a pre-scalar.
Experiment 11: Timer2 Interrupt with Counter on PORTB

Aim: To use Timer2 in CTC mode to create a delay and count up on PORTB, toggling
an LED on PORTD.

Code:

#include <avr/io.h>
#define F_CPU 8000000UL
#include <avr/interrupt.h>
int main(void)
{
unsigned char i;
DDRB = 0XFF;
DDRD = DDRD | (1 << 5);
TCNT2 = -16; // Load 240 for 2-microsecond delay
TCCR2 = 0X09; // Basic clock, CTC mode
TIMSK = (1 << OCIE2);
sei();

while (1)
{
for(i = 0; i < 256; i++)
PORTB = i;
}
return 0;
}

ISR(TIMER2_COMP_vect)
{
PORTD = PORTD ^ (1 << 5);
}

Output:

PORTB displays an incrementing counter, and an LED on PORTD toggles each time
the Timer2 interrupt occurs.
Experiment 12: USART Serial Data Transmission
Aim:
To transmit data serially at a baud rate of 9600 bps using USART.

Code:

c
Copy code
#include <avr/io.h>
#define F_CPU 8000000UL
#include <util/delay.h>
void usart_init(void)
{
DDRA = 0XFF;
UCSRB = (1 << TXEN);
UCSRC = UCSRC | (1 << UCSZ1) | (1 << UCSZ0) | (1 << URSEL);
UBRRL = 0X67; // Set baud rate to 9600
}

void usart_send(unsigned char i)


{
while (!(UCSRA & (1 << UDRE)));
_delay_ms(100);
UDR = i;
}

int main(void)
{
unsigned char str[] = "HELLO ALL";
unsigned char i = 0;
usart_init();

while (1)
{
usart_send(str[i++]);
PORTA = UDR;
if (str[i] == 0)
i = 0;
}
return 0;
}

Output:

The string "HELLO ALL" will be transmitted serially at 9600 bps, and each character
will appear on PORTA.

You might also like