Exp 1"Sequential LED Blinking using ATmega32 and proteus simulation.
"
30 Multiple Choice Questions (MCQs)
1. What is the clock frequency of the default ATmega32 microcontroller?
o a) 16 MHz
o b) 1 MHz
o c) 8 MHz
o d) 20 MHz
o Answer: b) 1 MHz
2. Which register controls the direction of I/O pins?
o a) PORTx
o b) DDRx
o c) PINx
o d) ADCx
o Answer: b) DDRx
3. What will setting PORTC = 0xFF do?
o a) Make all PORTC pins input
o b) Turn all LEDs OFF
o c) Set all PORTC pins HIGH
o d) Disable all interrupts
o Answer: c) Set all PORTC pins HIGH
4. What function in C is typically used to create delays in AVR programming?
o a) delay()
o b) wait()
o c) _delay_ms()
o d) hold()
o Answer: c) _delay_ms()
5. How many general-purpose I/O pins does ATmega32 have?
o a) 16
o b) 32
o c) 40
o d) 8
o Answer: b) 32
6. In sequential blinking, which operation helps shift LED patterns?
o a) Addition
o b) Multiplication
o c) Bitwise Shift
o d) Division
o Answer: c) Bitwise Shift
7. What is the full form of AVR?
o a) Analog Voltage Regulator
o b) Advanced Virtual RISC
o c) Automatic Voltage Regulator
o d) Atmel Virtual Register
o Answer: b) Advanced Virtual RISC
8. The file extension for Proteus simulation project is:
o a) .hex
o b) .dsn
o c) .c
o d) .ino
o Answer: b) .dsn
9. To upload C code into Proteus, which file format is used?
o a) .exe
o b) .bin
o c) .hex
o d) .cpp
o Answer: c) .hex
10. In Proteus, which component is used to simulate microcontrollers?
o a) Oscilloscope
o b) LED
o c) ATmega32
o d) Resistor
o Answer: c) ATmega32
11. What does PORTC &= ~(1 << i); do?
o a) Set bit i
o b) Toggle bit i
o c) Clear bit i
o d) Invert bit i
o Answer: c) Clear bit i
12. Which header file is needed for AVR functions?
o a) avr32.h
o b) avr/io.h
o c) avr/lib.h
o d) avrgcc.h
o Answer: b) avr/io.h
13. What is the purpose of #define F_CPU 1000000UL?
o a) Set baud rate
o b) Define frequency
o c) Allocate RAM
o d) Reset counter
o Answer: b) Define frequency
14. Which LED connection type is used commonly in sequential LED blinking?
o a) Parallel
o b) Series
o c) Zigzag
o d) SPI
o Answer: a) Parallel
15. _delay_ms(500); provides delay for:
o a) 0.5 second
o b) 1 second
o c) 5 seconds
o d) 50 milliseconds
o Answer: a) 0.5 second
16. Which port is usually used to connect LEDs in ATmega32?
o a) PORTA
o b) PORTC
o c) PORTB
o d) PORTD
o Answer: b) PORTC
17. Bitwise shift left operation << is used to:
o a) Turn off all LEDs
o b) Rotate pattern
o c) Move ON LED to next position
o d) Reset timer
o Answer: c) Move ON LED to next position
18. Which software generates the hex file from C code?
o a) Notepad++
o b) Proteus
o c) AVR-GCC/Atmel Studio
o d) Excel
o Answer: c) AVR-GCC/Atmel Studio
19. What does DDRC = 0xFF configure?
o a) Input pins
o b) Output pins
o c) ADC
o d) UART
o Answer: b) Output pins
20. Which port is typically used for JTAG in ATmega32?
o a) PORTB
o b) PORTC
o c) PORTD
o d) PORTA
o Answer: d) PORTA
21. How many LEDs can be directly connected to PORTC?
o a) 16
o b) 4
o c) 8
o d) 2
o Answer: c) 8
22. What does a pull-down resistor do?
o a) Pulls pin high
o b) Maintains pin low when not driven
o c) Increases voltage
o d) None
o Answer: b) Maintains pin low
23. The HEX file is loaded into:
o a) Power supply
o b) Microcontroller in Proteus
o c) LED pins
o d) Oscillator
o Answer: b) Microcontroller in Proteus
24. Bitwise OR | is used to:
o a) Turn all bits off
o b) Turn specific bit on
o c) Rotate bits
o d) Create error
o Answer: b) Turn specific bit on
25. Which of the following is NOT a correct LED logic level?
o a) 1 = ON
o b) 0 = OFF
o c) 1 = OFF
o d) Depends on circuit
o Answer: c) 1 = OFF
26. In C, how do you declare a delay function?
o a) delay_ms()
o b) wait_ms()
o c) _delay_ms()
o d) hold_ms()
o Answer: c) _delay_ms()
27. A LED needs a resistor to:
o a) Increase brightness
o b) Reduce current
o c) Generate power
o d) Activate delay
o Answer: b) Reduce current
28. Bit shifting is done to:
o a) Multiply by 2
o b) Divide by 2
o c) Shift LED pattern
o d) All of the above
o Answer: d) All of the above
29. When PORTC = 0x01, which LED is ON?
o a) PC7
o b) PC0
o c) PC5
o d) PC2
o Answer: b) PC0
30. Which bit manipulation will turn OFF LED at bit 2?
o a) PORTC |= (1<<2)
o b) PORTC &= ~(1<<2)
o c) PORTC ^= (1<<2)
o d) PORTC = 0x00
o Answer: b) PORTC &= ~(1<<2)
30 Gap Filling Questions
1. The register _______ is used to configure pin direction in AVR.
→ DDRx
2. PORTC = 0x08; turns ON LED connected to pin _______.
→ PC3
3. A microcontroller executes code stored in _______ memory.
→ Flash
4. In C code, we use #define F_CPU _______ before using _delay_ms().
→ 1000000UL
5. The file extension for the hex file is _______.
→ .hex
6. In Proteus, the schematic is saved with extension _______.
→ .dsn
7. The function _delay_ms(1000); delays program for _______ seconds.
→1
8. In AVR, to make a pin HIGH, we write PORTx |= _______;
→ (1<<n)
9. ATmega32 has _______ digital I/O pins.
→ 32
10. The logic level to turn ON LED is usually _______.
→ HIGH
11. Bitwise left shift operator is _______.
→ <<
12. _______ compiler is used for AVR C code.
→ AVR-GCC
13. The main() function is of type _______.
→ int
14. AVR code must include the header __________.
→ avr/io.h
15. The LED series resistor value is typically _______ ohms.
→ 220
16. Port C has _______ pins in ATmega32.
→8
17. Bitwise AND operator is written as _______.
→&
18. The command PORTC = 0x00; turns _______ all LEDs.
→ OFF
19. The microcontroller simulation software used is _______.
→ Proteus
20. The correct fuse bit setting ensures correct _______ frequency.
→ clock
21. To blink LEDs one by one, we use a _______ inside a loop.
→ shift
22. LED stands for _______.
→ Light Emitting Diode
23. PORTC ^= (1<<i); is used to _______ bit i.
→ toggle
24. The command DDRC = 0xFF; makes port C an _______.
→ output
25. When writing AVR C code, int i; declares a _______.
→ variable
26. #include <util/delay.h> is needed for _______ function.
→ delay
27. The LED anode is connected to _______ voltage.
→ positive
28. A _______ is used to compile AVR code.
→ toolchain
29. 0x01 << 3 equals _______ in binary.
→ 00001000
30. The CPU frequency in ATmega32 lab is _______ MHz.
→1
30 Short Questions with Code
1. What is the purpose of DDRC register in ATmega32?
→ To set the direction (input/output) of each pin on Port C.
2. Write a code to blink all 8 LEDs together on PORTC.
c
Copy code
DDRC = 0xFF;
while(1){
PORTC = 0xFF;
_delay_ms(500);
PORTC = 0x00;
_delay_ms(500);
}
3. How many I/O ports are available in ATmega32?
→ Four ports: PORTA, PORTB, PORTC, PORTD.
4. What does _delay_ms(500); do?
→ Delays the program for 500 milliseconds.
5. What header file is used for port access in AVR C?
→ #include <avr/io.h>
6. How to configure all PORTC pins as output?
→ DDRC = 0xFF;
7. Write the hex value to turn ON only PC2.
→ PORTC = 0x04;
8. What is the function of _delay_ms()?
→ Introduces a software delay.
9. Which compiler is used to convert C code to HEX?
→ AVR-GCC
10. Write C code to blink LED at PC0 only.
c
Copy code
DDRC = 0x01;
while(1){
PORTC ^= 0x01;
_delay_ms(1000);
}
11. How to shift the LED ON from PC0 to PC7?
→ Use left shift: PORTC = 1 << i;
12. What is the size of PORTC register?
→ 8 bits
13. What does PORTC &= ~(1<<i); mean?
→ Clears bit i (turn OFF specific LED).
14. How many clock cycles in 1 MHz for 1 second?
→ 1,000,000 cycles
15. What is the full form of MCU?
→ Microcontroller Unit
16. Which function is used to return from main()?
→ return 0;
17. What is a hex file?
→ Machine-level output of compiled C code used in microcontroller simulation.
18. How to initialize variable i for LED loop?
→ int i;
19. How to blink LEDs with increasing delay?
→ Use loop: _delay_ms(100 * i);
20. What is the voltage drop across an LED?
→ Typically 2V
21. What is the function of a resistor with LED?
→ Limits current to prevent LED damage.
22. How to reset PORTC?
→ PORTC = 0x00;
23. Write a loop to blink LEDs one-by-one.
c
Copy code
for(int i=0; i<8; i++){
PORTC = 1 << i;
_delay_ms(500);
}
24. How to toggle a single LED at PC5?
→ PORTC ^= (1 << 5);
25. Name a simulator used for AVR microcontrollers.
→ Proteus
26. What is the purpose of F_CPU macro?
→ Defines CPU frequency for delay calculations.
27. What does PORTC = 0xAA; do?
→ Turns ON alternate LEDs.
28. How to turn ON all LEDs using hex value?
→ PORTC = 0xFF;
29. Why use #include <util/delay.h>?
→ To use delay functions.
30. How does left shifting a bit help in LED pattern?
→ Moves ON LED to the next position (sequential blinking).
Experiment 2 – “ATmega32 Based LED Switching Simulation Using Proteus”
30 MCQs (Mixed Concept + Code-Based)
1. What is the role of DDRx register in LED control?
o a) Delay generation
o b) Setting pin direction
o c) Port value storage
o d) Timer configuration
o Ans: b) Setting pin direction
2. What is the correct code to turn ON LED connected at PC3?
o a) PORTC |= (1<<PC3);
o b) PORTC &= ~(1<<PC3);
o c) PORTC = 0x00;
o d) DDRC &= ~(1<<PC3);
o Ans: a) PORTC |= (1<<PC3);
3. In ATmega32, input from switches is usually read using:
o a) DDRx
o b) PINx
o c) PORTx
o d) ADCx
o Ans: b) PINx
4. If DDRB = 0x00 and PINB = 0x01, what does it mean?
o a) All pins are input, PB0 is HIGH
o b) All pins are output, PB0 is ON
o c) PB0 is OFF
o d) PB0 is floating
o Ans: a) All pins are input, PB0 is HIGH
5. To turn OFF LED at PC5, use:
o a) PORTC |= (1<<PC5);
o b) PORTC &= ~(1<<PC5);
o c) PORTC ^= (1<<PC5);
o d) DDRC = 0x00;
o Ans: b) PORTC &= ~(1<<PC5);
6. What logic level is used to detect button press (with pull-down)?
o a) 0
o b) 1
o c) floating
o d) depends on delay
o Ans: b) 1
7. Which pin is used to read logic value from the button?
o a) PORTx
o b) PINx
o c) DDRx
o d) ADCx
o Ans: b) PINx
8. What is the default state of ATmega32 I/O pins?
o a) Input
o b) Output
o c) Pull-up
o d) High impedance
o Ans: a) Input
9. What value of DDRC sets all Port C pins as output?
o a) 0xFF
o b) 0x00
o c) 0xAA
o d) 0x55
o Ans: a) 0xFF
10. What is the HEX equivalent of binary 00010000?
o a) 0x10
o b) 0x20
o c) 0x08
o d) 0x04
o Ans: a) 0x10
11. Which C function is needed to create delay?
o a) delay()
o b) _delay_ms()
o c) sleep()
o d) time_delay()
o Ans: b) _delay_ms()
12. What header file is required for delay?
o a) <stdio.h>
o b) <util/delay.h>
o c) <math.h>
o d) <delay.h>
o Ans: b) <util/delay.h>
13. How to set PB2 as input pin?
o a) DDRB &= ~(1<<PB2);
o b) PORTB |= (1<<PB2);
o c) DDRB |= (1<<PB2);
o d) PINB &= ~(1<<PB2);
o Ans: a) DDRB &= ~(1<<PB2);
14. Button press is usually detected as:
o a) Logic 0
o b) Logic 1
o c) High impedance
o d) Analog input
o Ans: b) Logic 1
15. Which one is true for pull-up resistor?
o a) Connects to GND
o b) Maintains LOW state
o c) Maintains HIGH when open
o d) Prevents input
o Ans: c) Maintains HIGH when open
16. What does PORTC ^= (1<<PC0); do?
o a) Turns PC0 ON
o b) Turns PC0 OFF
o c) Toggles PC0
o d) Disables PC0
o Ans: c) Toggles PC0
17. Proteus LED has 2 pins: anode and _______.
o a) drain
o b) source
o c) cathode
o d) gate
o Ans: c) cathode
18. What is the role of resistor with LED?
o a) Delay
o b) Voltage source
o c) Limit current
o d) None
o Ans: c) Limit current
19. What is the logic level of pressed switch with pull-down resistor?
o a) 0
o b) 1
o Ans: b) 1
20. If PINB & (1<<PB0) is true, it means:
o a) Switch at PB0 is pressed
o b) LED is ON
o c) Port is writing
o d) Overflow occurred
o Ans: a) Switch at PB0 is pressed
21. Code to set PB1 and PB2 as output:
o a) DDRB |= (1<<PB1)|(1<<PB2);
o b) PORTB |= (1<<PB1);
o c) PINB |= (1<<PB2);
o d) PORTB &= ~(1<<PB2);
o Ans: a) DDRB |= (1<<PB1)|(1<<PB2);
22. If LED glows only when switch is pressed, this is called:
o a) Latching
o b) Conditional control
o c) Timer mode
o d) Inversion
o Ans: b) Conditional control
23. What happens if no resistor is used with LED?
o a) LED glows faster
o b) No change
o c) LED may burn
o d) LED blinks
o Ans: c) LED may burn
24. What is the voltage drop of red LED?
o a) 5V
o b) 2V
o c) 3.3V
o d) 1V
o Ans: b) 2V
25. Code to check if switch at PB0 is pressed:
c
Copy code
if (PINB & (1<<PB0)) { ... }
o Ans: True
26. Delay for 1 second in C:
o a) _delay_ms(1000);
o Ans: True
27. PORT register is used to:
o a) Set pin direction
o b) Read input
o c) Write output logic
o d) Generate interrupts
o Ans: c) Write output logic
28. In Proteus, we load code using:
o a) .ino
o b) .bin
o c) .hex
o d) .c
o Ans: c) .hex
29. ATmega32 has how many ports?
o a) 3
o b) 4
o c) 6
o d) 8
o Ans: b) 4
30. PORTC = 0x00; means:
o a) All LEDs ON
o b) All LEDs OFF
o c) Some ON
o d) None
o Ans: b) All LEDs OFF
30 Gap Fillings (Code + Concept)
1. To configure Port C as output: DDRC = _______; → 0xFF
2. To detect switch input: use PINB & (1<<____); → PB0
3. Output LED logic is written using _______ register. → PORTx
4. To turn OFF PC2: PORTC &= ~(1<<____); → PC2
5. Pull-up keeps the logic level at _______ when switch is open. → HIGH
6. To delay 500 ms: _______(500); → _delay_ms
7. #define F_CPU _______UL → 1000000
8. LEDs should always be connected with a _______. → resistor
9. Input pins are read through _______ register. → PINx
10. DDRB &= ~(1<<PB1); sets PB1 as _______. → input
11. Switch simulation uses _______ component in Proteus. → button
12. The output code file used in Proteus is _______ format. → hex
13. Bitwise OR operator in C is written as _______. → |
14. DDRC = 0xFF; makes all pins _______. → output
15. _delay_ms(1000); creates _______ delay. → 1 second
16. Bit toggle: PORTC ^= (1<<____); → PC1
17. ATmega32 has _______ I/O pins. → 32
18. High logic level is represented by _______. → 1
19. Switch press detection: if(PINB & (1<<____)) → PB0
20. Button usually connected with _______ resistor. → pull-down
21. C function main must return _______. → 0
22. LED cathode should be connected to _______. → GND
23. PINB is a _______ register. → read-only
24. Code to initialize input: DDRB = _______; → 0x00
25. _delay_ms() is defined in _______ header. → util/delay.h
26. Toggling logic is used to _______ LED. → blink
27. To check bit 3 of PINB: PINB & (1<<____) → 3
28. Simulation software used is _______. → Proteus
29. Microcontroller used: _______. → ATmega32
30. Logic HIGH = _______ volts. → 5
30 Short Questions (Concept + Code)
1. Write code to blink LED at PC0 every 1 second.
c
Copy code
DDRC |= (1<<PC0);
while(1){
PORTC ^= (1<<PC0);
_delay_ms(1000);
}
2. How do you configure PB0 as input?
→ DDRB &= ~(1<<PB0);
3. What is the function of PINx register?
→ Used to read input values from port pins.
4. How do you detect switch press on PB1?
→ if (PINB & (1<<PB1)) { ... }
5. How to write LED ON at PC3?
→ PORTC |= (1<<PC3);
6. Why use resistor with LED?
→ To limit current and prevent LED damage.
7. What happens when PORTC = 0xFF?
→ All 8 LEDs on PORTC are ON.
8. How many bits in DDRx register?
→ 8 bits
9. Write code to toggle LED at PC2.
c
Copy code
PORTC ^= (1<<PC2);
10. Why is pull-down resistor important?
→ To prevent floating state and ensure logic LOW.
11. Write full LED switch code:
c
Copy code
DDRB &= ~(1<<PB0); // input
DDRC |= (1<<PC0); // output
while(1){
if(PINB & (1<<PB0)) PORTC |= (1<<PC0);
else PORTC &= ~(1<<PC0);
}
12. Which header includes delay functions?
→ <util/delay.h>
13. What is the default logic level of open switch with pull-down?
→ LOW (0)
14. What value will turn OFF all LEDs at PORTC?
→ PORTC = 0x00;
15. Which operator is used for bit masking?
→&
16. What does PORTC ^= 0xFF; do?
→ Toggles all bits of PORTC
17. Write code to blink two LEDs on PC0 and PC1.
c
Copy code
PORTC ^= (1<<PC0) | (1<<PC1);
_delay_ms(500);
18. Why use #define F_CPU in AVR code?
→ To define clock speed for correct delay
19. How to keep LED OFF on startup?
→ PORTC = 0x00;
20. What does OR operation do in LED code?
→ Turns ON selected bits without affecting others
21. How do you simulate pushbutton in Proteus?
→ Use SPST switch or push button component
22. Write loop to blink all LEDs one by one.
c
Copy code
for(int i=0; i<8; i++){
PORTC = (1<<i);
_delay_ms(300);
}
23. What logic level is used for OFF in Proteus LED?
→ 0 (LOW)
24. How many ports can be used for LED control in ATmega32?
→ 4 (PORTA to PORTD)
25. Write code to turn ON all odd LEDs.
→ PORTC = 0xAA;
26. How to turn off LED at PC1 only?
→ PORTC &= ~(1<<PC1);
27. Write if-else to check switch and control LED.
c
Copy code
if(PINB & (1<<PB0)) PORTC |= (1<<PC0);
else PORTC &= ~(1<<PC0);
28. What is the typical resistor value for LED protection?
→ 220Ω
29. What file type do we upload in Proteus?
→ .hex file
30. How many I/O pins are in each port of ATmega32?
→ 8 pins
Experiment 3 – “4-bit Binary Up-Down Counter using ATmega32 with Proteus
Simulation”
30 MCQs (Mixed: Concept + Code)
1. A 4-bit binary counter counts from:
o a) 0 to 8
o b) 0 to 15
o c) 0 to 255
o d) 0 to 31
o Ans: b) 0 to 15
2. To increment a counter variable count, we use:
o a) count++
o b) ++count
o c) count = count + 1
o d) All of these
o Ans: d) All of these
3. The register PORTC is used for:
o a) Delay
o b) Input
o c) Output display
o d) ADC
o Ans: c) Output display
4. How many LEDs are required for a 4-bit binary display?
o a) 2
o b) 4
o c) 8
o d) 16
o Ans: b) 4
5. Which C operator checks if button is pressed?
o a) =
o b) &
o c) ||
o d) %
o Ans: b) &
6. The command PORTC = count; shows:
o a) Character value
o b) Decimal value
o c) Binary representation on LEDs
o d) Voltage
o Ans: c) Binary representation on LEDs
7. The max decimal value a 4-bit counter can show is:
o a) 10
o b) 15
o c) 16
o d) 32
o Ans: b) 15
8. A button press can be read using:
o a) DDRx
o b) PORTx
o c) PINx
o d) EEPROM
o Ans: c) PINx
9. To count down, the variable should:
o a) count++
o b) count--
o c) count = 0
o d) count |= 1
o Ans: b) count--
10. What is the binary of decimal 9?
o a) 1000
o b) 1001
o c) 1010
o d) 1111
o Ans: b) 1001
11. What is the purpose of _delay_ms(300);?
o a) Debounce
o b) Delay display
o c) Slow down update
o d) All of the above
o Ans: d) All of the above
12. Bit 0 of PORTC is represented by:
o a) PC3
o b) PC0
o c) PC7
o d) PD0
o Ans: b) PC0
13. count &= 0x0F; ensures:
o a) Count becomes 0
o b) Count stays within 4 bits
o c) Count increases
o d) Count resets
o Ans: b) Count stays within 4 bits
14. To make PORTC output:
o a) DDRC = 0x00;
o b) DDRC = 0xFF;
o c) PORTC = 0xFF;
o d) PINB = 0x00;
o Ans: b) DDRC = 0xFF;
15. Binary of 4 is:
o a) 0100
o b) 0010
o c) 1000
o d) 0001
o Ans: a) 0100
16. When button at PB0 is pressed, it returns:
o a) 0
o b) 1
o Ans: b) 1
17. What is the purpose of if(PINB & (1<<PB0))?
o a) Write 1 to PB0
o b) Clear PB0
o c) Check button press
o d) Toggle PB0
o Ans: c) Check button press
18. Why debounce is necessary?
o a) Remove floating values
o b) Prevent multiple counts per press
o Ans: b) Prevent multiple counts per press
19. Which function is used to toggle between up/down mode?
o a) digitalRead()
o b) Button interrupt
o c) Code logic using flag
o d) PWM
o Ans: c) Code logic using flag
20. The max binary value for 4 bits is:
o a) 1110
o b) 1111
o Ans: b) 1111
21. Use of PORTC = count; is to:
o a) Flash LEDs
o b) Print on serial
o c) Show counter on LEDs
o Ans: c) Show counter on LEDs
22. Decimal 5 = Binary ______:
o a) 1011
o b) 0101
o Ans: b) 0101
23. What is wraparound behavior in counter?
o a) 15→0 or 0→15
o Ans: True
24. To prevent overflow:
o a) if(count > 15) count = 0;
o Ans: True
25. How many values in total for 4-bit counter?
o a) 15
o b) 16
o Ans: b) 16
26. What is the output of count = 7; PORTC = count;?
o a) LED pattern: 0111
o Ans: True
27. Bitwise masking is used to:
o a) Clear specific bits
o Ans: True
28. If switch at PB1 is pressed, count should:
o a) Decrease
o Ans: True
29. What data type for count?
o a) char
o b) int
o c) uint8_t
o Ans: c) uint8_t
30. Debouncing delay in ms:
o a) 1
o b) 300
o Ans: b) 300
30 Gap Fillings (Concept + Code)
1. The 4-bit counter uses ______ LEDs for display. → 4
2. To store current count: uint8_t ______ = 0; → count
3. For increment: count = count + ______; → 1
4. To prevent overflow: if(count > 15) count = ______; → 0
5. PORTC = count; shows ______ on LEDs. → binary
6. To enable all Port C as output: DDRC = ______; → 0xFF
7. To read switch at PB0: PINB & (1<<____); → PB0
8. PORTC &= ~(1<<PC3); turns ______ PC3. → off
9. To decrement: count = count - ______; → 1
10. In C, 0x0F is equal to ______ in binary. → 00001111
11. Maximum value in 4-bit binary is ______. → 15
12. To toggle LED at PC1: PORTC ^= (1<<____); → PC1
13. If count is 3, LED pattern = ______. → 0011
14. Button bounce causes ______ counts. → multiple
15. PORTC = 0x0F; turns ON ______ LEDs. → 4
16. _delay_ms(____); used for debounce. → 300
17. PORTC = count; sends ______ to LED. → value
18. To limit count to 4 bits: count &= ______; → 0x0F
19. Data type for binary counter: ______ count; → uint8_t
20. Initial value: count = ______; → 0
21. Binary for decimal 10 is ______. → 1010
22. Button read uses ______ register. → PINx
23. If up button is PB0, down button is usually ______. → PB1
24. To blink each state slowly: _delay_ms(____); → 500
25. 4-bit counter has ______ possible states. → 16
26. LED anode goes to ______. → PORT pin
27. For continuous loop, we use ______. → while(1)
28. In Proteus, we simulate buttons using ______. → SPST switch
29. Count variable updated inside ______ loop. → main/while
30. Decrement: if(count == 0) count = ______; → 15
30 Short Questions (Concept + Code)
1. What is a 4-bit up-down counter?
→ A logic system that counts from 0 to 15 and back using 4 binary bits.
2. How many LEDs are used for 4-bit display?
→ 4 LEDs
3. Write C code to increment and show count on PORTC.
c
Copy code
DDRC = 0xFF;
uint8_t count = 0;
while(1){
PORTC = count;
count++;
_delay_ms(300);
}
4. Write code to decrement counter.
c
Copy code
count--;
PORTC = count;
5. How to detect UP button at PB0?
c
Copy code
if(PINB & (1<<PB0)) count++;
6. Why limit count to 4 bits?
→ To prevent value >15 (as only 4 bits are available)
7. What does PORTC = count; do?
→ Sends binary value to LEDs.
8. How to prevent multiple counts from one press?
→ Add _delay_ms(300); for debouncing.
9. Binary of 7 is:
→ 0111
10. How to mask upper 4 bits?
→ count &= 0x0F;
11. Why use uint8_t for count?
→ It ensures 8-bit variable (faster, efficient)
12. Write if condition to wrap from 15 to 0.
c
Copy code
if(count > 15) count = 0;
13. What is effect of count--; at 0?
→ May wrap to 255 (unless handled)
14. Write code to check both up and down buttons.
c
Copy code
if(PINB & (1<<PB0)) count++;
if(PINB & (1<<PB1)) count--;
15. What is binary of decimal 12?
→ 1100
16. How many counts total in 4-bit?
→ 16 (0–15)
17. What causes bouncing in switch?
→ Mechanical contact noise
18. How to show counter on LEDs?
→ PORTC = count;
19. What happens if no debounce delay?
→ Multiple counts per press
20. What register is used to read switch?
→ PINx
21. Where to place debounce delay?
→ After detecting button press
22. Write code to reset counter at 16.
c
Copy code
if(count > 15) count = 0;
23. Give logic to wrap down from 0 to 15.
c
Copy code
if(count == 0) count = 15;
else count--;
24. How to show 0xF on LEDs?
→ PORTC = 0x0F;
25. How to setup Proteus circuit?
→ ATmega32, 4 LEDs to PORTC, 2 buttons to PB0 & PB1
26. Why use while(1) loop?
→ Infinite loop for continuous counting
27. What is PINB & (1<<PB1) used for?
→ Check down button
28. How to display number 9 in binary?
→ PORTC = 0b1001;
29. What is output of PORTC = 0x0A;?
→ Binary 1010 (PC3 and PC1 ON)
30. Why use logic level 1 for switch press?
→ Button closes to VCC → logic HIGH
Experiment 4 – “Up-Down Counter with Seven Segment Display Using
ATmega32 with Proteus Simulation”
30 MCQs (Code + Concept Mixed)
1. A common cathode 7-segment display lights a segment when:
o a) 1 is written
o b) 0 is written
o c) floating state
o d) GND is disconnected
o Ans: a) 1 is written
2. To show digit “0” on a 7-segment, which segments must be ON?
o a) a, b, c, d, e, f
o b) b, c
o c) a, b, c, e, f
o d) All except g
o Ans: d) All except g
3. The segment pattern for digit 3 in binary is:
o a) 0b1111001
o b) 0b0110000
o c) 0b1110011
o d) 0b0111101
o Ans: d) 0b0111101
4. To increment counter value:
o a) count--
o b) count++
o c) count = 0
o d) count |= 1
o Ans: b) count++
5. What is the max digit shown in up counter (0–9)?
o a) 8
o b) 9
o c) 10
o d) F
o Ans: b) 9
6. Which register sends the segment pattern to PORT?
o a) DDRx
o b) PORTx
o c) PINx
o d) TCCR0
o Ans: b) PORTx
7. What does the value 0b0111111 represent?
o a) Digit 8
o b) Digit 0
o c) All segments ON
o d) Segment a-g ON
o Ans: b) Digit 0
8. 7-segment display typically uses:
o a) 7 inputs
o b) 8 inputs
o c) 9 inputs
o d) 10 inputs
o Ans: b) 8 inputs (7 segments + 1 dot)
9. Which PORT is used to output the display pattern?
o a) PORTB
o b) PORTC
o c) PORTD
o d) PORTA
o Ans: Any (usually PORTC or PORTD)
10. Debounce delay is usually:
o a) 1 ms
o b) 100 ms
o c) 300 ms
o d) 500 ms
o Ans: c) 300 ms
11. What is the purpose of a lookup table in this experiment?
o a) Store names
o b) Store segment patterns
o c) Store delays
o d) Display hex
o Ans: b) Store segment patterns
12. Segment pattern of digit 5 is:
o a) 0b1101101
o Ans: True
13. To display a number, we write:
o a) PORTC = segment[num];
o Ans: True
14. Button press is detected using which register?
o a) DDRx
o b) PINx
o Ans: b) PINx
15. What is binary of 0x3F?
o a) 00111111
o Ans: True
16. What does segment[10] store?
o a) Nothing (index out of bounds)
o Ans: True
17. Segment pattern for “8”:
o a) All segments ON
o Ans: True
18. Which bit is dot segment in 7-segment?
o a) Bit 0
o b) Bit 7
o Ans: b) Bit 7
19. Button logic is usually:
o a) Active LOW
o b) Active HIGH
o Ans: b) Active HIGH (depends on wiring)
20. Up and down counting is controlled by:
o a) Analog pins
o b) Buttons connected to PORTB
o Ans: b) Buttons connected to PORTB
21. What data type is used for storing counter?
o a) float
o b) uint8_t
o Ans: b) uint8_t
22. What happens after count > 9?
o a) Show F
o b) Reset to 0
o Ans: Reset to 0
23. Binary for digit 2:
o a) 0b01011011
o Ans: True
24. What is #define F_CPU 1000000UL for?
o a) Clock speed
o Ans: Clock speed for delay
25. Header file for delay:
o a) <delay.h>
o b) <util/delay.h>
o Ans: b) <util/delay.h>
26. DDRC = 0xFF; does what?
o a) Input
o b) Output
o Ans: b) Output
27. Segment “g” is usually:
o a) Middle bar
o Ans: True
28. Button bounce can be fixed using:
o a) Capacitor
o b) Software delay
o Ans: Both
29. Purpose of array segment[]:
o a) Maps digits to segment codes
o Ans: True
30. PORTC = segment[count]; displays:
o a) Binary
o b) Digit on 7-seg
o Ans: b) Digit on 7-seg
30 Gap Fillings (Code + Concept Mixed)
1. Segment pattern for 0 = 0b_______; → 00111111
2. Segment[3] = _______; → 0b0111101
3. Binary of 5 = _______; → 0b1101101
4. To prevent overflow: if(count > 9) count = _______; → 0
5. Segment pattern stored in _______ array. → segment
6. 7-segment has ______ segments. → 7
7. Dot segment is usually bit number _______. → 7
8. To output value: PORTC = _______; → segment[count]
9. To set port as output: DDRC = _______; → 0xFF
10. For delay: use function _______; → _delay_ms(300)
11. Value of segment[0] = _______; → 0x3F
12. PORTC = 0x4F displays digit _______; → 1
13. To go down: count = count - _______; → 1
14. Lookup table index for digit 6 = _______; → 6
15. Segment ‘a’ corresponds to bit _______; → 0
16. Value of 7 = binary _______; → 0111000
17. Main loop syntax: while(_______) → 1
18. To check UP button: if(PINB & (1<<_______)) → PB0
19. Button press gives logic _______. → 1
20. Segment pattern for digit 9 = _______; → 0b1111011
21. Which bit is LSB in segment pattern? → Bit _______ → 0
22. PORTC = 0x6D; displays digit _______; → 5
23. Up-down controlled by using ______ buttons. → 2
24. #include <_______> → util/delay.h
25. #define F_CPU _______UL → 1000000
26. To clear display: PORTC = _______; → 0x00
27. Pattern for digit 8 = _______; → 0x7F
28. Index out of range can cause _______ error. → garbage/output
29. 7-segment simulated in Proteus with model _______. → CA (Common Anode) or CC
30. Binary value 01001111 = digit _______; → 4
30 Short Questions (Code + Concept Mixed)
1. What is a 7-segment display?
→ An electronic display device to show digits using 7 LEDs (a–g).
2. How many segments are required to display number 8?
→ All 7 segments
3. Write the segment pattern for digit 0.
→ 0b00111111 or 0x3F
4. What is a lookup table in this experiment?
→ An array that stores segment codes for digits 0–9.
5. Write the C array to store digit patterns.
c
Copy code
uint8_t segment[10] = {0x3F,0x06,0x5B,0x4F,0x66,
0x6D,0x7D,0x07,0x7F,0x6F};
6. Which function outputs the segment value?
→ PORTC = segment[count];
7. How do you detect UP button press?
→ if(PINB & (1<<PB0))
8. How do you increment the count?
→ count++;
9. What is the max count shown on single 7-segment?
→9
10. How do you reset count after 9?
c
Copy code
if(count > 9) count = 0;
11. Write code to decrement on button press.
c
Copy code
if(PINB & (1<<PB1)) count--;
12. How to debounce button in code?
→ Add _delay_ms(300); after button check.
13. Why use DDRC = 0xFF;?
→ Set PORTC as output for display
14. How do you prevent count < 0?
c
Copy code
if(count == 0) count = 9;
else count--;
15. Why use delay in the loop?
→ To reduce speed and debounce buttons
16. How to turn off all segments?
→ PORTC = 0x00;
17. Which segment is middle bar?
→ Segment g
18. How do you simulate 7-segment in Proteus?
→ Use 7-segment component and connect to ATmega32
19. What is the dot segment used for?
→ Decimal point
20. Write full code line to show digit 7.
→ PORTC = segment[7];
21. What happens if count > 9 and not reset?
→ Garbage value on display
22. Write the line to check DOWN button.
→ if(PINB & (1<<PB1))
23. What happens if no lookup array used?
→ Manual mapping needed (less efficient)
24. How many bits needed for displaying digit?
→ 7 bits
25. Why use uint8_t count;?
→ 8-bit memory-efficient integer
26. Can we display letters like A or F?
→ Yes, with custom segment patterns
27. How many pins are active in digit 1?
→ 2 (b and c)
28. Write code to show current value.
→ PORTC = segment[count];
29. How to toggle between up and down modes?
→ Use a flag or separate buttons
30. Why use Proteus simulation?
→ Easy testing of hardware and logic without real components
Exp 5"LCD Interfacing using ATMega32 with Proteus Simulation"
30 MCQs (Concept + Code Mixed)
1. A 16x2 LCD can display how many characters at once?
o a) 8
o b) 16
o c) 32
o d) 64
o Ans: c) 32
2. The control pin RS in LCD is used for:
o a) Power supply
o b) Contrast control
o c) Command/Data selection
o d) Enable pulse
o Ans: c) Command/Data selection
3. What is the function of lcd_init()?
o a) Turns on LEDs
o b) Sets up the LCD
o Ans: b) Sets up the LCD
4. LCD data pins are usually connected to:
o a) PORTA
o b) PORTD
o Ans: b) PORTD (commonly)
5. Which header is used for LCD in AVR-GCC?
o a) <lcd.h>
o b) <util/lcd.h>
o c) <lcd_lib.h>
o d) Custom user library
o Ans: d) Custom user library
6. lcd_command(0x01); does what?
o a) Clears screen
o Ans: Clears screen
7. What does lcd_print("HELLO"); do?
o a) Flashes LEDs
o b) Displays HELLO
o Ans: b) Displays HELLO
8. The LCD E pin (Enable) is used to:
o a) Select row
o b) Clock data in
o Ans: b) Clock data in
9. How many lines in 16x2 LCD?
o a) 1
o b) 2
o Ans: b) 2
10. LCD initialization needs:
o a) Just power
o b) Command sequence
o Ans: b) Command sequence
11. Contrast is controlled using:
o a) VCC
o b) GND
o c) Potentiometer on VEE
o Ans: c) Potentiometer on VEE
12. The default address of line 1, position 0 is:
o a) 0x80
o Ans: a) 0x80
13. lcd_gotoxy(0,1); moves cursor to:
o a) Row 1, Col 1
o b) Row 2, Col 1
o Ans: b) Row 2, Col 1
14. After sending a command, we must:
o a) Reset MCU
o b) Delay
o Ans: b) Delay
15. lcd_command(0x0C); turns:
o a) Display OFF
o b) Display ON, Cursor OFF
o Ans: b)
16. lcd_data('A'); does what?
o a) Sends command
o b) Displays character 'A'
o Ans: b)
17. Which mode is faster: 4-bit or 8-bit?
o a) 4-bit
o b) 8-bit
o Ans: b) 8-bit
18. RS = 1 means:
o a) Command mode
o b) Data mode
o Ans: b) Data mode
19. How many data lines in 4-bit mode?
o a) 4
o b) 8
o Ans: a) 4
20. lcd_clear(); is same as:
o a) lcd_command(0x01);
o Ans: True
21. Which pin gives LCD Enable pulse?
o a) RW
o b) E
o Ans: b) E
22. Which library function moves the cursor?
o a) lcd_cursor()
o b) lcd_gotoxy()
o Ans: b) lcd_gotoxy()
23. 16x2 LCDs operate typically at:
o a) 5V
o b) 12V
o Ans: a) 5V
24. LCD command to shift cursor right is:
o a) 0x06
o Ans: a) 0x06
25. lcd_print("123"); uses how many characters?
o a) 2
o b) 3
o Ans: b) 3
26. RS pin set to 0 means:
o a) Data mode
o b) Command mode
o Ans: b) Command mode
27. LCD command to display ON, cursor blinking:
o a) 0x0E
o b) 0x0F
o Ans: b) 0x0F
28. First line address range of LCD is:
o a) 0x80 to 0x8F
o Ans: True
29. Data sent to LCD must be:
o a) ASCII encoded
o Ans: True
30. RW = 0 means:
o a) Read
o b) Write
o Ans: b) Write
30 Gap Fillings
1. LCD has ______ rows and ______ columns → 2, 16
2. lcd_command(0x01); clears the ______ → display
3. RS = 0 means ______ mode → command
4. RW = 0 means ______ mode → write
5. To show "HELLO", use lcd________("HELLO"); → print
6. E pin is used to ______ data → latch/send
7. Line 1 base address = 0x______ → 80
8. Contrast is controlled by pin ______ → VEE
9. lcd_gotoxy(0, 1); moves to 2nd ______ → line
10. LCD operates at ______ volts → 5
11. Command for display ON, cursor ON = 0x______ → 0E
12. lcd_data('M'); displays character ______ → M
13. Function to go to location: lcd_______(x,y); → _gotoxy
14. LCD data pins usually connected to ______ → PORTD
15. In 4-bit mode, ______ data lines used → 4
16. Cursor OFF command = 0x______ → 0C
17. #define F_CPU 1000000______ → UL
18. _delay_ms(300); used for ______ → delay
19. lcd_command(0x06); shifts cursor to the ______ → right
20. Command to return cursor home = 0x______ → 02
21. LCD enable pulse duration should be at least ______ µs → 1
22. To display number 5, use lcd_data('_____'); → 5
23. Common LCD controller chip = ______ → HD44780
24. LCD RW pin is connected to ______ → GND
25. lcd_clear(); clears the ______ → screen
26. LCD cursor blinking command = 0x______ → 0F
27. LCD command mode requires RS = ______ → 0
28. LCD functions must have a ______ after command → delay
29. To start LCD, use lcd________(); → init
30. To display "AVR", use lcd_print("_____"); → AVR
30 Short Questions
1. What is the full form of LCD?
→ Liquid Crystal Display
2. How many characters can a 16x2 LCD display?
→ 32 (16 in each line)
3. What is the role of RS pin in LCD?
→ To select between command and data mode
4. What does lcd_init() function do?
→ Initializes the LCD for operation
5. How do you display the string "HELLO"?
→ lcd_print("HELLO");
6. What is the purpose of lcd_command(0x01);?
→ Clears the display
7. Which pin is used to latch data into LCD?
→ E (Enable) pin
8. What is the use of RW pin?
→ Select Read or Write operation
9. Why is delay required after LCD command?
→ To give LCD time to process the command
10. How to move cursor to line 2, column 5?
→ lcd_gotoxy(4, 1);
11. What does lcd_data('A'); do?
→ Displays character ‘A’ on LCD
12. What is command 0x0F used for?
→ Display ON, cursor blinking
13. How is contrast of LCD controlled in Proteus?
→ Using a potentiometer on VEE pin
14. What is the controller used in most LCDs?
→ HD44780
15. Why use custom LCD library?
→ To simplify LCD commands and setup
16. How do you clear the display using function?
→ lcd_clear();
17. What is lcd_gotoxy() used for?
→ To move cursor to desired position
18. How do you display an integer on LCD?
→ Convert to string using itoa() and then use lcd_print()
19. How do you define system clock?
→ #define F_CPU 1000000UL
20. What delay header is used for LCD timing?
→ <util/delay.h>
21. What is the function of lcd_data()?
→ Sends character data to LCD
22. How to turn OFF cursor?
→ lcd_command(0x0C);
23. How to initialize LCD in code?
→ lcd_init();
24. Why use PORTD for data lines?
→ Easy access to 8-bit port in ATmega32
25. Which pin should always be connected to GND for write mode?
→ RW pin
26. How is a 16x2 LCD connected to ATmega32 in Proteus?
→ RS, RW, E to PORTB; Data pins to PORTD
27. What happens if LCD is not initialized?
→ It shows garbage or doesn't display
28. How do you shift display left?
→ lcd_command(0x18);
29. Which port direction register should be set to output for LCD?
→ DDRB and DDRD
30. Why simulate LCD in Proteus?
→ To verify output before real hardware testing
Experiment 6 – “4x4 Matrix Keypad Interfacing using ATmega32 with Proteus
Simulation”
30 MCQs (Code + Concept Mixed)
1. A 4x4 keypad has how many keys?
o a) 8
o b) 12
o c) 16
o d) 10
o Ans: c) 16
2. A 4x4 matrix keypad has:
o a) 4 rows and 4 columns
o Ans: True
3. Total I/O pins required for 4x4 keypad:
o a) 4
o b) 8
o Ans: b) 8 (4 rows + 4 columns)
4. When a key is pressed in a matrix keypad, it connects:
o a) One row to another
o b) A row and a column
o Ans: b) A row and a column
5. To detect key press, rows are set as:
o a) Input
o b) Output
o Ans: b) Output
6. To scan keypad, columns are:
o a) Output
o b) Input with pull-up
o Ans: b) Input with pull-up
7. Keypad scanning involves:
o a) PWM
o b) ADC
o c) Multiplexing
o Ans: c) Multiplexing
8. Key detection logic is done via:
o a) Polling
o b) Interrupt
o Ans: a) Polling (usually)
9. Key debounce is needed to:
o a) Increase speed
o b) Avoid multiple inputs
o Ans: b) Avoid multiple inputs
10. Each row is pulled LOW one-by-one to:
o a) Power the keypad
o b) Detect pressed key
o Ans: b)
11. A pressed key connects:
o a) VCC to row
o b) Row to column
o Ans: b)
12. The character layout of 4x4 keypad is typically:
o a) Alphanumeric
o b) Hexadecimal
o Ans: b)
13. Which function is used to detect key press?
o a) getKey()
o b) readKey()
o c) scan_keypad()
o Ans: c) scan_keypad()
14. Columns are normally:
o a) High
o b) Low
o Ans: a) High (via pull-up)
15. To scan keypad, we set one row LOW and:
o a) Read columns
o Ans: True
16. If column 3 is low, it means:
o a) Button not pressed
o b) Corresponding key is pressed
o Ans: b)
17. In keypad matrix, pull-up resistors are used on:
o a) Rows
o b) Columns
o Ans: b)
18. Button bounce typically lasts:
o a) 1–5ms
o b) 10–50ms
o Ans: b)
19. Common debounce method:
o a) Capacitor
o b) Software delay
o c) Both
o Ans: c) Both
20. Keypad library functions are often user-written because:
o a) Built-in support is limited
o Ans: True
21. Proteus component used for keypad:
o a) Push Button
o b) Keypad 4x4
o Ans: b)
22. If row 0 is LOW and column 2 reads LOW, pressed key is:
o a) (0,2) = 3rd key in 1st row
o Ans: True
23. Keypad interface is useful for:
o a) Data input
o b) Security code
o c) Calculator
o d) All
o Ans: d)
24. To identify key, we map:
o a) Row and Column index
o Ans: True
25. Logical condition: if(PINC & (1<<PC0)) checks:
o a) PC0 is high
o Ans: True
26. Key '5' is located at:
o a) Row 1, Col 0
o b) Row 1, Col 1
o Ans: b)
27. Column scanning must be:
o a) Sequential
o Ans: True
28. LCD + Keypad interface is used in:
o a) Menu navigation
o Ans: True
29. Pressing multiple keys at once can cause:
o a) Lockup
o b) Ghosting
o Ans: b) Ghosting
30. How many total key combinations in 4x4 matrix?
o a) 12
o b) 16
o Ans: 16
30 Gap Fillings
1. 4x4 keypad has ______ rows and ______ columns → 4, 4
2. Total keys in matrix keypad = ______ → 16
3. Data is detected by scanning ______ and reading ______ → rows, columns
4. Keypad columns are configured as ______ input → pull-up
5. Rows are set to LOW one-by-one during ______ → scanning
6. To prevent bounce, add a delay of about ______ ms → 300
7. When a key is pressed, a ______ connection is made between row and column → short
8. The function to scan keypad is usually called _______() → scan_keypad
9. Keypad pin configuration: ROW1–ROW4 and COL1–COL4 = total ______ pins → 8
10. Character map is usually stored in a ______ array → 2D
11. If row 2 and column 1 are active, the key is at position (______, ______) → 2,1
12. A typical key layout for 4x4 keypad includes numbers ______ → 0–9
13. Keypad pins are connected to PORTB and ______ → PORTC
14. if((PINC & (1<<PC3))==0) means column 3 is ______ → low/pressed
15. To make all rows HIGH: PORTx = 0x__ → F0
16. Setting DDRB = 0xF0 means upper 4 bits are ______ → output
17. To identify pressed key: compare both row and ______ → column
18. PORTB = ~(1 << row); makes selected row ______ → low
19. Each key press should be followed by _______(300); → _delay_ms
20. In simulation, component used: ______ keypad → 4x4
21. Keypad matrix = ROWx ______ → COL
22. Keypad used for entering ______ → input
23. Key 'A' is typically placed at position ______ → (3,0)
24. PORTD can be used to display pressed ______ → key
25. DDRC = 0x0F; makes lower 4 pins of PORTC as ______ → output
26. Scanning is done inside a while(___) loop → 1
27. All columns go LOW if key is ______ → pressed
28. Key detection loop uses nested ______ → for loops
29. Use of keypad avoids needing multiple ______ buttons → individual
30. Multiple simultaneous presses cause ______ effect → ghosting
30 Short Questions (Code + Concept Mixed)
1. What is a 4x4 matrix keypad?
→ A grid of 4 rows × 4 columns totaling 16 keys.
2. How does matrix keypad work?
→ Pressing a key connects one row and one column together.
3. How many pins are needed for 4x4 keypad?
→ 8 (4 rows + 4 columns)
4. How are rows and columns configured in microcontroller?
→ Rows as outputs, columns as inputs with pull-up.
5. How do you detect a key press?
→ By pulling one row LOW at a time and checking which column goes LOW.
6. What is ghosting in keypads?
→ Wrong detection when multiple keys are pressed simultaneously.
7. Write a sample code snippet for row scanning.
c
Copy code
for(uint8_t row=0; row<4; row++){
PORTB = ~(1<<row);
if(!(PINC & (1<<PC0))) key = keypad[row][0];
}
8. What is the purpose of debounce delay?
→ To avoid multiple detections from one press.
9. Which header is used for delay in AVR?
→ <util/delay.h>
10. How do you map keypad to characters?
→ Use a 2D char array:
c
Copy code
char keypad[4][4] = {{'1','2','3','A'}, ... };
11. How is keypad connected in Proteus?
→ 4x4 keypad component to PORTB and PORTC of ATmega32.
12. What is the use of if((PINC & (1<<PC2))==0)?
→ To detect if column 2 is active (key press)
13. Write the pin direction setup for keypad (rows on upper nibble).
c
Copy code
DDRB = 0xF0; // Rows output
PORTB = 0x0F; // Columns pull-up
14. What does PORTB = ~(1<<row); do?
→ Activates one row by pulling it LOW
15. Write a function prototype to scan keypad.
→ char scan_keypad(void);
16. How are inputs read in AVR?
→ Using PINx register
17. Why use nested loops in keypad scanning?
→ To iterate rows and columns and detect key
18. How to show the pressed key on LCD?
c
Copy code
lcd_data(scan_keypad());
19. What is the default state of column lines?
→ High (due to pull-up)
20. What happens if all rows are HIGH?
→ No key will be detected
21. What character will (row 2, col 1) usually return?
→ '5'
22. How to detect which key is pressed?
→ Match active row and column to a lookup table
23. How many characters in total in 4x4 keypad?
→ 16
24. Is keypad a digital or analog device?
→ Digital
25. What is typical delay used in key scanning?
→ 300 ms
26. Why is key debounce necessary in real circuits?
→ Because switches bounce, causing multiple signals
27. Which type of scan is more common: row-to-column or column-to-row?
→ Row-to-column
28. How do you handle multiple key presses?
→ Limit input to single press using software
29. How does Proteus simulate a keypad press?
→ Click on the button in virtual keypad
30. What is the use of keypad in embedded projects?
→ User input, passcode entry, control systems, menu selection
Experiment 7 – “Position Control of Servo Motor using ATmega32 with Proteus
Simulation”
30 MCQs (Code + Concept Mixed)
1. What type of signal is used to control servo motors?
o a) Analog voltage
o b) PWM (Pulse Width Modulation)
o c) Serial data
o d) DC current
o Ans: b) PWM
2. Typical servo control pulse frequency is:
o a) 20 kHz
o b) 50 Hz
o c) 1 kHz
o d) 100 Hz
o Ans: b) 50 Hz
3. The pulse width for servo control typically varies from:
o a) 0.5 ms to 2.5 ms
o b) 1 ms to 2 ms
o c) 0 ms to 5 ms
o d) 2 ms to 10 ms
o Ans: b) 1 ms to 2 ms
4. What is the function of Timer1 in ATmega32 in this experiment?
o a) Count external pulses
o b) Generate PWM signal
o c) Generate interrupts
o d) ADC conversion
o Ans: b) Generate PWM signal
5. Which register controls the PWM duty cycle for Timer1?
o a) OCR1A
o b) OCR0
o c) TCCR1A
o d) TCNT1
o Ans: a) OCR1A
6. To achieve 50 Hz PWM frequency with ATmega32, the timer is configured with:
o a) Prescaler 8
o b) Prescaler 64
o c) Prescaler 256
o d) Prescaler 1024
o Ans: c) Prescaler 256 (commonly)
7. PWM mode used for servo control is:
o a) Fast PWM
o b) Phase Correct PWM
o c) Normal mode
o d) CTC mode
o Ans: a) Fast PWM
8. What is the PWM resolution in ATmega32 Timer1?
o a) 8-bit
o b) 16-bit
o c) 10-bit
o d) 12-bit
o Ans: b) 16-bit
9. To move the servo to 0 degrees, the PWM pulse width should be approx:
o a) 0.5 ms
o b) 1 ms
o c) 1.5 ms
o d) 2 ms
o Ans: b) 1 ms
10. The variable controlling the pulse width is usually:
o a) OCR1A
o Ans: True
11. What is the role of the servo motor's feedback potentiometer?
o a) Provide position feedback
o b) Generate PWM signal
o c) Control speed
o d) Provide power
o Ans: a) Provide position feedback
12. Proteus simulation helps to:
o a) Test servo hardware wiring
o b) Test PWM code logic
o c) Both
o Ans: c) Both
13. Which header file is needed for delay functions in AVR?
o a) <delay.h>
o b) <util/delay.h>
o Ans: b) <util/delay.h>
14. To set PWM duty cycle to 7.5% (for 90°), OCR1A value is set accordingly. Which
statement is true?
o a) OCR1A = (TimerMax * 7.5) / 100
o Ans: True
15. The servo motor shaft rotates approximately how many degrees?
o a) 180°
o b) 360°
o c) 90°
o d) 270°
o Ans: a) 180°
16. The pulse repetition rate (period) for servo control is:
o a) 20 ms
o b) 50 ms
o c) 10 ms
o d) 5 ms
o Ans: a) 20 ms
17. What is the purpose of setting the DDR register for PWM output pin?
o a) Configure as input
o b) Configure as output
o Ans: b) Configure as output
18. Which pin of ATmega32 is commonly used for PWM output with Timer1?
o a) OC1A (Pin PD5)
o Ans: True
19. In CTC mode, PWM signal is:
o a) Not generated
o b) Only timer interrupts
o Ans: a)
20. What is the timer top value for 16-bit timer in servo control?
o a) 0xFFFF
o b) 0x03E8
o Ans: Depends on prescaler and frequency (usually set)
21. PWM signal duty cycle controls:
o a) Servo angle
o Ans: True
22. What happens if PWM pulse width is less than 1 ms?
o a) Servo moves beyond 0°
o b) Servo might jitter
o Ans: b) Servo might jitter
23. The TCCR1A register bits control:
o a) Waveform generation mode
o Ans: True
24. Which of the following is NOT a PWM mode?
o a) Fast PWM
o b) Phase Correct PWM
o c) CTC mode
o Ans: c) CTC mode
25. What unit is used to measure PWM duty cycle?
o a) Percentage (%)
o Ans: True
26. How do you stop PWM output on OC1A pin?
o a) Disable timer
o b) Disconnect pin
o c) Clear COM1A1:0 bits
o Ans: c) Clear COM1A1:0 bits
27. What does sei() function do?
o a) Enable global interrupts
o Ans: True
28. The function to set PWM duty cycle is usually:
o a) OCR1A = value;
o Ans: True
29. The main loop to sweep servo angle involves:
o a) Incrementing OCR1A gradually
o Ans: True
30. Servo motor feedback is typically:
o a) Analog voltage
o Ans: True
30 Gap Fillings
1. Servo motors are controlled by ______ signals → PWM
2. Typical servo PWM frequency = ______ Hz → 50
3. Pulse width range for servo is ______ to ______ ms → 1, 2
4. Timer1 in ATmega32 is a ______ bit timer → 16
5. Register controlling PWM duty cycle = ______ → OCR1A
6. The output compare pin for Timer1 is ______ → OC1A
7. Prescaler value commonly used = ______ → 256
8. PWM period = 20 ms corresponds to frequency ______ Hz → 50
9. Duty cycle is expressed in ______ → percentage
10. 90° servo position pulse width = ______ ms → 1.5
11. Servo motor shaft rotation max angle = ______ → 180
12. PWM signal duty cycle controls the servo ______ → angle
13. ATmega32 PWM pin is configured as ______ → output
14. PWM signal is a ______ waveform → square
15. Timer1 top value for servo is set in ______ register → ICR1
16. To initialize timer, set ______ bits → WGM
17. The delay between pulses is about ______ ms → 20
18. Servo motor converts electrical signal to ______ motion → mechanical
19. In Proteus, servo motor symbol is found under ______ → motors
20. The OCR1A value changes the ______ width → pulse
21. The timer counts from 0 to ______ → ICR1
22. Prescaler divides the clock by ______ → 256
23. To start PWM, COM1A bits are set to ______ → non-inverting mode
24. The function _delay_ms() is declared in ______ → util/delay.h
25. PWM duty cycle can be calculated as (OCR1A/ICR1) × ______ → 100
26. Servo jitter occurs due to incorrect ______ width → pulse
27. Servo control pulse must be repeated every ______ ms → 20
28. OCR1A register is a ______ bit register → 16
29. PWM frequency depends on the ______ and prescaler → clock
30. To stop PWM output, clear the ______ bits → COM1A
30 Short Questions (Code + Concept Mixed)
1. What is PWM and why is it used for servo control?
→ PWM is Pulse Width Modulation, used to control servo angle by varying pulse width.
2. What is the typical frequency for servo PWM signals?
→ 50 Hz
3. What timer in ATmega32 is used for PWM generation in this experiment?
→ Timer1
4. How does changing the OCR1A value affect the servo?
→ It changes the PWM duty cycle, thus controlling servo angle.
5. What is the pulse width range for servo motors?
→ Approximately 1 ms to 2 ms
6. Write the code snippet to set OCR1A for 1.5 ms pulse width if ICR1 = 19999.
c
Copy code
OCR1A = 1499; // 1.5 ms pulse width assuming 16MHz clock with prescaler
8
7. Why is the prescaler used in timer setup?
→ To slow down the timer clock to achieve desired PWM frequency.
8. What is the role of ICR1 in PWM mode?
→ It sets the TOP value for Timer1 in PWM mode.
9. How do you initialize Timer1 for 16-bit Fast PWM?
→ By setting WGM bits to 14 (0x0E) and setting ICR1 as TOP.
10. Which pin outputs the PWM signal on ATmega32?
→ OC1A (PD5)
11. How do you configure the PWM output pin as output?
→ DDRD |= (1 << PD5);
12. What is the function of the COM1A1:0 bits?
→ They control the output mode of PWM signal on OC1A pin.
13. Explain why a delay is used between PWM pulses?
→ Servo expects pulse every 20 ms for proper operation.
14. What happens if the PWM pulse width is set below 1 ms?
→ Servo may jitter or move to undesired position.
15. How do you stop PWM signal generation?
→ Clear COM1A bits in TCCR1A.
16. Write code snippet to initialize Timer1 with prescaler 256.
c
Copy code
TCCR1B |= (1 << WGM13) | (1 << WGM12) | (1 << CS12);
17. Why use Proteus simulation for servo control experiments?
→ To verify PWM and servo position logic without physical hardware.
18. What is the purpose of the feedback potentiometer in servo?
→ Provides position feedback to internal control circuitry.
19. How is the duty cycle calculated from OCR1A and ICR1?
→ Duty cycle = (OCR1A / ICR1) × 100%
20. How do you change servo position from 0° to 180°?
→ Vary PWM pulse width from ~1 ms to 2 ms by changing OCR1A.
21. Which function in AVR code provides millisecond delay?
→ _delay_ms()
22. How many bits is OCR1A register?
→ 16 bits
23. What is the default frequency of ATmega32 clock?
→ 1 MHz or 16 MHz (depends on setup)
24. What are the waveform generation mode bits for Fast PWM 16-bit?
→ WGM13:0 = 14
25. How do you set the output compare pin for PWM in code?
→ TCCR1A |= (1 << COM1A1);
26. How often should servo control pulse be sent?
→ Every 20 ms
27. Write a code line to set servo angle to 90°.
c
Copy code
OCR1A = ICR1 / 2;
28. Why is PWM preferred over analog voltage for servo control?
→ PWM is precise, digital-friendly, and noise-immune.
29. What does sei() do in AVR code?
→ Enables global interrupts.
30. How do you simulate servo motor behavior in Proteus?
→ Connect servo component and observe shaft movement with PWM input.
Experiment 8 – “Introduction to AVR Trainer Kit”
30 MCQs (Concept + Code Mixed)
1. What is an AVR Trainer Kit?
o a) A software tool
o b) A hardware platform for AVR MCU learning
o c) A compiler
o d) A simulator only
o Ans: b)
2. Which microcontroller is commonly used in AVR Trainer Kits?
o a) PIC16F877A
o b) ATmega32
o c) ARM Cortex-M3
o d) 8051
o Ans: b)
3. Which programming interface is commonly available on AVR Trainer Kits?
o a) USB ISP
o b) JTAG
o c) SPI
o d) UART
o Ans: a)
4. What is the main purpose of the AVR Trainer Kit?
o a) Programming AVR MCUs
o b) Experimenting with embedded systems
o c) Learning interfacing peripherals
o d) All of the above
o Ans: d)
5. Which component is often used for user input on the trainer kit?
o a) Rotary encoder
o b) 4x4 matrix keypad
o c) Push buttons
o d) Touch screen
o Ans: c)
6. The LCD on AVR Trainer Kit is usually:
o a) 8x2
o b) 16x2
o c) 20x4
o d) OLED
o Ans: b)
7. Which programming language is mostly used for AVR microcontrollers?
o a) Java
o b) Python
o c) C
o d) Assembly only
o Ans: c)
8. AVR Trainer Kits help in understanding which communication protocols?
o a) SPI and I2C
o b) UART
o c) CAN bus
o d) All of the above
o Ans: d)
9. Which software is commonly used to write and compile AVR programs?
o a) MPLAB
o b) Atmel Studio
o c) Arduino IDE
o d) Keil uVision
o Ans: b)
10. What power supply voltage is typical for AVR Trainer Kits?
o a) 3.3V
o b) 5V
o c) 12V
o d) 24V
o Ans: b)
11. Which tool is used to upload code to AVR MCU?
o a) Programmer
o b) Debugger
o c) Compiler
o d) Oscilloscope
o Ans: a)
12. How many general-purpose I/O pins does ATmega32 have?
o a) 8
o b) 32
o c) 40
o d) 64
o Ans: b)
13. What is the function of the crystal oscillator on the trainer kit?
o a) Power supply
o b) Clock generation
o c) Reset
o d) Communication
o Ans: b)
14. AVR Trainer Kit usually includes which display interface?
o a) Seven segment
o b) LCD
o c) LED matrix
o d) OLED
o Ans: b)
15. The reset button on the trainer kit is used to:
o a) Power ON/OFF the MCU
o b) Restart program execution
o c) Program MCU
o d) None
o Ans: b)
16. Which communication port is commonly used for debugging?
o a) SPI
o b) UART
o c) I2C
o d) CAN
o Ans: b)
17. How is the LCD interfaced to the MCU on trainer kit?
o a) Parallel interface
o b) SPI
o c) UART
o d) I2C
o Ans: a)
18. The LED indicators on the trainer kit are connected to:
o a) Analog pins
o b) Digital I/O pins
o c) Power supply
o d) Oscillator pins
o Ans: b)
19. What is the typical crystal frequency on AVR Trainer Kit?
o a) 1 MHz
o b) 8 MHz
o c) 16 MHz
o d) 20 MHz
o Ans: c)
20. The main clock source in ATmega32 is:
o a) Internal RC oscillator
o b) External crystal
o c) Power supply
o d) PLL
o Ans: b)
21. Which compiler option is used to generate hex file for AVR?
o a) -O0
o b) -o
o c) -mmcu
o d) -c
o Ans: c)
22. What is the function of the ISP connector?
o a) Power supply
o b) Program MCU
o c) Debugging
o d) Reset
o Ans: b)
23. AVR Trainer Kits may include which sensor interface?
o a) Temperature sensor
o b) Light sensor
o c) Both
o d) None
o Ans: c)
24. What is the main IDE used with AVR Trainer Kit?
o a) Arduino IDE
o b) Atmel Studio
o c) MPLAB X
o d) Code Composer Studio
o Ans: b)
25. Which header file contains MCU register definitions?
o a) avr/io.h
o b) stdio.h
o c) util/delay.h
o d) stdlib.h
o Ans: a)
26. How is power typically supplied to the AVR Trainer Kit?
o a) USB
o b) Battery
o c) External DC supply
o d) All of the above
o Ans: d)
27. Which component is used to reset the MCU manually?
o a) Push button
o b) Jumper
o c) DIP switch
o d) Potentiometer
o Ans: a)
28. Which communication interface is often demonstrated on the trainer kit?
o a) SPI
o b) UART
o c) I2C
o d) All of these
o Ans: d)
29. Which of the following is NOT part of AVR Trainer Kit?
o a) LCD
o b) MCU
o c) Heater
o d) Keypad
o Ans: c)
30. The main programming language for AVR Trainer Kit is:
o a) Python
o b) Assembly and C
o c) Java
o d) C++
o Ans: b)
30 Gap Fillings
1. AVR Trainer Kit is used for learning ______ microcontrollers → AVR
2. The microcontroller commonly used is ______ → ATmega32
3. AVR Trainer Kit includes an ______ for displaying data → LCD
4. The programming interface on the kit is called ______ → ISP
5. The crystal oscillator provides the ______ signal → clock
6. The MCU clock frequency is typically ______ MHz → 16
7. User inputs are given using ______ → push buttons
8. The MCU is powered by ______ volts → 5
9. Code for AVR MCUs is mostly written in ______ language → C
10. The reset button restarts the ______ → MCU
11. The ISP connector uses ______ protocol → SPI
12. LEDs on the trainer kit are connected to ______ pins → digital I/O
13. The LCD used is usually ______ × 2 → 16
14. The MCU clock is generated by a ______ → crystal oscillator
15. The MCU registers are defined in header file ______ → avr/io.h
16. Delay functions require header file ______ → util/delay.h
17. The power supply for the kit can be via ______ or USB → external adapter
18. The IDE commonly used is called ______ Studio → Atmel
19. The MCU pins are configured by setting ______ registers → DDR
20. The program is loaded into MCU using a ______ → programmer
21. The programming cable connects to the ______ port → ISP
22. Keypads on the kit are arranged in a ______ matrix → 4x4
23. Analog sensors connect to the MCU via ______ pins → ADC
24. Communication protocols demonstrated include UART, SPI, and ______ → I2C
25. The MCU clock frequency is measured in ______ → MHz
26. The MCU executes instructions sequentially by the ______ cycle → fetch-decode-
execute
27. The MCU's I/O pins are grouped in ______ → ports
28. Interrupts allow the MCU to respond to external ______ → events
29. The MCU needs to be ______ before programming → reset
30. The trainer kit helps students to understand embedded ______ systems → design
30 Short Questions (Concept + Code Mixed)
1. What is an AVR Trainer Kit?
→ A hardware platform to learn and experiment with AVR microcontrollers.
2. Which MCU is commonly used on the AVR Trainer Kit?
→ ATmega32
3. What is the purpose of the ISP interface?
→ To program the microcontroller in-circuit.
4. Which component displays information on the trainer kit?
→ 16x2 LCD
5. How do you reset the microcontroller manually?
→ Using the reset push button.
6. Which language is mainly used to program AVR MCUs?
→ C language
7. What is the role of the crystal oscillator?
→ To provide clock pulses for MCU operation.
8. How are user inputs generally given on the trainer kit?
→ Using push buttons or keypads.
9. Name three communication protocols often demonstrated on the trainer kit.
→ UART, SPI, I2C
10. Which header file is essential for AVR MCU register definitions?
→ <avr/io.h>
11. How is power supplied to the trainer kit?
→ Via external DC supply, battery, or USB.
12. What is the function of the LEDs on the trainer kit?
→ To indicate digital output status.
13. What is the function of the reset button?
→ To restart MCU execution.
14. Which IDE is commonly used to write AVR code?
→ Atmel Studio
15. How do you configure MCU pins as output?
→ By setting bits in DDR registers.
16. How is code uploaded to the MCU?
→ Using a programmer connected to the ISP port.
17. What is the use of push buttons on the trainer kit?
→ To provide digital input signals.
18. Name one sensor that might be interfaced with the trainer kit.
→ Temperature sensor
19. How is LCD connected to the MCU?
→ Through data and control pins using parallel interface.
20. What is the clock frequency of the MCU on the trainer kit?
→ Typically 16 MHz
21. How do interrupts benefit the MCU operation?
→ By allowing the MCU to respond to events immediately.
22. What is the function of the ISP programmer?
→ To flash the program into the MCU memory.
23. Name one output device on the trainer kit besides LCD.
→ LEDs
24. What is the basic programming language for embedded systems?
→ C language
25. How do you include delay in AVR programs?
→ Using _delay_ms() function.
26. Which file contains delay functions for AVR?
→ <util/delay.h>
27. What is the use of DDR registers?
→ To configure pins as input or output.
28. What is the role of the crystal oscillator in timing?
→ Provides stable clock for instruction timing.
29. How is power managed in the trainer kit?
→ Using voltage regulators and power switches.
30. Why is an AVR Trainer Kit useful for students?
→ It provides hands-on experience with microcontroller programming and interfacing.
Experiment 9 – “1 Hz Signal Generation using ATmega32 (Timer0) with Proteus
Simulation”
30 MCQs (Code + Concept Mixed)
1. What is the frequency of the desired output signal?
o a) 1 kHz
o b) 1 Hz
o c) 10 Hz
o d) 100 Hz
o Ans: b) 1 Hz
2. Which timer of ATmega32 is used in this experiment?
o a) Timer0
o b) Timer1
o c) Timer2
o d) None
o Ans: a) Timer0
3. Timer0 in ATmega32 is a ______-bit timer.
o a) 8
o b) 16
o c) 32
o d) 64
o Ans: a) 8
4. The timer counts from ______ to ______.
o a) 0 to 255
o b) 0 to 1023
o c) 0 to 65535
o d) 0 to 127
o Ans: a) 0 to 255
5. To generate a 1 Hz signal, the timer is typically configured in:
o a) Normal mode
o b) CTC mode
o c) PWM mode
o d) Phase correct PWM
o Ans: b) CTC mode
6. What register holds the compare value in CTC mode?
o a) OCR0
o b) TCNT0
o c) TCCR0
o d) TIMSK
o Ans: a) OCR0
7. To generate a 1 Hz signal, the timer overflow period must be:
o a) 1 ms
o b) 1 s
o c) 100 ms
o d) 10 s
o Ans: b) 1 s
8. Which prescaler value is commonly used for Timer0?
o a) 8
o b) 64
o c) 256
o d) 1024
o Ans: d) 1024
9. The CPU clock frequency is assumed to be:
o a) 1 MHz
o b) 8 MHz
o c) 16 MHz
o d) 20 MHz
o Ans: c) 16 MHz (usually)
10. The toggle output pin for Timer0 in ATmega32 is:
o a) OC0 (PB3)
o b) OC1A (PD5)
o c) OC2 (PD7)
o d) None
o Ans: a) OC0 (PB3)
11. In CTC mode, the timer resets when TCNT0 reaches:
o a) 255
o b) OCR0
o c) 0
o d) 127
o Ans: b) OCR0
12. To toggle the output pin on compare match, COM01:0 bits must be set to:
o a) 01
o b) 10
o c) 11
o d) 00
o Ans: a) 01
13. The formula for timer tick time is:
o a) Prescaler / CPU clock
o Ans: True
14. The output frequency formula for toggle on compare match is:
o a) CPU clock / (2 × Prescaler × (OCR0 + 1))
o Ans: True
15. The value of OCR0 to get 1 Hz from 16 MHz CPU clock with 1024 prescaler is
approximately:
o a) 15624
o b) 156
o c) 61
o d) 249
o Ans: d) 249
16. Which bit in TIMSK enables Timer0 compare match interrupt?
o a) OCIE0
o b) TOIE0
o c) OCIE1A
o d) TOIE1
o Ans: a) OCIE0
17. Enabling interrupts requires setting:
o a) sei()
o b) cli()
o c) ISR()
o d) main()
o Ans: a) sei()
18. The interrupt service routine for Timer0 compare match is:
o a) ISR(TIMER0_COMP_vect)
o b) ISR(TIMER1_OVF_vect)
o c) ISR(INT0_vect)
o d) ISR(ADC_vect)
o Ans: a)
19. The OC0 pin toggles every time:
o a) Timer overflows
o b) Timer reaches compare value
o Ans: b)
20. What is the purpose of toggling OC0 pin?
o a) To generate square wave
o Ans: True
21. How many times per second will OC0 toggle to get 1 Hz signal?
o a) 1
o b) 2
o c) 0.5
o d) 4
o Ans: b) 2 (toggle twice per period)
22. The signal period is:
o a) 1/frequency
o Ans: True
23. The OCR0 register is 8-bit, so max value is:
o a) 255
o Ans: True
24. If OCR0 is set too low, output frequency will:
o a) Increase
o Ans: True
25. Timer0 can be clocked from:
o a) Internal CPU clock
o b) External clock source
o c) Both
o Ans: c)
26. The initial value of TCNT0 is:
o a) 0
o Ans: True
27. The main advantage of using CTC mode is:
o a) Automatic reset on compare match
o Ans: True
28. To disable Timer0, prescaler bits should be set to:
o a) 0
o Ans: True
29. To simulate the output, the OC0 pin is connected to:
o a) Oscilloscope or LED
o Ans: True
30. What header files are essential for timer and interrupt usage?
o a) avr/io.h and avr/interrupt.h
o Ans: True
30 Gap Fillings
1. Timer0 in ATmega32 is an ______ bit timer → 8
2. The compare match register is named ______ → OCR0
3. CTC stands for ______ → Clear Timer on Compare
4. The CPU clock frequency is usually set to ______ MHz → 16
5. The prescaler value for this experiment is ______ → 1024
6. To toggle OC0 on compare match, set COM00 bit to ______ → 1
7. Timer0 counts from 0 to ______ → OCR0
8. The frequency formula is CPU clock divided by ______ → (2 × Prescaler × (OCR0 +1))
9. The output pin OC0 is located on PORT ______ → B
10. Interrupts are enabled by calling the function ______ → sei()
11. The Timer0 compare match interrupt vector is ______ → TIMER0_COMP_vect
12. The OCR0 register is ______ bits wide → 8
13. The timer period for 1 Hz signal is ______ seconds → 1
14. The toggling of OC0 pin creates a ______ wave → square
15. The main control register for Timer0 is ______ → TCCR0
16. Timer interrupts improve ______ of code → efficiency
17. To clear the timer, the TCNT0 register is set to ______ → 0
18. The interrupt service routine begins with ______ macro → ISR()
19. The prescaler divides the clock to ______ frequency → lower
20. To stop the timer, prescaler bits are cleared to ______ → 0
21. The output toggle occurs on ______ match → compare
22. The main loop can be empty if interrupts are used for toggle → True
23. Timer0 can generate PWM signals as well as ______ → interrupts
24. The output frequency is half the toggle frequency → True
25. OCR0 value for 1 Hz with 16 MHz clock and 1024 prescaler is ______ → 249
26. The interrupt mask register is ______ → TIMSK
27. The delay between toggles is ______ seconds → 0.5
28. The interrupt flag is cleared automatically by hardware → True
29. The OC0 pin is multiplexed with ______ pin → PB3
30. Proteus simulation allows visualizing ______ output → PWM/square wave
30 Short Questions (Code + Concept Mixed)
1. What is Timer0 in ATmega32?
→ An 8-bit timer/counter module used for timing and counting operations.
2. What is CTC mode?
→ Clear Timer on Compare match mode where timer resets on compare match.
3. Why use prescaler in timer?
→ To reduce the timer clock frequency to achieve desired time intervals.
4. How to calculate OCR0 for a given frequency?
→ OCR0 = (CPU frequency) / (2 × prescaler × desired frequency) -1
5. Write code to configure Timer0 in CTC mode with prescaler 1024.
c
Copy code
TCCR0 = (1 << WGM01) | (1 << CS02) | (1 << CS00);
6. What does setting COM00 = 1 do?
→ Toggles OC0 pin on compare match.
7. How to enable Timer0 compare interrupt?
→ TIMSK |= (1 << OCIE0);
8. How to enable global interrupts?
→ By calling sei();
9. Write ISR function prototype for Timer0 compare.
c
Copy code
ISR(TIMER0_COMP_vect) {
// interrupt code
}
10. What happens in the ISR to generate the signal?
→ Usually toggling a variable or output pin.
11. Why is OC0 pin used in this experiment?
→ To output the generated square wave signal.
12. What is the max count value of Timer0?
→ 255
13. Why use CTC mode instead of normal mode?
→ To reset timer at desired count instead of overflow.
14. What is the formula for timer tick time?
→ Tick time = Prescaler / CPU frequency
15. How often does the ISR trigger to get 1 Hz?
→ Twice per period (at half period each toggle).
16. What happens if interrupts are not enabled?
→ ISR won't execute, signal not generated.
17. How to simulate Timer0 output in Proteus?
→ Connect OC0 pin to oscilloscope.
18. What register controls the timer mode?
→ TCCR0
19. How to clear the timer counter?
→ Set TCNT0 = 0;
20. How to stop Timer0?
→ Clear clock select bits in TCCR0.
21. What does ISR stand for?
→ Interrupt Service Routine
22. How to configure OC0 as output pin?
→ Set DDRB |= (1 << PB3);
23. What is the role of TIMSK?
→ To enable/disable timer interrupts.
24. What does WGM01 bit do in TCCR0?
→ Sets CTC mode when 1.
25. How to write a delay in AVR code?
→ Using _delay_ms() function.
26. Which header file must be included for interrupts?
→ <avr/interrupt.h>
27. What frequency will be on OC0 pin if OCR0 is 249?
→ 1 Hz
28. How does prescaler affect output frequency?
→ Higher prescaler lowers frequency.
29. What is the purpose of the main loop in this experiment?
→ Often empty; timer interrupt handles signal generation.
30. Why use hardware toggle instead of software toggle for output pin?
→ Hardware toggle is faster and more precise.
Experiment 10 – “Interfacing LM35 Temperature Sensor using ATmega32 with
Proteus Simulation”
30 MCQs (Code + Concept Mixed)
1. What type of sensor is LM35?
o a) Digital temperature sensor
o b) Analog temperature sensor
o c) Pressure sensor
o d) Humidity sensor
o Ans: b)
2. What is the output voltage sensitivity of LM35?
o a) 10 mV/°C
o b) 100 mV/°C
o c) 1 V/°C
o d) 0.1 mV/°C
o Ans: a)
3. The LM35 sensor output voltage is directly proportional to:
o a) Temperature in °F
o b) Temperature in °C
o c) Humidity
o d) Pressure
o Ans: b)
4. What is the operating voltage range of LM35?
o a) 4V to 30V
o b) 2V to 5V
o c) 1V to 12V
o d) 3.3V only
o Ans: a)
5. Which ADC channel of ATmega32 is commonly used to connect LM35?
o a) ADC0 (Pin PA0)
o b) ADC1
o c) ADC2
o d) ADC3
o Ans: a)
6. What is the resolution of the ADC in ATmega32?
o a) 8-bit
o b) 10-bit
o c) 12-bit
o d) 16-bit
o Ans: b)
7. What is the reference voltage used for ADC in this experiment?
o a) 5V
o b) 3.3V
o c) Internal 2.56V
o d) External reference
o Ans: a)
8. How is the analog output of LM35 converted to digital in the MCU?
o a) Using ADC
o b) Using DAC
o c) Using PWM
o d) Using UART
o Ans: a)
9. What does ADC stand for?
o a) Analog to Digital Converter
o Ans: True
10. What function is used to start ADC conversion?
o a) Set ADSC bit in ADCSRA
o Ans: True
11. How do you know ADC conversion is complete?
o a) ADIF bit set
o b) Polling ADSC bit
o Ans: Both
12. Which register holds the ADC result?
o a) ADC
o b) ADCL and ADCH
o Ans: ADCL and ADCH
13. What is the maximum voltage that can be measured by the ADC with 5V reference?
o a) 5V
o Ans: True
14. The digital value from ADC can be converted to voltage by:
o a) (ADC_value × Vref) / 1023
o Ans: True
15. How to convert voltage to temperature for LM35?
o a) Temperature (°C) = Voltage (mV) / 10
o Ans: True
16. The ADC clock frequency must be between:
o a) 50 kHz to 200 kHz
o Ans: True
17. Which prescaler is commonly used for ADC?
o a) 128
o Ans: True
18. The ADC input pins are multiplexed with:
o a) PORTA pins
o Ans: True
19. How do you enable ADC in ATmega32?
o a) Set ADEN bit in ADCSRA
o Ans: True
20. What is the function of the ADMUX register?
o a) Select ADC channel and reference
o Ans: True
21. What voltage supply is typically used to power ATmega32?
o a) 5V
o Ans: True
22. What is the unit of output of LM35?
o a) Volts
o b) mV
o Ans: b)
23. Which library header is necessary for delay functions?
o a) <util/delay.h>
o Ans: True
24. How many bits wide is the ADC result?
o a) 10 bits
o Ans: True
25. Which register must be checked to confirm ADC conversion complete?
o a) ADCSRA
o Ans: True
26. What type of sensor is LM35?
o a) Linear analog temperature sensor
o Ans: True
27. How do you read ADC value in C?
o a) ADC or (ADCL + (ADCH << 8))
o Ans: True
28. What is the effect of noise on ADC readings?
o a) Causes inaccurate values
o Ans: True
29. How to improve ADC reading accuracy?
o a) Use averaging and proper filtering
o Ans: True
30. What is Proteus used for in this experiment?
o a) Simulating hardware and ADC readings
o Ans: True
30 Gap Fillings
1. LM35 outputs voltage proportional to ______ → temperature
2. The output voltage changes by ______ mV per degree Celsius → 10
3. ATmega32 has a ______ bit ADC → 10
4. ADC input pins are on port ______ → A
5. The ADC reference voltage used is usually ______ V → 5
6. ADC conversion result is stored in ______ registers → ADCL and ADCH
7. To start ADC conversion, set the ______ bit in ADCSRA → ADSC
8. ADC conversion complete flag is ______ → ADIF
9. The LM35 sensor operates from voltage ______ V to ______ V → 4 to 30
10. The temperature is calculated by dividing voltage by ______ → 10
11. The ADC prescaler is set to ______ → 128
12. ADC clock frequency must be between ______ and ______ kHz → 50 and 200
13. The ADC is enabled by setting the ______ bit → ADEN
14. The function of ADMUX register is to select ______ and reference → channel
15. The ADC result resolution is ______ bits → 10
16. The analog input voltage must not exceed the ______ voltage → reference
17. LM35 sensor outputs voltage in ______ → millivolts
18. The sensor output is connected to ______ ADC channel → ADC0
19. To read ADC value, read ______ then ______ registers → ADCL, ADCH
20. The delay library used is ______ → util/delay.h
21. ADC conversion is started by setting ADSC bit to ______ → 1
22. The ADC conversion result is left or right adjusted using ______ bit → ADLAR
23. Noise can affect the accuracy of ______ → ADC readings
24. To get temperature in Celsius, convert ADC voltage and divide by ______ → 10
25. Proteus simulation is used to test ______ and output signals → hardware
26. The output of LM35 increases linearly with ______ → temperature
27. The ADC in ATmega32 uses a ______ reference voltage → voltage
28. The MCU used in this experiment is ______ → ATmega32
29. The sensor's output pin is connected to MCU's ______ pin → ADC0
30. The analog value is converted into digital by ______ → ADC
30 Short Questions (Code + Concept Mixed)
1. What type of sensor is LM35?
→ LM35 is an analog temperature sensor.
2. What is the output voltage change per °C for LM35?
→ 10 mV/°C
3. How is the analog signal from LM35 converted to digital in ATmega32?
→ Using the internal ADC.
4. Which ADC channel is used to connect LM35?
→ ADC0 (Pin PA0).
5. What is the resolution of the ATmega32 ADC?
→ 10 bits.
6. Write the code snippet to enable ADC in ATmega32.
c
Copy code
ADCSRA |= (1 << ADEN);
7. How do you start an ADC conversion?
c
Copy code
ADCSRA |= (1 << ADSC);
8. How do you check if ADC conversion is complete?
→ By checking if ADIF bit in ADCSRA is set.
9. How to read ADC value in code?
c
Copy code
uint16_t adc_value = ADC; // or (ADCL | (ADCH << 8));
10. How to convert ADC value to voltage?
→ Voltage = (ADC_value × Vref) / 1023.
11. How to convert voltage to temperature?
→ Temperature (°C) = Voltage (mV) / 10.
12. Why is a prescaler used for ADC clock?
→ To set ADC clock frequency within operational limits.
13. What prescaler value is used in this experiment?
→ 128.
14. Which register selects the ADC input channel?
→ ADMUX.
15. What is the function of the ADLAR bit?
→ Left adjust ADC result.
16. Why is the reference voltage important for ADC?
→ It defines the maximum measurable voltage.
17. How do you connect LM35 sensor to ATmega32 physically?
→ Output pin to ADC0, Vcc to 5V, GND to ground.
18. What happens if the input voltage exceeds reference voltage?
→ ADC reading saturates at max value.
19. How is noise minimized during ADC readings?
→ By using filtering and averaging multiple samples.
20. What is the typical supply voltage for LM35?
→ 5V.
21. What header files are needed for delay and ADC?
→ <util/delay.h>, <avr/io.h>.
22. What is Proteus simulation used for in this experiment?
→ To simulate sensor interface and ADC operation.
23. Write code to read ADC value and convert to temperature.
c
Copy code
uint16_t adc_value = ADC;
float voltage = (adc_value * 5.0) / 1023.0;
float temperature = voltage * 100; // since 10mV/°C
24. What is the advantage of using LM35?
→ It provides linear voltage output proportional to temperature.
25. How do you initialize ADC in ATmega32?
→ Set ADMUX, ADCSRA with prescaler and enable ADC.
26. Why use 10-bit ADC?
→ To achieve finer resolution of input voltage.
27. How can you display the temperature on LCD?
→ Convert temperature value to string and send to LCD.
28. What is the default state of ADC after reset?
→ Disabled.
29. How do you enable global interrupts if ADC interrupt is used?
→ Use sei();
30. What precautions are needed during ADC reading?
→ Avoid noise and stable input voltage.