Featured post

Objectives and content

Monday, 25 April 2016

Blink a LED

Expt-1

1.       Title: Blink a LED using ATMEGA32 at an equal interval

2.      Components required: 
Sl. No.
Category
Item name/value
Quantity
Remarks
1
IC
ATMEGA32
1

2

7805
1

3
Resistor
10K        
1

4

330R
1

5
Capacitor
0.1uf
2

6

22pf
2

7

10uf, 24Volt
1

8
Crystal Oscillator
16MHz
1

9
LED
Green
1

10
Battery
9Volt
1


3.       Procedure:
a.       Assign the clock frequency
b.      Include the header files avr/io.h and util/delay.h
c.       Assign port D0 pin as output port to connect LED
d.      Assign value logic 1 to port D0
e.      Assign delay for few milliseconds
f.        Complement the logic value of port D0 pin
g.       Go to step ‘e’
4.       Code:
  #ifndef F_CPU
  #define F_CPU 16000000UL
  #endif
  #include <avr/io.h>
  #include <util/delay.h>
  int main(void)
  {
  DDRD=0xFF; //PORTD declared as output
  PORTD=0x01;
  while(1)
  {
     _delay_ms(400);
     PORTD^= 1<<PD0;
  }
  return 0;
  }

5.       Blink Simulation:


Expt-2

1.       Title: Blink a LED using push button switch
2.       Components required:
Sl. No.
Category
Item name/value
Quantity
Remarks
1
IC
ATMEGA32
1

2

7805
1

3
Resistor
10K        
1

4

330R
1

5
Capacitor
0.1uf
2

6

22pf
2

7

10uf, 24Volt
1

8
Crystal Oscillator
16MHz
1

9
LED
Green
1

10
Battery
9Volt
1

11
Switch
Pushbutton
1


3.       Procedure:
a.       Assign the clock frequency
b.      Include the header files avr/io.h, compat/deprecated.h and util/delay.h
c.       Assign port D0 pin as output port to connect LED
d.      Assign port B0 pin as input port to connect pushbutton switch
e.      Pull up port B0 to logic 1.
f.        Assign value logic 1 to port D0
g.       If PB0 is logic 1 go to step j
h.      Complement the logic value of port D0 pin
i.         Assign delay for few milliseconds
j.        Go to step ‘g’
4.       Code:
  #ifndef F_CPU
  #define F_CPU 16000000UL
  #endif
  #include<avr/io.h>
  #include<compat/deprecated.h>
  #include<util/delay.h>
  int main(void)
  {
  DDRD=0xFF; //PORTD declared as output
  DDRB=0x00;
  sbi(PINB,0);
  PORTD=0x01;
  while(1)
  {
     if(bit_is_clear(PINB,0))
     {
            _delay_ms(50);
            PORTD^= 1<<PD0;
            _delay_ms(100);
     }
  }
  return 0;
  }

5.       Blink1 Simulation:

Expt-3

1.       Title: Blink a LED using push button switch through interrupt
2.   Components required:
Sl. No.
Category
Item name/value
Quantity
Remarks
1
IC
ATMEGA32
1

2

7805
1

3
Resistor
10K        
1

4

330R
1

5
Capacitor
0.1uf
2

6

22pf
2

7

10uf, 24Volt
1

8
Crystal Oscillator
16MHz
1

9
LED
Green
1

10
Battery
9Volt
1

11
Switch
Pushbutton
1


3.   Procedure:
a.       Assign the clock frequency
b.      Include the header files avr/io.h, util/delay.h and avr/interrupt.h
c.       Assign port D0 pin as output port to connect LED
d.      Assign port D2 pin as input port to receive interrupt through pushbutton switch
e.      Assign value logic 1 to port D0 and D2
f.        Enable INT0 by setting it logic 1 in the register GICR
g.       Setting ISC01 as logic 1 in the register MCUCR the falling edge at INT0 is now ready to generate an interrupt request.
h.      Set the global interrupt
i.         Continue an infinite loop with any or no instruction(s)
j.        write an interrupt function ISR(INT0_vect)
                                                                           i.      Complement the logic value of port D0 pin
                                                                         ii.      Assign delay for few milliseconds

4.   Code:
                                #ifndef F_CPU
                              #define F_CPU 16000000UL
                             #endif
                              #include <avr/io.h>
                              #include <util/delay.h>
                              #include <avr/interrupt.h>
                             ISR(INT0_vect)
                            {
                              _delay_ms(50);
                              PORTD^= 1<<PD0;
                               _delay_ms(50);
                            }
                            int main()
                            {
                            DDRD |= 1<<PD0;
                            DDRD &= 0xFB;
                            _delay_ms(50);
                          PORTD |=(1<<PD0)|(1<<PD2);
                          GICR  |=   ( 1 << INT0 );   // Enable INT0
                          MCUCR |= (1<<ISC01);
                          sei();
                          while(1)
                          {
                             
                           }
                           return 0;
                          }

5.   Blink2 Simulation:

No comments:

Post a Comment