You are on page 1of 8

DARSHAN| [ESD] |

ESD Lab [5]


[ROLL N0.:-201501094]
Question [1.a]
ANSWER
int count=0x00;

void ISR_INT0() org 0x002


{
delay_ms(500);
PORTB = PORTB ^ 0x01;
delay_ms(500);
PORTB = PORTB ^ 0x01;
delay_ms(500);
PORTB = PORTB ^ 0x01;
delay_ms(500);
PORTB = PORTB ^ 0x01;
// SREG.B7=1;

// GIFR.B6 = 0;
}
void timer0_ovr() org 0x012
{
TIFR.B0=0;

if(count==10000)
{
PORTA = PORTA ^ 0x01;
count=0;
}
else
count++;

}
void main() {
DDRA = 0xFF;
DDRD = 0x00;
DDRB = 0x01;

PORTA = 0x01;
GICR = 0x40;
MCUCR = 0x03;
TCCR0=0x02;
TCNT0=0X37;
SREG.B7=1;
TIMSK.B0=1;
while(1);

} [Circuit Diagram]

[Explanation of Steps]

STEP.1: connect 0 and GND pins of PORTB, 2 and GND pins of PORTD , 0
and GND pins of PORTA with breadboard.
STEP.2: joint a LEDs, switch and resistors with breadboard.
STEP.3: build the code on ATMEGA board.
STEP.4: run the code.
[Short Description]

There are two LEDS which we want to blow, one LED at 0.25Hz and second at
1Hz but we want LED1 blinking continuously and LED2 blink 2 time when we
press a button(call interrupt). So we simple joint LED1 at PORTB.B0 pin and
LED blinking at 0.25Hz, for 0.25Hz we right a code. For second LED we joint at
PORTA.B0 and wait for interrupt so when switch will press than LED2 will blink.
So we Joint switch with PORTD.B2 (create an interrupt). So we code for this
system. In code we use timer0 for blinking LED1 and for LED2 we use
interrupt0, for interrupt0 we call two registers GICR , MCUCR , interrupt0 is at
PORTD.B2 pin so we declare as input pin and now we press button than blink
a LED2 for 2 times.

Question [2]
ANSWER

int count=0x00;
void ISR_INT0() org 0x002
{
while(PIND.B3==0)
{
if(PORTA==0x08)
{
delay_ms(500);
PORTA = 0x01;
}
else
{
delay_ms(500);
PORTA = PORTA << 1;
}
}
PIND.B2=0;
GIFR.B6=0;
}

void ISR_INT1() org 0x004


{
while(PIND.B2==0)
{
if(PORTA==0x01)
{
delay_ms(500);
PORTA = 0x08;
}
else
{
delay_ms(500);
PORTA = PORTA >> 1;
}
}
PIND.B3=0;
GIFR.B7=0;
}

void main() {
DDRA = 0xFF;
DDRD = 0x00;
DDRB = 0x01;

PORTA = 0x08;
GICR = 1<<INT0 | 1<< INT1;
MCUCR = 0x0F;
SREG.B7=1;
while(1);
}
[Circuit Diagram]

[Explanation of Steps]

STEP.1: connect 0,1,2,3 and GND pins of PORTA, 2,3 and GND pins of
PORTD with breadboard.
STEP.2: joint a LEDs, switch and resistors with breadboard.
STEP.3: build the code on ATMEGA board.
STEP.4: run the code.

[Short Description]

There are four LEDS which we want to blink alternative with delay of 0.5S
and we have two buttons one we call LEFT button and second we call
RIGHT button. When we press button LEFT than LEDS blinking left to right
and when we press RIGHT button than LEDS blinking right to left. So for
that we use two interrupts one call INT0 and second call INT1 witch are at
PORTD.B2 and PORTD.B3 so we declare that ports as inputs. And we joint 4
LEDS at PORTA and PORTA declare as output port. Here we use MCUCR,
GIFR and GICR registers for declare interrupts.
Question [2]
ANSWER

int count=0x00;
void ISR_INT0() org 0x002
{
PORTA = PORTA + 1;
if(PORTA == 16)
{
PORTA = 0x00;
count++;
}

// SREG.B7=1;

GIFR.B6 = 0;
}

void main() {
DDRA = 0xFF;
DDRD = 0x00;
PORTA = 0x00;
GICR = 1<<INT0;
MCUCR = 0x03;
SREG.B7=1;
TIMSK.B0=1;
while(1);

[Circuit Diagram]
[Explanation of Steps]

STEP.1: connect 0,1,2,3 and GND pins of PORTA, 2 and GND pins of PORTD
with breadboard.
STEP.2: joint a LEDs, switch and resistors with breadboard.
STEP.3: build the code on ATMEGA board.
STEP.4: run the code.

[Short Description]

There are four LEDS which we want to display count 0 to 15. So for that we
use one interrupt which increment count when its come. Basically we put
a button when its press that time count increment and 4 LEDS display
that number. So we want 4 LEDS joint with PORTA and we declare PORTA
as output port. For interrupt we declare PORTD.B2 as input port so when
interrupt come count will increment. We use MCUCR, GIFR and GICR for
calling interrupt.

You might also like