Question 9.25: A switch is connected to pin P1.2. Write an 8051 C program t...

A switch is connected to pin P1.2. Write an 8051 C program to monitor SW and create the following frequencies on pin P1.7:
SW=0: 500Hz
SW=1: 750Hz, use Timer 0, mode 1 for both of them.

The blue check mark means that this solution has been answered and checked by an expert. This guarantees that the final answer is accurate.
Learn more on how we answer questions.
#include <reg51.h>
sbit   mybit=P1^5;
sbit   SW=P1^7;
void  T0M1Delay(unsigned char);
void  main(void){

SW=1;
while (1) {

mybit=~mybit;
if (SW==0)

T0M1Delay(0);

else

T0M1Delay(1);

}

}
. . . . .

. . . . .
void T0M1Delay(unsigned char c){

TMOD=0x01;
if (c==0) {

TL0=0x67;
TH0=0xFC;^{\nearrow ^{\fbox{FC67H = 64615 65536 – 64615 = 921 921 × 1.085 μs = 999.285 μs 1 / (999.285 μs × 2) = 500 Hz } } }

}
else {

TL0=0x9A;
TH0=0xFD;

}
TR0=1;
while (TF0==0);
TR0=0;
TF0=0;

}

Related Answered Questions

Question: 9.22

Verified Answer:

//tested for DS89C420, XTAL = 11.0592 MHz #include...
Question: 9.24

Verified Answer:

#include <reg51.h> void T1M2Delay(void); sbi...
Question: 9.6

Verified Answer:

In the timer delay calculation of Example 9-5, we ...