MIC Unit 2 Paper solution
MIC Unit 2 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
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.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)
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
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
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
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
}
}