0% found this document useful (0 votes)
63 views8 pages

MIC Unit 2 Paper solution

Microcontroller Unit 2 SPPU Question paper solution

Uploaded by

ujwala darekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views8 pages

MIC Unit 2 Paper solution

Microcontroller Unit 2 SPPU Question paper solution

Uploaded by

ujwala darekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Previous SPPU Insem Question Paper Solution

Unit 2

Q.1) Draw an interacting diagram of DAC with 8051 and write an embedded C program
for generation of Triangular having frequency of 50Hz. [5] (Oct 2022)

#include <reg51.h>
#define DAC_PORT P1 // Define DAC connected to Port P1
#define STEP_DELAY 10 // Delay between steps (adjust for desired frequency)
// Constants for triangular waveform generation
#define MAX_DAC_VALUE 255 // Maximum DAC value for 8-bit resolution
#define MIN_DAC_VALUE 0 // Minimum DAC value
void delay(unsigned int ms) {
unsigned int i, j;
for (i = 0; i < ms; i++) {
for (j = 0; j < 1275; j++) {
// Delay loop
}
}
}
void main(void) {
unsigned char dac_value = MIN_DAC_VALUE;
unsigned char increment = 1
while (1) {
DAC_PORT = dac_value; // Output the current DAC value
delay(STEP_DELAY); // Wait for the next step
Previous SPPU Insem Question Paper Solution
Unit 2

// Update DAC value for triangular waveform


if (dac_value >= MAX_DAC_VALUE) {
increment = -1; // Start decreasing
} else if (dac_value <= MIN_DAC_VALUE) {
increment = 1; // Start increasing
}
dac_value += increment; // Update DAC value
}
}

Q.2) Write an embedded C program to rotate the stepper motor in clockwise direction
continuously with highest delay generated using timer 0 mode1. [5] (Oct 2022)
#include <reg51.h>
#define STEP_DELAY 50000 // Adjust this value for the delay between steps
// Define the four-step sequence for clockwise rotation
unsigned char step_sequence[4] = {0x01, 0x03, 0x02, 0x00};
unsigned char current_step = 0; // Current step in the sequence
void timer0_init(void) {
TMOD &= 0xF0; // Clear the Timer 0 mode bits
TMOD |= 0x01; // Set Timer 0 in Mode 1 (16-bit timer mode)
TH0 = (65536 - STEP_DELAY) >> 8; // Set the high byte of the timer
TL0 = (65536 - STEP_DELAY) & 0xFF; // Set the low byte of the timer
ET0 = 1; // Enable Timer 0 interrupts
TR0 = 1; // Start Timer 0
EA = 1; // Enable global interrupts
}
void timer0_ISR(void) interrupt 1 {
// Timer 0 interrupt service routine
TH0 = (65536 - STEP_DELAY) >> 8; // Reload Timer 0 high byte
TL0 = (65536 - STEP_DELAY) & 0xFF; // Reload Timer 0 low byte
P1 = step_sequence[current_step]; // Output the current step to port P1
current_step = (current_step + 1) % 4; // Move to the next step in the sequence
}
void main(void) {
timer0_init(); // Initialize Timer 0

while (1) {
// Main loop does nothing; Timer 0 ISR handles stepping
}
}

Q.3) Enlist features of 8051 microcontroller. [5] (Oct 2022)


An 8051 microcontroller comes bundled with the following features −
 4KB bytes on-chip program memory (ROM)
Previous SPPU Insem Question Paper Solution
Unit 2

 128 bytes on-chip data memory (RAM)


 Four register banks
 128 user defined software flags
 8-bit bidirectional data bus
 16-bit unidirectional address bus
 32 general purpose registers each of 8-bit
 16 bit Timers (usually 2, but may have more or less)
 Three internal and two external Interrupts
 Four 8-bit ports,(short model have two 8-bit ports)
 16-bit program counter and data pointer
 8051 may also have a number of special features such as UARTs, ADC, Op-amp, etc.

Q.4) Draw an interfacing of Opto-isolator with 8051 and write an embedded C program to
flash the bulb connected to its output. [5] (Oct 2022)

#include <reg51.h> // Header file for 8051 microcontroller


sbit optoInput = P2^0; // Define optoisolator input pin
sbit led = P3^0; // Define LED pin
void delay(unsigned int time) {
unsigned int i, j;
for(i = 0; i < time; i++)
for(j = 0; j < 1275; j++);
}
void main() {
while (1) {
Previous SPPU Insem Question Paper Solution
Unit 2

if (optoInput == 1) { // Check if optoisolator output is high


led = 1; // Turn on the LED
} else {
led = 0; // Turn off the LED
}
delay(100); // Small delay for stability
}}

Q.5) Design a DAS for the security purpose which include control of actions through Key,
status indication by LED connected to relay and opening of door stepper motor. Make
provision of buzzer to beep. [5] (Oct 2022)
Here’s a simple embedded C program to control the security system. This code assumes the
following:
 Keypad: Provides input to the microcontroller.
 Relay: Controlled by a digital output pin.
 LEDs: Indicate the system status.
 Stepper Motor: Controlled through a stepper motor driver.
 Buzzer: Activated for alerts.

#include <reg51.h>
#define RELAY P1_0 // Relay control pin
#define LED1 P1_1 // LED for armed status
#define LED2 P1_2 // LED for disarmed status
#define BUZZER P3_0 // Buzzer control pin
#define STEP_PIN0 P2_0 // Stepper Motor control pin 0
#define STEP_PIN1 P2_1 // Stepper Motor control pin 1
#define STEP_PIN2 P2_2 // Stepper Motor control pin 2
#define STEP_PIN3 P2_3 // Stepper Motor control pin 3

void delay(unsigned int ms) {


unsigned int i, j;
for (i = 0; i < ms; i++) {
for (j = 0; j < 1275; j++) {
// Delay loop
} }}
void stepper_motor_step(unsigned char step) {
// Example 4-step sequence
switch (step) {
case 0:
STEP_PIN0 = 1;
STEP_PIN1 = 0;
STEP_PIN2 = 0;
STEP_PIN3 = 0;
break;
Previous SPPU Insem Question Paper Solution
Unit 2

case 1:
STEP_PIN0 = 0;
STEP_PIN1 = 1;
STEP_PIN2 = 0;
STEP_PIN3 = 0;
break;
case 2:
STEP_PIN0 = 0;
STEP_PIN1 = 0;
STEP_PIN2 = 1;
STEP_PIN3 = 0;
break;
case 3:
STEP_PIN0 = 0;
STEP_PIN1 = 0;
STEP_PIN2 = 0;
STEP_PIN3 = 1;
break;
}}
void main(void) {
unsigned char step = 0;
// Initialization
RELAY = 0; // Relay off
LED1 = 0; // Armed status LED off
LED2 = 1; // Disarmed status LED on
BUZZER = 0; // Buzzer off
P2 = 0x00; // Initialize stepper motor pins to 0
while (1) {
// Check Keypad Input
// If a certain key is pressed, toggle system states or perform actions
if (/*Condition to arm system*/) {
LED1 = 1; // Turn on armed status LED
LED2 = 0; // Turn off disarmed status LED
RELAY = 1; // Activate relay to lock the door
// Control stepper motor to open the door
for (step = 0; step < 4; step++) {
stepper_motor_step(step);
delay(100); // Adjust delay for motor speed
}}
if (/*Condition to disarm system*/) {
LED1 = 0; // Turn off armed status LED
LED2 = 1; // Turn on disarmed status LED
RELAY = 0; // Deactivate relay to unlock the door
Previous SPPU Insem Question Paper Solution
Unit 2

// Control stepper motor to close the door


for (step = 0; step < 4; step++) {
stepper_motor_step(step);
delay(100); // Adjust delay for motor speed
}}
// Trigger buzzer for security alerts
if (/*Security breach detected*/) {
BUZZER = 1; // Turn on buzzer
delay(1000); // Buzzer duration
BUZZER = 0; // Turn off buzzer
}}}

Q.6) Write embedded C program to display HEX counter on LED connected to port 0. [7]
(Sep 2023)
#include <reg51.h>
void delay(unsigned int ms) {
unsigned int i, j;
for (i = 0; i < ms; i++) {
for (j = 0; j < 1275; j++) {
// Delay loop
}
}
}
void main(void) {
unsigned char counter = 0;

// Initialize Port 0
P0 = 0x00;
while (1) {
P0 = counter; // Output counter value to Port 0 (connected LEDs)
delay(500); // Delay to make the counter visible
counter++; // Increment counter
if (counter > 0x0F) { // Reset counter after 0x0F (15 in decimal)
counter = 0x00;
}
}
}

Q.7) Draw an interfacing diagram of stepper motor and write embedded C program to
rotate it clockwise continuously. [8] (Sep 2023)
#include <reg51.h>
#define STEP_PIN0 P1_0 // Stepper Motor Control Pin 0
#define STEP_PIN1 P1_1 // Stepper Motor Control Pin 1
#define STEP_PIN2 P1_2 // Stepper Motor Control Pin 2
Previous SPPU Insem Question Paper Solution
Unit 2

#define STEP_PIN3 P1_3 // Stepper Motor Control Pin 3


void delay(unsigned int ms) {
unsigned int i, j;
for (i = 0; i < ms; i++) {
for (j = 0; j < 1275; j++) {
// Delay loop
} }}
void stepper_motor_step(unsigned char step) {
// Example 4-step sequence for a stepper motor
switch (step) {
case 0:
STEP_PIN0 = 1; STEP_PIN1 = 0; STEP_PIN2 = 0; STEP_PIN3 = 0; break;
case 1:
STEP_PIN0 = 0; STEP_PIN1 = 1; STEP_PIN2 = 0; STEP_PIN3 = 0; break;
case 2:
STEP_PIN0 = 0; STEP_PIN1 = 0; STEP_PIN2 = 1; STEP_PIN3 = 0; break;
case 3:
STEP_PIN0 = 0; STEP_PIN1 = 0; STEP_PIN2 = 0; STEP_PIN3 = 1; break;
}}
void main(void) {
unsigned char step = 0; // Initialize stepper motor pins
P2 = 0x00;
while (1) {
// Rotate stepper motor clockwise
stepper_motor_step(step);
step = (step + 1) % 4; // Move to the next step
delay(100); // Adjust the delay for desired speed
}}
Previous SPPU Insem Question Paper Solution
Unit 2

Q.8) Draw an interfacing diagram to glow the lamp connected to Relay at Port pin P1.1
and write embedded C program to make it ON and OFF. [7] (Sep 2023)
#include <reg51.h>
#define RELAY P1_1 // Define relay control pin
void delay(unsigned int ms) {
unsigned int i, j;
for (i = 0; i < ms; i++) {
for (j = 0; j < 1275; j++) {
// Delay loop
}
}
}
void main(void) {
// Initialize the relay control pin as output
P1 = 0x00; // Set all Port 1 pins to 0 (or configure as needed)
while (1) {
RELAY = 1; // Turn on the lamp (relay energized)
delay(1000); // Lamp ON duration
RELAY = 0; // Turn off the lamp (relay de-energized)
delay(1000); // Lamp OFF duration
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy