FMA All Unit Imp (Question & Answers - Merged
FMA All Unit Imp (Question & Answers - Merged
Ans 1.
1. Unsigned Char: The unsigned char is an 8-bit data type. Thus, it must be
use to store the value in the range of 0-255 (00H-FFH). Since the 8051 is
an 8-bit microcontroller, it is the one of the most widely used data type.
2. Signed Char: The signed char is an 8-bit data type that uses the most
significant bit (D7 of D7 – DO) to represent the – or + value. As a result,
only 7 bits are there for the magnitude of the signed number, giving us
values from -128 to +127.
3. Unsigned int: The unsigned int is a 16-bit data type that takes a value in
the range of 0 to 65535 (0000 – FFFFH). In the 8051, unsigned int is used
to define 16-bit variables such as memory addresses. It is also used to set
counter values of more than 256. Since the 8051 is an 8-bit
microcontroller and the int data type takes two bytes of RAM, the int data
type must not be used, unless it is required. Since registers and memory
accesses are in 8-bit chunks, the misuse of int variables will result in a
larger hex file.The compiler will not generate an error for this misuse, but
the overhead in hex file size is noticeable.
4. Signed int: Signed int is a 16-bit data type that uses the most significant
bit (D15 of D15 – DO) to represent the – or + value. As a result, only 15 bits
are remaining for the magnitude of the number, or values from -32,768 to
+32,767.
5. Sbit (single bit): The sbit keyword is a widely used 8051 C data type
designed specifically to access single-bit addressable registers. It allows
access to the single bits of the SFR registers. Among the SFRs that are
widely used and are also bit-addressable are ports PO -P3. We can use sbit
to access the individual bits of the ports
6. Bit: The bit data type allows access to single bits of bit-addressable
memory spaces 20 – 2FH. While the sbit data type is used for bit-
addressable SFRs, the bit data type is used for the bit-addressable section
of RAM space 20 -2FH.
7. sfr: To access the byte-size SFR registers, we use the sfr data type.
Q4. Explain the function of bit TF0 in TCON register and write a program in
C language to start timer 0
Ans4. TF0 is timer 0 overflow flag. It is set by hardware when timer/counter 0
overflows. It is 5th bit of TCON register, TCON.5
#include <reg51.h>
void main (void)
{
TR0 = 1;
}
Q5. Write a program in C language to copy the contents of Port 2 to Port 1.
Solution 5.
#include<reg51.h>
void main(void)
{
unsigned char x;
P2 = 0XFF;
x = P2;
P1 = x;
}
Calculation :
Frequency = 125 Hz
Time = (1/125) = 8*(10^-3)sec = 8 msec
Time period of full square wave = 8msec
Timer period of half wave = 4msec (8/2)
Clock pulse needed to be counted by timer to give the delay of 4msec is =
(4msec/1.085usec) = 3686.63=3686
Q7. Write a program to generate square wave of 50Hz frequency with 50%
duty cycle on pin 2.3. Assume XTAL=11.0592 MHz & use timer 0 in
mode l.
Ans 7.
#include<reg51.h>
sbit wave=P2^3;
void main(void)
{
while(1)
{
Wave=0;
TMOD= 0X ;(for timer 0 mode1 find the value)
TL0 = ; (find the value doing calculation)
TH0= ; (find the value doing calculation
TR0 = 1;
While(TF0==0);
TR0=0;
TF0=0;
wave = ~ wave;
}
}
Calculation :
Frequency = 50 Hz
Time = (1/50) = sec ( find the value)
Time period of full square wave = msec ( find the value)
Timer period of half wave = msec ( find the value)
Clock pulse needed to be counted by timer to give the delay of msec ( find the
value) is = (find the value/1.085usec) = find the value
Explanation of bits :
1) TF1 (TCON.7 ) – Timer 1 overflow flag. It is set by hardware to 1 when
timer/counter counts form all 1s to 0s(overflow). For e.g : when timer 1 in
mode 1 rolls from FFFFH to 0000H, TF1 becomes equals to 1.
It serves as an interrupt for timer 1. Memory location 001BH in the
interrupt vector table belongs to Timer 1 interrupt.
Q9. Write C Program to toggle bit P1.5 of port P1, 5000 times.
Ans9.
#include<reg51.h>
sbit mybit = P1^5;
void main(void)
{
unsigned int z;
for (z=0; z<5000; z++)
{
mybit = ~ mybit;
}
}
Q10. Write a program in C to toggle all bits of Port 1
Ans 10.
#include<reg51.h>
void main(void)
{
P1=~P1;
}
Q11. Write a 8051 C program to toggle only bit P2.4 continuously without
disturbing any other bit of port 2.
Ans 11.
#include<reg51.h>
sbit P2_4 = P2^4;
void main(void)
{
while (1)
{
P2_4 =~ P2_4;
}
}
Q12. Write a program in C language to toggle only bit P1.5 of port P1 ,
50000 times.
Ans12. Refer answer 9.
Q13. Explain Timer mode 0 & mode 1 of 8051 microcontroller.
Answer 13.
• Timer Mode 1: It is a 16-bit timer; therefore, it allows values from 0000 to
FFFFH to be loaded into the timer’s registers TL and TH. After TH and TL
are loaded with a 16-bit initial value, the timer must be started by
instruction TR1/TR0 =1. After the timer is started. It starts count up until
it reaches its limit of FFFFH. When it rolls over from FFFF to 0000H, it sets
high a flag bit called TF (timer flag). This timer flag can be monitored. After
the timer reaches its limit and rolls over, in order to repeat the process the
registers TH and TL must be reloaded with the original value and TF must
be reset to 0.
• Timer Mode 0: Mode 0 is exactly same like mode 1 except that it is a 13-bit
timer instead of 16-bit. It can hold values between 0000 to 1FFFH in TH-
TL. When the timer reaches its maximum of 1FFFH, it rolls over to 0000,
and TF is raised.
• Timer Mode 2: It is an 8 bit timer that allows only values of 00 to FFH to be
loaded into the timer’s register TH. After TH is loaded with 8 bit value, the
8051 gives a copy of it to TL. Then the timer must be started. It is done by
the instruction “TR0=1” for timer 0 and “TR1=1” for timer1.
• After timer is started, it starts to count up by incrementing the TL register.
It counts up until it reaches its limit of FFH. When it rolls over from FFH
to 00. It sets high the TF (timer flag). If we are using timer 0, TF0 goes
high; if using TF1 then TF1 is raised.
• When Tl register rolls from FFH to 00 and TF is set to 1, TL is reloaded
automatically with the original value kept by the TH register.
• To repeat the process, we must simply clear TF and let it go without any
need by the programmer to reload the original value.
• This makes mode 2 auto reload, in contrast in mode 1 in which
programmer has to reload TH and TL
Ans 16.
#include<reg51.h>
void delay(void);
sbit P1_5 = P1^5;
void main(void)
{
P1_5 =~ P1_5;
delay();
}
Void delay(void)
{
TMOD = 0X01;
TL0 = 0XB0;
TH0 = 0X3C;
TR0 = 1;
while(TF0==0);
TF0 = 0;
TR0 = 0;
}
Q1. Write a short note on interrupt structure of 8051.
Ans1. There are six types of interrupts in 8051:
Timer Interrupts:
1) Timer 0 (TF0)
2) Timer 1 (TF1)
External Hardware Interrupts:
3) INT 0
4) INT 1
Serial Communication Interrupts:
5) Receive and Transmit Interrupts (RI & TI)
6) Reset Interrupt
• In ROM, fixed amount of space, and a memory address is given to each interrupt, hence
when an interrupt occurs microcontroller jumps to that particular address of the
interrupts in the memory.
Following are the address allotted to the interrupts where interrupt program (ISR) is
saved and is called ad INTERRUPT VECTOR TABLE
Reset 0000
INT 0 0003
TF0 000B
INT 1 0013
TF1 001B
RI & TI 0023
• The timer and serial interrupts are internally produced by the microcontroller.
• The external interrupts are produced by additional interfacing devices or
switches that are externally connected with the microcontroller at pin no.
12(P3.2) and pin no. 13(P3.3)
• These external interrupts can be level triggered or edge triggered and are called
as hardware interrupts.
• SFRs involved with interrupts are as follows:
• Interrupt Enable Register (IE) : It is used to enable or disable any interrupt.
• Interrupt Priority Register (IP) : It is used to change the priority levels of the
interrupt i. e. which interrupt will be executed first.
• Timer Control Register (TCON) : Used to monitor Timer Interrupts and
External Hardware Interrupts.
Q2. Write a program in C language to enable hardware interrupts INT0 and INT1.
Ans 2.
#include < reg51.h>
void main(void)
{
IE=0X85;
}
Q3. Write down the steps to program ADC 0809.
Ans 3. Following are the steps to program ADC 0809
1) Select the analog channel by providing bits to A, B, and C address according to
following table:
Selected C B A
Analog
Channel
IN0 0 0 0
IN1 0 0 1
IN2 0 1 0
IN3 0 1 1
IN4 1 0 0
IN5 1 0 1
IN6 1 1 0
IN7 1 1 1
2) Activate the ALE (Address Latch Enable) pin. It needs a L to H pulse to latch in the
address.
3) Activate SC (Start of Conversion) by an L to H pulse to initiate the conversion.
4) Monitor EOC (end of conversion) to see whether conversion is finished. H to L
output indicates that the data is converted and is ready to be picked up. If we do
not use EOC, we can read the converted digital data after a brief time delay.
5) Activate OE (output enable) to read data out of the ADC chip. A L to H pulse to the
OE pin will bring digital data out of the chip. OE is same as RD pin in other ADC
chip.
Q4. Draw the IE register and explain the functions of bits EA, ET0 and EX0.
Ans 4.
Interrupt Enable Register (IE)
• Upon reset all interrupts are disabled (masked). They must be enabled by
software by using IE register for the microcontroller to respond to them. This
register is responsible for enabling (unmasking) and disabling (masking) the
interrupts. It is a bit addressable register.
• EA (IE.7) : It is called as Enable all . If EA =1, all interrupts are enabled, if EA =0 ,
no interrupt will be responded , even if the associated bit in the IE register is
high.
• IE. 6 : Not implemented, reserved for future use.
• ET2(IE.5) : Enables or disables timer 2 overflow.
• ES (IE.4) : Enables or disables the serial port interrupt.
• ET1 (IE.3) : Enables or disables the timer 1 overflow interrupt.
• EX1 (IE.2) : Enables or disables the external interrupt 1.
• ET1 (IE.1) : Enables or disables the timer 0 overflow interrupt.
• EX0 (IE.0) : Enables or disables the external interrupt 0.
Q5. Write down the steps in executing on an interrupt.
Ans 5. Steps followed by 8051 while occurrence of an Interrupt
1) It finishes the instruction it is executing and saves the address of the next
instruction (PC) on the stack.
2) It also saves the current status of all the interrupts internally (i.e. not on the
stack).
3) It jumps to a fixed location in memory called the interrupt vector table that
holds the address of the interrupt service routine.
4) The microcontroller gets the address of the ISR from the interrupt vector
table and jumps to it. It starts to execute the interrupt service subroutine
until it reaches the last instruction of the subroutine which is RETI (return
from interrupt).
5) After executing RETI instruction, the microcontroller returns to the place
where it was interrupted. First, it gets the program counter (PC) address
from the stack by popping the top two bytes of the stack into the PC.
Then it starts to execute from that address.
Q6. Draw and explain interfacing diagram of ADC with 8051.
Ans 6.
Microcontroller sends a LOW to HIGH level signal to ALE pin (its active-high pin) of ADC
to enable the latch in the address.
By applying HIGH to LOW Level signal to SC (Start Conversion), ADC starts analog to
digital conversion.
EOC (end of conversion) pin is monitored to see whether the conversion is finished. H
to L output indicates that the data is converted and is ready to be picked up.
After this, microcontroller enables the output line by applying a LOW to HIGH signal to
OE pin of ADC0809.
Q7. Explain interrupt structure of 8051 microcontroller with neat diagram
Ans 7. Same as answer 1,
Q8. Explain Interrupt Priority Register of 8051 Microcontroller.
Ans 8. Interrupt Priority Register (IP)
• The priorities are assigned to the interrupts to decide which interrupt will be
executed if more than one interrupts are activated at the same time.
• The following table shows the interrupt priority
Priority bit = 1 assigns high priority. Priority bit = 0 assigns low priority.
-- IP.7 : Reserved
-- IP.6 : Reserved
PT2 IP.5 : Timer 2 interrupt priority bit(8052 only)
PS IP. 4 : Serial port interrupt priority bit
PT1 IP.3 : Timer 1 interrupt priority bit
PX1 IP.2 : External interrupt 1 priority bit
PT0 IP.1 : Timer 0 interrupt priority bit
PX0 IP.0 : External interrupt 0 priority bit
5 0
0 1 0 1 0 0 0 0
Q2. Write down a short note on interfacing of a GSM module with 8051
microcontroller.
GSM stands for Global System for Mobile Communication. It is a digital cellular
technology used for transmitting mobile voice and data services.
The idea of GSM was developed at Bell Laboratories in 1970. It is a widely used
mobile communication system in the world. GSM is an open and digital cellular
technology used for transmitting mobile voice and data services operate at the
850MHz, 900MHz, 1800MHz, and 1900MHz frequency bands.
GSM module is a device or chip that uses GSM network to establish communication
between electronic devices.
GSM is a standard developed by standard developed by the European
Telecommunications Standards Institute (ETSI).
To communicate with GSM modem, AT commands are required.
Microcontroller sends these commands to the GSM modem, which is then
activated to perform the required operation.
RXD pin of 8051 microcontroller is connected to TXD pin of GSM module and
TXD pin of 8051 microcontroller is connected to RXD pin of GSM module.
AT commands with a GSM modem can be used to access following information and
services:
1. Information and configuration pertaining to MODEM and SIM card.
2. SMS services.
3. MMS services.
4. Fax services.
5. Data and Voice link over mobile network.
Q3. Write a program to transfer a character “P” serially at baud rate of 9600, Use
serial port in Mode 1. Crystal frequency is 11.0592 MHz
Q4. Draw the SCON register and explain use of individual bits of the register in
detail./Write a short note on SCON register.
Ans 4. SCON register is an 8-bit register used to program the start bit, stop bit, and
data bits of data framing , among other things.
SM0 and SM1 are D7 and D6 of SCON register, respectively. These two bits
determine the framing of data by specifying the number of bits per character, and
the start and stop bits. They take the following combinations
Modes of serial communication
SM0 SM1
0 0 Serial Mode 0
0 1 Serial Mode 1, 8-bit data, 1 stop bit , 1 start bit
1 0 Serial Mode 2
1 1 Serial Mode 3
In serial mode 1, for each character a total of 10 bits are transferred , where the
first bit is the start bit , followed by 8 bits of data, and finally 1 stop bit.
SM2
It is the 5th bit of the SCON register. It enables the multiprocessing capability. It will
be set to 0, since it is not used.
REN
It is D4 bit of SCON register called as receive enable. When REN =1, 8051 receives
data on the RxD pin. If REN =0, the receiver is disabled. REN must be set to 1 , in
case of both receive and transfer data.
TB8
TB8(Transfer bit 8) is bit D3 of SCON. It is used for serial mode 2 and 3. It is not
used in our applications, hence it is made as 0.
RB8
RB8(receive bit 8) is bit D2 of SCON. It is used for serial mode 2 and 3. It is not used
in our applications, hence it is made as 0.
TI
TI(Transmit Interrupt) is bit D1 of SCON register, When 8051 finishes the transfer
of the 8-bit character, it raises the TI flag to indicate that it is ready to transfer
another byte. The TI bit is raised at the beginning of the stop bit.
RI
RI(receive interrupt) is bit D0 of SCON register, When 8051 receives data serially
via RxD, it get rid of the start and stop bits and places the byte in the SBUF register.
Then it raises the RI flag bit to indicate that a byte has been received and should be
picked up before it is lost. RI is raised hallway through the stop bit.
5 0
0 1 0 1 0 0 0 0
#include<reg51.h>
void main(void)
{
unsigned char z;
z=0;
TMOD = 0X20;
TH1=0XFA;
SCON = 0X50;
TR1=1;
while(z<10)
{
SBUF ='T';
while(TI==0);
TI=0;
z++;
}
}
Q8. Write short note AT commands required for GSM.
Classification of AT commands
Examples of AT commands
SBUF register :
SBUF is an 8-bit register used for serial communication. For a byte of data to be
transferred via TxD line, it must be placed in the SBUF register. Similarly SBUF holds the
byte of data when it is received by the 8051’s RxD line.
SCON register:
Timer registers
Serial Communication registers of 8051 are programmed to transfer and receive data
serially.
Q10. Explain how Baud Rate is set for serial communication in 8051
microcontroller.
Ans10. The rate of data transfer in serial data communication is stated in bits per
second(bps) and is also called as baud rate. Baud rate is programable and is done with
the help of timer 1 in mode 2, that is 8-bit auto reload. 8051 divides the crystal frequency
by 12 to get the machine cycle frequency. If XTAL = 11.0592 MHz, the machine cycle
frequency is 921.6 kHz (11.0592MHz/12). The 8051’s serial communication UART
circuitry divides the machine cycle frequency of 921.6 kHz by 32 once more before it is
used by Timer 1 to set the baud rate. Therefore, 921.6 kHz divided by 32 gives 28,800 Hz.
For e.g : To set the baud rate of 9600, following calculations need to be performed:
Q11. Write a program to transfer a character “A” serially at baud rate of 4800, Use
serial port in mode 1. Crystal frequency is 11.0592 MHz
Q12. Assuming crystal frequency of 11.0592 MHz, find the value to be loaded in
TH1 to set up the following baud rates 1) 9600 2) 2400 3) 1200
Q2. Draw an interfacing diagram of stepper motor with 8051. Assuming the
motor is controlled through most significant 4 bits of port 1. Write a program in
C language to run the stepper motor continuously in anticlockwise direction.
Assume suitable step sequence.
Ans 2.
• While a conventional motor shaft runs freely, the stepper motor shaft moves in
a fixed repeat-able increment. The stepper motor discussed here has a total of 6
leads: 4 leads representing the four stator windings and 2 commons for the
center-tapped leads. As the sequence of power is applied to each stator
winding, the rotor will rotate. since the 8051 lacks sufficient current to drive
the stepper motor windings, we must use a driver such as the ULN2003 to
energize the stator.
• Below table shows a 2-phase, 4-step stepping sequence.
•
# include<reg51.h>
void delay(unsigned int);
void main(void)
{
while(1)
{
P1 = 0x60;
delay(10);
P1 = 0x30;
delay(10);
P1 = 0x90;
delay(10);
P1 = 0xC0;
delay(10);
}
}
void delay(unsigned int time)
{
unsigned int i, j;
for(i=0; i<time; i++)
for(j=0; j<1275; j++);
}
Q3. Explain the function of an electromechanical relay and draw an interfacing
diagram of relay with microcontroller 8051 with suitable driver circuit.
Relays are the switches which aim at closing and opening the circuits electronically as
well as electromechanically. It controls the opening and closing of the circuit contacts
of an electronic circuit. When the relay contact is open (NO), the relay isn’t energize
with the open contact. However, if it is closed (NC), the relay isn’t energize given the
closed contact
Q4. Draw and explain interfacing of LED in common anode and common
cathode configurations. Write a program in C language for blinking display
of a LED connected to port pin P1.0. Use a suitable delay.
LED is a PN Junction diode which emits light when activated. It is activated when its
positive terminal is connected to positive supply and negative terminal is connected to
ground. In the following diagram, LED is connected to Port 2.0 pin.
LEDs need approximately voltage drop of 1.7 V and 10 mA current to flow through
them in order to glow at maximum intensity.
In this circuit, LEDs are connected to the port P0. Since, it is common cathode
configuration, anode terminal of LEDs are connected to port 0 and all cathode
terminals are connected together to ground. The controller is connected with external
crystal oscillator to pin 18 and 19 pins. Crystal pins are connected to the ground
through capacitors of 33pf. LED is connected to the AT89C51 microcontroller with the
help of a current limiting resistor.
Ans 5. LED is a PN Junction diode which emits light when activated. It is activated
when its positive terminal is connected to positive supply and negative terminal is
connected to ground. In the following diagram, LED cathode terminal is connected to
Port 2.0 pin and anode is connected to Vcc supply. A program is written to turn on and
off LED with some time delay.
Ans 5.
Q6. With the help of block diagram explain Key interfacing using 8051.
Ans 6. In the following diagram, Key is like a switch which is used to control the LED
on and off operation. Key is connected to Port 0.0 pin, LED cathode terminal is
connected to Port 2.0 pin and anode terminal is connected to Vcc supply through
resistance R3. When key is pressed, 0 gets input into Port 0.0 pin, and Port 2.0 pin
gives output as 0 which turns on the LED. A program is written to turn on the LED
when key is pressed.
#include<reg51.h>
sbit switch = P0^0;
sbit Led = P2^0;
void main (void)
{
switch = 1;
if (switch==0)
{
Led = 0;
}
else
{
Led = 1;
}
}
Q7. With the help of block diagram explain Power measurement using 8051.
Q9. Draw interfacing diagram of a stepper motor with 8051 and write program
to rotate stepper motor 360 Degree in anticlockwise direction with step angle of
1.8 degree.
Ans 9. Refer Answer 12, also above program has been solved in class.
Q10. Draw interfacing diagram of stepper motor with 8051 and Write a C
program to rotate stepper motor in forward, reverse direction.
Ans10.
Program for clockwise(forward rotation)
# include<reg51.h>
void delay(unsigned int);
void main(void)
{
while(1)
{
P1 = 0x66;
delay(10);
P1 = 0xCC;
delay(10);
P1 = 0x99;
delay(10);
P1 = 0x33;
delay(10);
}
}
void delay(unsigned int time)
{
unsigned int i, j;
for(i=0; i<time; i++)
for(j=0; j<1275; j++);
}
Program for anticlockwise rotation(reverse rotation)
# include<reg51.h>
void delay(unsigned int);
void main(void)
{
while(1)
{
P1 = 0x66;
delay(10);
P1 = 0x33;
delay(10);
P1 = 0x99;
delay(10);
P1 = 0xCC;
delay(10);
}
}
void delay(unsigned int time)
{
unsigned int i, j;
for(i=0; i<time; i++)
for(j=0; j<1275; j++);
}
Q12. Write a program to rotate a motor 64° in the clockwise direction. The
motor has a step angle of 2°. Use the normal 4 step sequence.
Ans 12.
# include<reg51.h>
void delay(unsigned int);
void main(void)
{
unsigned char x = 0;
while(x<8)
{
P1 = 0x66;
delay(10);
P1 = 0xCC;
delay(10);
P1 = 0x99;
delay(10);
P1 = 0x33;
delay(10);
x++;
}
}
void delay(unsigned int time)
{
unsigned int i, j;
for(i=0; i<time; i++)
for(j=0; j<1275; j++);
}
Q13.What is step angle? Calculate the steps required to complete one revolution
for 1.2 degree step angle stepper motor.
Ans 13. The step angle is the minimum degree of rotation associated with a
single step.
• Steps per revolution is the total number of steps needed to rotate one
complete rotation or 360 degrees
• Steps required to complete one revolution for 1.2 degrees = 360/1.2 = 300
Ans 14. Relays are used to protect the electrical system and to minimize the damage to
the equipment connected in the system due to over currents/voltages. The relay is
used for the purpose of protection of the equipment connected with it.
These are used to control the high voltage circuit with low voltage signal in
applications audio amplifiers and some types of modems.
These are used to control a high current circuit by a low current signal in the
applications like starter solenoid in automobile. These can detect and isolate the faults
that occurred in power transmission and distribution system. Typical application
areas of the relays include
Industrial Automation
Power relays are extensively used in industrial automation to control motors, pumps,
fans, and various machine
Home Appliances
In the realm of home appliances, power relays play a vital role in regulating heating
elements, motors, and compressors. They are responsible for the reliable on-off
switching of devices such as ovens, refrigerators, and washing machines.
HVAC Systems
Heating, ventilation, and air conditioning (HVAC) systems rely on power relays to
control the operation of heaters, fans, and air conditioning units.
Power relays are integrated into security systems to control access points, alarms, and
surveillance equipment.
Automotive Industry
In the automotive sector, power relays control various components such as starter
motors, headlights, windshield wipers, and power windows.
Energy Distribution: Power relays are used in energy distribution systems to control
circuit breakers and switchgear. They ensure the safe and efficient distribution of
electricity within power grids and substations.
Q15. With the help of block diagram explain voltage and current measurement
using 8051.
Q16. Draw an interfacing diagram of stepper motor with 8051. Assuming the
motor is controlled through least significant 4 bits of port 2, assuming the step
angle of motor is 1.8 degrees, Write a program in C language to run the stepper
motor in anticlockwise direction through an angle of 7.2 degrees. Assume
suitable step sequence.
Ans 17.
#include<reg51.h>
sbit switch = P2^0;
sbit Led =P1^3;
void main (void)
{
switch = 1;
if (switch==0)
{
Led = 0;
}
else
{
Led = 1;
}
}