File (ESD)
File (ESD)
DESIGN
EAEPC17
PRACTICAL FILE
2024-25
Submitted by: Submitted to:
Name: Aman Singh Dr. C.S. Vinitha
Roll No.: 2022UEA6576
Branch: ECAM
Section: 02
1 Addition of 10 numbers
Code:
.org 0
.include "m32def.inc"
ldi r16, 10
dec r16
brne loop
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
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
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.
\
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
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:
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:
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
#include <avr/io.h>
int main(void)
EEDR = '6';
EECR = EECR |
(1<<EEMWE); EECR =
EECR | (1<<EEWE);
return 0;
Output:
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
}
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.