Question

In: Computer Science

Q2. Write an 8051 C program that uses 3 temperature sensors (TS1, TS2, TS3),   3 LEDs...

Q2. Write an 8051 C program that uses 3 temperature sensors (TS1, TS2, TS3),   3 LEDs (GreenLED, BlueLED and RedLED) and 1 buzzer (BUZZ). Monitor the temperature sensors such that whenever any of the sensor goes high, the buzzer will produce a sound and at the same time, its corresponding LED blinks 3 times. You may use any of the I/O Port Pins.    
SOLUTION:
C PROGRAM

Solutions

Expert Solution

Here our task is to write a program which continously monitor the three sensor pins and blink the coressponding LED if any of it goes high ,

step1) we have to define 3 input pins for sensors and 4 output pins for Buzzer and leds

step2) check whether any of the sensor is high using if statement

step3) blink the corresponding led and turn on buzzer with help of delay function

This can be easily implemented in C as below

CODE

(Please read all comments for better understanding of the program)

I am also attaching the text version of the code in case you need to copy paste

#include<reg51.h> //calling reg51 header file from library

sbit TS1 = P2^1; //Defining sensor TS1 as pin1 at port 2

sbit TS2 = P2^2; //Defining sensor TS2 as pin2 at port 2

sbit TS3 = P2^3; //Defining sensor TS3 as pin3 at port 2


sbit LEDgreen = P3^1; //Defining LEDgreen as pin 1 port 3

sbit LEDblue = P3^2; //Defining LEDblue as pin 2 port 3

sbit LEDred = P3^3; //Defining LEDred as pin 1 port 3

sbit Buzzer = P3^4; //Defining Buzzer as pin 1 port 3


void Delay() //defining a delay function
{
int j;

inti;

for(i=0;i<100;i++) // by continous looping it will create a small
// delay in the runninmg of 8051
{

for(j=0;j<100;j++)

{

}


int main ()

{

P3 = 0x00; //P3 port is used as output

P2 = 0xFF; //P2 port is used as input

while(1) //craeting a loop that will run as long as 8051 is powered up

{


if(TS1 == 0) // this condition will be true when sensor TS1 id high

{
  
Buzzer=1; // turn on the Buzzer
  
for (int k=0;k<3;k++ ){ // loop which run 3 times
  
LEDgreen = 1 ; // turn on the green led

Delay(); //calling dely function to create a small delay

LEDgreen = 0 ; //turn on green led   

}
Buzzer=0; //turn of buzzer
}

}


if(TS2 == 0) // this condition will be tru when sensor TS2 id high

{
  
Buzzer=1; // turn on the Buzzer
  
for (int l=0;l<3;l++ ){ // loop which run 3 times
  
LEDblue = 1 ; // turn on the blue led

Delay(); //calling dely function to create a small delay

LEDblue = 0 ; //turn on blue led   

}
Buzzer=0; //turn of buzzer
}

}

if(TS3 == 0) // this condition will be true when sensor TS3 id high

{
  
Buzzer=1; // turn on the Buzzer
  
for (int m=0;m<3;m++ ){ // loop which run 3 times
  
LEDred = 1 ; // turn on the red led

Delay(); //calling dely function to create a small delay

LEDred = 0 ; //turn on red led   

}
Buzzer=0; //turn of buzzer
}

}


}

}


Related Solutions

Write a C program for a PIC18F4321 microcontroller to convert eight LM-34 temperature sensors, which are...
Write a C program for a PIC18F4321 microcontroller to convert eight LM-34 temperature sensors, which are connecte4d to AN0 to AN7, and display on a display consisting of two 7-segment displays. Use a three-bit switch to select one of the eight sensors to display.
Write a program that uses an array for time and temperature. The program should contain an...
Write a program that uses an array for time and temperature. The program should contain an array with 24 elements, each of which is holding a temperature for a single hour. Your program should have a function that lists all of the temperatures that are held in the array. Temperatures should be listed to console with one entry per line. Your program should have a function that lists a single temperature entry. You should ask the user for a number...
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at...
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at a rate of 1 Hz and the other at a rate of 2 HZ.
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
write a assembly language program to convert GRAY to BCD code in 8051
write a assembly language program to convert GRAY to BCD code in 8051
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
Write a C++ program that uses all the relational operators.
Write a C++ program that uses all the relational operators.
Write an assembly language program for 8051 microcontroller to find the sum of the following series,...
Write an assembly language program for 8051 microcontroller to find the sum of the following series, 1, -2, +3, -4, +5, -6,..., up to 100 terms. Store lower byte in R0 and higher byte in R1.
Write an 8051-assembly language program for the interfacing of ADC0804 and LM35 to display the room...
Write an 8051-assembly language program for the interfacing of ADC0804 and LM35 to display the room temperature on 16x2 LCD (10marks) please note that the program should be interfacing with ADC0804.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT