Question

Using uVison: Write a C program that generates a 1 second square wave on Pin 2...

Using uVison: Write a C program that generates a 1 second square wave on Pin 2 Port B. Using generated signal from that Pin 2, as an input to Pin 3 Port B drive the red LED at the same rate and the Blue LED at half the rate of the Red LED.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I m writing this program for 8051 microcontroller

#include<reg51.h>
void T0M1Delay(void);
sbit mybit=P2^2;
sbit LED=P2^3;

getting input from P2^2
unsignedint i; //data type
void main(void)
{
while(1)
{
mybit=~mybit; //for generation of square wave
RLED=~RLED; //Red led as per the square wave it will be on and off

for(i=0;i<28;i++)
{
T0M1Delay() ; //this is to provide the delay of 1 sec which is required
}
}
BLED=~BLED; //for blue led we want half time
for(i=0;i<14;i++)
{
T0M1Delay() ;//this is to provide half the time delay
}

}
This loop should repeat 28 times to get the delay of 1 sec

void T0M1Delay(void)
{
TMOD=0×01; //timer 0 in mode 1
TL0=0×00; //load the value of TL0
TH0=0×00; //load the value of TH0
TR0=1; //start timer
while(TF0==0); //wait untill TF0 becomes 0
TR0=0;
TF0=0;
}
XTAL frequency=22MHz
so the maximum delay with this crystal frequency is 37.75ms
to get 1 sec delay we take a loop which runs 28 times
=28*35.75
=1000ms=1sec

Add a comment
Know the answer?
Add Answer to:
Using uVison: Write a C program that generates a 1 second square wave on Pin 2...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT