Question

In: Computer Science

1) Write an 8051 C program that will simulate a traffic light. Green will turn on...

1) Write an 8051 C program that will simulate a traffic light. Green will turn on for 2 seconds, Yellow for 1 second and Red for 2 seconds. The green, yellow and red LEDs are connected to Ports P11, P12 and P13.

2) Write an 8051 C program that will turn on or turn off an LED using a switch. The LED is connected to Port P15 while the switch is connected to Port P11.

Solutions

Expert Solution

solution:

1.

C program to simulate a traffic light :

Give :

Port P1.1 : connect Green LED

Port P1.2 : connect Yellow LED

Port P1.3 : connect Red LED

Delay : 2 sec for green , 1 sec for yellow , 2 sec for red

Code:

#include<reg51.h>

sbit greenLed=P1^1; //Led connected to port-1 pin#1

sbit yellowLed=P1^2; //Led connected to port-1 pin#2

sbit redLed=P1^3; //Led connected to port-1 pin#3

void delay()
{
int count=0;
while(count!=500)
{
   TMOD=0x01; //16-bit timer0 selected
   TH0=0xF8;   // Loading high byte in TH
   TL0=0xCC;   // Loaded low byte in TL
   TR0=1;      // Running the timer
    while(!TF0);   //Checking the timer flag register if it is not equal to 1
   TR0 = 0;      // If TF0=1 stop the timer
   TF0 = 0;      // Clear the Timer Flag bit for next calculation

   count++;
}

}

void main()
{
P1=0x00;   //Port-1 Declared Output

while(1)     // Constantly running while loop.
{
greenLed=1;    // Green LED glows here
yellowLed =0; //Yellow LED off
redLed = 0; // Red LED off

delay(); // Delay for 1 second
delay(); // Delay for 1 second

greenLed=0;    // Green LED off
yellowLed =1; //Yellow LED glows here
redLed = 0; // Red LED off

delay(); // Delay for 1 second

greenLed=0;    // Green LED off
yellowLed =0; //Yellow LED off
redLed = 1; // Red LED glows here

delay(); // Delay for 1 second
delay(); // Delay for 1 second

}
}

please give me thumb up


Related Solutions

Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
*****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...
please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program...
Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program to schedule disk in seek optimization.
Write a c++ Program To simulate the messages sent by the various IoT devices, a text...
Write a c++ Program To simulate the messages sent by the various IoT devices, a text le called device data.txt is provided that contains a number of device messages sent, with each line representing a distinct message. Each message contains a device name, a status value and a Unix epoch value which are separated by commas. Your c++ program will read this le line by line. It will separate the message into device name, status value and epoch value and...
In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling...
In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling algorithm. It should implement threads for the algorithm plus the main thread using a linked list to represent the list of jobs available to run. Each node will represent a Job with the following information: int ProcessID int time time needed to finish executing The thread representing the scheduler algorithm should continue running until all jobs end. This is simulated using the time variable...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single 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 is equal to 7 or 11, the player wins immediately....
Write a C/C++ program that simulate a menu based binary numbercalculator. This calculate shall have...
Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities:Covert a binary string to corresponding positive integersConvert a positive integer to its binary representationAdd two binary numbers, both numbers are represented as a string of 0s and 1sTo reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the following three functions:int binary_to_decimal(string...
A traffic light at a certain intersection is green 50% of the time,yellow 10% of the...
A traffic light at a certain intersection is green 50% of the time,yellow 10% of the time, and red 40% of the time. A car approaches this intersection once each day. We would like to know about the number of days that pass up to and including the first time the car encounters a red light. Assume that each day represents an independent trial. a) Define the random variable of interest, it support, and parameter values. b) What is the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT