




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Problem Statement 1: Write an Assembly Language Program(for 8051) to add 2 16-bit numbers, 0xFC45 and 0x02EC.
Tool Used: Keil μVision C
Flowchart:
Start
Clear carry bit
Move lower byte of first number to Accumulator
Add lower byte of second number to Accumulator
Save result to R
Move higher byte of first number to Accumulator
Add lower byte of second number to Accumulator along with the Carry
Save result to R
Stop
v o i d main ( ) { w h i l e ( 1 ) { output1 = ˜ i n p u t ; output2 = i n p u t ; } }
Result: When P1.0 is turned ON, P2.0 is OFF and P3.0 is ON and when P1.0 is OFF, P2.0 is ON and P3. is OFF.
Problem Statement 3: Write an Embedded C program(for 8051) such that a switch is connected to the pin P1.0; when P1. is turned ON, PORT2(all pins) is OFF and PORT3(all pins) is ON and when P1.0 is OFF, PORT2(all pins) is ON and PORT3(all pins) is OFF. ON and OFF indicates the state of a pin.
Tool Used: Keil μVision C
Flowchart:
Start
Read P1.
Clear PORT2, Set PORT3 (^) P1.0 =? Set PORT2, Clear PORT
Program:
#i n c l u d e <r e g 5 1. h>
s b i t i n p u t = P1 ˆ 0 ;
v o i d main ( ) { P2 = 0xFF ; %s e t P2 as output p o r t P3 = 0xFF ; %s e t P3 as output p o r t
w h i l e ( 1 ) { i f ( i n p u t = = 1 ) { P2 = 0 ; P3 = 0xFF ; } e l s e { P2 = 0xFF ; P3 = 0 ; } } }
Result: When P1.0 is turned ON, PORT2(all pins) is OFF and PORT3(all pins) is ON and when P1.0 is OFF, PORT2(all pins) is ON and PORT3(all pins) is OFF. ON and OFF indicates the state of a pin.
Problem Statement 4: Write an Embedded C program(for 8051) such that if P1.0 is ON, P3.1 turns ON after a 30sec delay, remains ON for 30sec and then turns OFF; if P1.0 is OFF, P3.2 is ON. Also P3.1 is always in the complimented state of P3.2.
Tool Used: Keil μVision C
Flowchart:
Start
Read P1.
Wait 30 sec
Set P3.2, Clear P3.
Set P3.1, Clear P3.
Wait 30 sec
Problem Statement 5: Configure a GPIO pin of an 8015 μ-controller to drive an LED and 2 GPIO pins as inputs(say, i/p-a and i/p-b) connected to switches. Write an Embedded C program(for 8051) such that if i/p-a is ON, LED turns ON; if i/p-b is ON LED turns off; if both the inputs are ON or OFF, the LED preserves its previous state.
Tool Used: Keil μVision C
Truth Table:
input a input b output(LED) 0 0 state remains intact 0 1 LED is OFF 1 0 LED is ON 1 1 state remains intact
Flowchart:
Start
A Read P1.
Read P1.1 P1.0 =? Read P1.
Program:
#i n c l u d e <r e g 5 1. h>
s b i t i n p u t a = P1 ˆ 0 ; s b i t inputb = P1 ˆ 1 ; s b i t output = P1 ˆ 2 ;
v o i d main ( ) { output = 1 ; % s e t p i n P1. 2 as output w h i l e ( 1 ) { i f ( ( i n p u t a = = 1 ) && ( inputb = = 0 ) ) { output = 1 ; }
i f ( ( i n p u t a = = 0 ) && ( inputb = = 1 ) ) { output = 0 ; }
e l s e { output = output ; } } }
Result: When input a is ON and b is OFF, LED is ON; when input a is OFF and b is ON, LED is OFF; and when both inputs a and b are ON or OFF, the stste of the LED remains intact.