0% found this document useful (0 votes)
40 views30 pages

Es Module Ii

Embedded systems

Uploaded by

21951a67j9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views30 pages

Es Module Ii

Embedded systems

Uploaded by

21951a67j9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

ES MODULE II

PART A
1)Write an embedded C program to interface LED to the port 0 of 8051
microcontroller.
ns:
#include<reg51.h>

void main(){

unsigned int k;

unsigned char l,b;

while(1){

P0=0x01;

b=P0;

for(l=0;l<3000;l++){

for(k=0;k<8;k++){

b=b<<1;

P0=b;

2)Discuss in detail about the embedded C program in Keil IDE with examples.
Embedded C is the most popular programming language in the software field
fordeveloping electronic gadgets. Each processor is associated with
embeddedsoftware. Embedded C Programming plays a major role in performing
specificfunctions by the processor. In our day-to-day life, we frequently use many
electronicdevices such as washing machines, mobile phones, digital cameras and so
on that willwork based on microcontrollers that are programmed by embedded C.
The use of Clanguage to program microcontrollers is becoming too common. And
most of thetime it's not easy to build an application in assembly which instead you
can makeeasily in C. So, It's important that you know the C language for
microcontrollerswhich is commonly known as Embedded C. As we are going to use
Keil C51 Compiler, hence we also call it Keil C.

Example
Here we have used the following code −

#include<reg51.h>
sbit LED_pin = P2^0; //set the LED pin as P2.0
void delay(int ms){
unsigned int i, j;
for(i = 0; i< ms; i++){
//Outer for loop for given milliseconds value
for(j = 0; j < 1275; j++){
//execute in each milliseconds;
}
}
}
void main(){
while(1){
//infinite loop for LED blinking
LED_pin = 0;
delay(500); //wait for 500 milliseconds
LED_pin = 1;
delay(500); //wait for 500 milliseconds
}
}
3)Explain the basic flow of control construct in,
i) Constant time statements
ii) Sequence of statements
iii) For loops
iv) While loops
Ans:
Constant Time statements:
The execution of constant time statements is a constant, independent of the size of
the input.
❖ Declarations and initializations of simple data types:
➢ int x,y;
➢ char mychar=‘a‘;
❖ Assignment statements of simple data types:
➢ x-y;
❖ Arithmetic operations:
➢ X=5y+4z;
❖ Array referencing:
➢ A[j]
❖ Referencing/dereferencing pointers:
➢ cursor=head->next;
❖ Most conditional tests:
➢ if(x<12)…

ii) Sequence of statements


For a sequence of statements, simply compute their individual complexity functions.

iii) For loops


Inline Functions are those functions whose definitions are small and can
besubstituted at the place where its function call occurs. Function substitution
istotally compiler choice.
Let’s take below example:

iv) While loops


The line while(1) is most popular used in applications for embedded
microcontrollers,for reasons which will be explained below.

The line while(1) in a C program creates an infinite loop- this is a loop that
neverstops executing. It executes over and over and over again, unless the program
isintentionally stopped or there is some condition under this loop that gets met
thattakes the program out of this infinite loop.
Let's take the following C program.

#include <stdio.h>

void main()

printf("Hello World");

while(1);

4)Interpret the inline functions and inline assembly in C structures with


anexample.
Ans:
Inline Functions are those functions whose definitions are small and can be
substituted at the place where its function call occurs. Function substitution is
totally compiler choice.

Let’s take below example:


#include <stdio.h>

// Inline function in C
inline int foo()
{
return 2;
}

// Driver code
int main()
{

int ret; // inline function call


ret = foo();
printf("Output is: %d\n", ret);
return 0;
}

Inline assembly

In computer programming, an inline assembler is a feature of some compilers that


allows low-level code written in assembly language to be embedded within a
program, among code that otherwise has been compiled from a higher-level
language such as C.

#include <errno.h>

long int syscall3(unsigned int num, int arg1, int arg2, int arg3){
int retA, retB;

long int ret;

asm ( "syscall\n\t"

:"=a"(retA),"=d"(retB)
:"a"(num),"d"(arg3),"D"(arg1),"S"(arg2)

:"cc","memory"

);

ret=retA; /* here, only one */

if (-125 <= ret && ret < 0) {

errno = -ret;

ret = -1;

return ret;

5)Describe an embedded C program in order to perform bitwise operations


onspecified data.
The bitwise or bit-level operator lay’s foundation for bitwise operations in
embeddedprogramming. We hope you already have sound knowledge of binary
number systemsin order to follow this tutorial. Many newbies found themselves
confused withBitwise Vs. Boolean operations. A bitwise expression is used when we
want to modifya variable by changing some or any of the individual bits of the
variable. & and | arebitwise operators for AND & OR respectively. We’ll see in the later
part of this post,how it will be used to set, clear and extract a bit using bitwise
operations. A Booleanexpression is used when we want to know something about a
variable: is it equal to12, is it greater than 12 or is it less than 5 etc. Boolean operators
are: && (logical and),
|| (logical or), !(logical not). X && Y returns TRUE only if both X and Y are TRUE. X ||
Yreturns TRUE if either X or Y are TRUE.

Example:
uint8_t A = 0x3B //00111011;
uint8_t B = 0x96 //100101
AND (& in C)
AND compares each bit and returns 1 if the two bits are 1 (TRUE) otherwise 0 (FALSE). So: C = A & B;

00111011………………..(A=0x3B)
& 10010110………………..(B=0x96)
00010010
The value of C will be 0x12 or in binary 00010010. That is where there is a 1 in each bit for both

values. OR (| in C)

OR will return a 1 if there is a 1 in either value at that bit. So: C = A | B;

00111011………………..(A=0x3B)
| 10010110………………..(B=0x96)
10111111
The value of C will be 0xBF or in binary 10111111

XOR (^ in C - Exclusive OR)


XOR will return a 1 if there is a 1 at that bit for either value but not both. For
example,if bit position 5 for both values has a 1 then XOr returns a 0. But if only one
has a 1and the other has a 0 XOR returns a 1. So: C = A^B;

00111011………………..(A=0x3B)
^ 10010110………………..(B=0x96)
10101101
The value of C will be 0xAD or in binary 10101101.
NOT (! in C)
This returns the compliment of a value. This mean where there was a 0 there willnow
be a 1 and vice versa. So: C = ~(A);

!00111011………………..(A=0x3B)
11000100………………..(C=0xC4)
The value of C will be 0xC4 or in binary 11000100

Bitwise Shift Operators (<<, >>)


nd then there are two shift operators – Left shift and Right shift. These
operatorsshift the bits by the corresponding value, in other word’s move the bits.
The sign <<for left shift and >> for right shift. Here is an example:

C = A << 2; // left shift A by 2


bit-shift-operator-left
Bit Shift Operator (Left)
The value of C becomes 0xEC or in binary 11101100 after shifting 2-bits to the left.

D = B >> 4; // right shift B by 4


bit-shift-operator-right
Bit Shift Operator (Right)
The value of D becomes 0x03 or in binary 00001001 after shifting 4-bits to right.

6)Write an embedded C Program to toggle all the bits of Port P1 continuously with 250 ms delay using
8051microcontroller.
Ans:
#include <reg51.h>

void MSDelay(unsigned int);

void main(void) {

while(1) { //repeat forever

P1=0x55;

MSDelay(250); //time delay

P1=0xAA;
MSDelay(250) }}
Assume the program is tested for the DS89C420 with XTML=11.0592MHz.

90ns =1275 = 114750ns = 1ms

void MSDelay(unsigned int itime) {

unsigned int i,j;

for (i=0; i<itime; i++)

for (j=0; j<1275; j++); // 1ms delay

7)Write an embedded C program to interface the keyboard and Whenever a key


ispressed, it should be displayed on LCD using 8051.

#include<reg52.h> //including sfr registers for ports of the controller


#include<lcd.h>

//LCD Module Connections


sbit RS = P0^0;
sbit EN = P0^1;
sbit D0 = P2^0;
sbit D1 = P2^1;
sbit D2 = P2^2;
sbit D3 = P2^3;
sbit D4 = P2^4;
sbit D5 = P2^5;
sbit D6 = P2^6;
sbit D7 = P2^7;
//End LCD Module Connections

//Keypad Connections
sbit R1 = P1^0;
sbit R2 = P1^1;
sbit R3 = P1^2;
sbit R4 = P1^3;
sbit C1 = P1^4;
sbit C2 = P1^5;
sbit C3 = P1^6;
sbit C4 = P1^7;
//End Keypad Connections
void Delay(int a)
{
int j;
int i;
for(i=0;i<a;i++)
{
for(j=0;j<100;j++)
{
}
}
}

char Read_Keypad()
{
C1=1;
C2=1;
C3=1;
C4=1;
R1=0;
R2=1;
R3=1;
R4=1;
if(C1==0){Delay(100);while(C1==0);return
'7';}
if(C2==0){Delay(100);while(C2==0);return
'8';}
if(C3==0){Delay(100);while(C3==0);return
'9';}
if(C4==0){Delay(100);while(C4==0);return '/';}
R1=1;
R2=0;
R3=1;
R4=1;
if(C1==0){Delay(100);while(C1==0);return '4';}
if(C2==0){Delay(100);while(C2==0);return '5';}
if(C3==0){Delay(100);while(C3==0);return '6';}
if(C4==0){Delay(100);while(C4==0);return
'X';} R1=1;
R2=1;
R3=0;
R4=1;
if(C1==0){Delay(100);while(C1==0);return
'1';}
if(C2==0){Delay(100);while(C2==0);return
'2';}
if(C3==0){Delay(100);while(C3==0);return
'3';}
if(C4==0){Delay(100);while(C4==0);return '-';}
R1=1;
R2=1;
R3=1;
R4=0;
if(C1==0){Delay(100);while(C1==0);return 'C';}
if(C2==0){Delay(100);while(C2==0);return '0';}
if(C3==0){Delay(100);while(C3==0);return '=';}
if(C4==0){Delay(100);while(C4==0);return '+';}
return 0;
}

void main()
{
int i=0;
char c,p;
Lcd8_Init();
while(1)
{
Lcd8_Set_Cursor(1,1);
Lcd8_Write_String("Keys Pressed:");
Lcd8_Set_Cursor(2,1);
Lcd8_Write_String("Times:");
while(!(c = Read_Keypad()));
p=c;
while(p==c)
{
i++;
Lcd8_Set_Cursor(1,14);
Lcd8_Write_Char(c);
Lcd8_Set_Cursor(2,7);
Lcd8_Write_Char(i+48);
Delay(100);
while(!(c = Read_Keypad()));
}
i=0;
Lcd8_Clear();
}
}
The code consists of two user defined functions. The Delay() is used to delay the program execution.
TheRead_Keypad() reads the keypad. If any key is pressed it waits until the key is released and returns
thecorresponding character. If no key is being pressed it returns zero.

8)Write an 8051 C program to toggle all the bits of P0 continuously between


valuesof 0x00 and 0xFF.

#include<reg51.h>
Void main (void)

unsigned char z;

for (z=0 ;z<=255 ; z++)


P1=z;

Run the above program on your simulator to see how P1 displays values 00-FF in binary

The signed character is an 8 – bit data type that uses the most significant bit (D7 of D 7 of D0) to represent + or – value
.Asresult we have only 7 bits for the magnitude of the signed number .

1. #include<reg51.h>

sbit led=P0^0;

sbit sw=P3^0;

int i;

main()

while(1)

if (sw==0)

led=0;

for(i=0;i<1000;i++);

led=1;

for(i=0;i<1000;i++);

P2=0x00;
for(i=0;i<1000;i++);

P2=0xFF;

for(i=0;i<1000;i++);

}
2.

#include<reg51.h>

int i=0;

//xdata int k;

main()

while(1)

P0=0x00;

for(i=0;i<1000;i++);

` P0=0xFF;

for(i=0;i<1000;i++);

9)Write an embedded C program to toggle only the bit P1.5 continuously with some delay using
8051microcontroller.
Ans:
#include<reg51.h>

sbit pin = P1^5;


void delay(){
int i;
TMOD = 0x01;
for(i=0; i<1000; i++){
TH0 = 0xFC;
TL0 = 0x66;
TR0 = 1;
while(TF0 != 1){
;
}
TR0 = 0;
TF0 = 0;
}
}

void main(){
while (1)
{
pin = ~pin;
delay();
}

10. Write an embedded C program to interface LCD data pins to port P1 and
displaya message on it using an 8051 microcontroller.

#include <reg51.h>

#define lcd_data P2

sbit rs=P0^0;
sbit rw=P0^1;
sbit en=P0^2;

void lcd_init();
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
void lcd_delay();

void lcd_init()
{
cmd(0x38);
cmd(0x0e);
cmd(0x01);
cmd(0x06);
cmd(0x0c);
cmd(0x80);
}

void cmd(unsigned char a)


{
lcd_data=a;
rs=0;
rw=0;
en=1;
lcd_delay();
en=0;
}

void dat(unsigned char b)


{
lcd_data=b;
rs=1;
rw=0;
en=1;
lcd_delay();
en=0;
}

void show(unsigned char *s)


{
while(*s) {
dat(*s++);
}
}

void lcd_delay()
{
unsigned int lcd_delay;
for(lcd_delay=0;lcd_delay<=6000;lcd_delay++);
}

int main()
{
unsigned int j;
lcd_init();
while(1) {
cmd(0x80);
show(" Welcome To ");
cmd(0xc0);
show(" EMBETRONICX.COM");

for(j=0; j<30000; j++);


cmd(0x01);
for(j=0; j<30000; j++);
}
}

Part-B

1.Explain the functions of a typical parallel I/O interface with a neat

diagram. Functions:

1. It is used to synchronise the operating speed of CPU with respect


toinput-output devices.
2. It selects the input-output device which is appropriate for the interpretation
ofthe input-output device.
3. It is capable of providing signals like control and timing signals.
4. In this data buffering can be possible through a data bus.
5. There are various error detectors.
6. It converts serial data into parallel data and vice versa.
7. It converts digital data into analog signals and vice versa.

2. Write an embedded C program to interface digital to analog converter (DAC)with


8051 microcontroller with a neat circuit diagram.

A.

Circuit Diagram
Output
The output will look like this −

3.Write an embedded C program for reading and writing bits in a simple


versionalong with explanation.
Explanation:

Here, we explain how we can copy the value from one pin to another pin of the
sameport in an 8051 microcontroller. This is required in cases when the pins of
aparticular port are connected to the different input and output devices. Thus in
suchcases, the code to access the devices will be different as per the companies
manufacturing them. So there comes the necessity to read from and write to
aparticular pin only, rather than the entire port of the microcontroller.

4. Explain the interfacing of the keyboard with 8051 and explain each pin in 8051?

The keyboard here we are interfacing is a matrix keyboard. This keyboard is designed
with particular rows and columns. These rows and columns are connected to the
microcontroller through its ports of the microcontroller 8051. We usually use an 8*8
matrix keyboard. So only two ports of 8051 can be easily connected to the rows and
columns of the keyboard.

Pin diagram of 8051 microcontroller:


Descriptions of pins:

● Pin 1 to pin 8 (Port 1): Pin 1 to Pin 8 are assigned to Port 1 for simple
I/Ooperations. They can be configured as input or output pins depending on
thelogic control i.e. if logic zero (0) is applied to the I/O port it will act as an
outputpin and if logic one (1) is applied the pin will act as an input pin.
● Pin 9 (RST): Reset pin. It is an active-high, input pin. Therefore if the RST pin
ishigh for a minimum of 2 machine cycles, the microcontroller will reset i.e. it
willclose and terminate all activities.
● Pin 10 to Pin 17 (Port 3): Pin 10 to pin 17 are port 3 pins which are also referred
toas P3.0 to P3.7. These pins are similar to port 1 and can be used as
universalinput or output pins. These pins are bidirectional pins.
● Pin 18 and Pin 19 (XTAL2 And XTAL1): These pins are connected to an external
oscillator which is generally a quartz crystal oscillator.
● Pin 20 (GND): This pin is connected to the ground. It has to be provided with
a0V power supply.
● Pin 21 to Pin 28 (Port 2): Pin 21 to pin 28 are port 2 pins also referred to as P2.0to
P2.7.These pins are bidirectional.
● Pin 29 (PSEN): PSEN stands for Program Store Enable. It is an output,
active-lowpin. This is used to read external memory.
● Pin 30 (ALE/ PROG): ALE stands for Address Latch Enable. It is an input,
active-high pin. This pin is used to distinguish between memory chips
whenmultiple memory chips are used.
● Pin 31 (EA/ VPP): EA stands for External Access input. It is used
toenable/disable external memory interfacing.
● Pin 32 to Pin 39 (Port 0): Pin 32 to pin 39 are port 0 pins also referred to as
P0.0to P0.7. They are bidirectional input/output pins.
● Pin 40 (VCC): This pin provides power supply voltage i.e. +5 Volts to the circuit.

5. Explain in detail the interfacing of the LCD display with


8051microcontrollerwith a neat diagram.

16×2 LCD display is a very basic module and is very commonly used in
various devices and circuits.
16×2 LCD means it can display 16 characters per line and there are 2 such lines. In
this LCD each character is displayed in a 5×7 pixel matrix. This LCD has two registers,
namely, Command and Data. The command register stores the command
instructions given to the LCD. A command is an instruction given to LCD to do a
predefined task like initializing it, clearing its screen, setting the cursor position,
controlling display, etc. The data register stores the data to be displayed on the LCD.
The data is the ASCII value of the character to be displayed on the LCD.
The LCD display module requires 3 control lines as well as either 4 or 8 I/O lines for
the data bus. The user may select whether the LCD is to operate with a 4-bit data
busor an 8-bit data bus. If a 4-bit data bus is used the LCD will require a total of 7
data lines (3 control lines plus the 4 lines for the data bus). If an 8-bit data bus is used
the LCD will require a total of 11 data lines (3 control lines plus the 8 lines for the data
bus).

The three control lines are referred to as EN, RS, and RW.
The EN line is called “Enable.” This control line is used to tell the LCD that you are
sending it data. To send data to the LCD, your program should make sure this line is
low (0) and then set the other two control lines and/or put data on the data bus.
When the other lines are completely ready, bring EN high (1) and wait for the
minimum amount of time required by the LCD datasheet (this varies from LCD to
LCD), and end by bringing it low (0) again.
The RS line is the “Register Select” line. When RS is low (0), the data is to be treated
as a command or special instruction (such as clear screen, position cursor, etc.).
When RS is high (1), the data being sent is text data which should be displayed on the
screen. For example, to display the letter “T” on the screen you would set RS high.
The RW line is the “Read/Write” control line. When RW is low (0), the information on
the data bus is being written to the LCD. When RW is high (1), the program is
effectively querying (or reading) the LCD. Only one instruction (“Get LCD status”) is a
read command. All others are write commands–so RW will almost always be LOW.

Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation
selected by the user). In the case of an 8-bit data bus, the lines are referred to as
DB0, DB1, DB2, DB3, DB4, DB5, DB6, and DB7.
6. Explain about the multiple interrupts in 8051 microcontroller.

Interrupts are the events that temporarily suspend the main program, pass the control to
the external sources and execute their task. It then passes the control to the main program
where it had left off.

The 8051 microcontroller can recognize five different events that cause the main
program to interrupt from the normal execution. These five sources of interrupts in
8051 are:
Timer 0 overflow interrupt- TF0
Timer 1 overflow interrupt- TF1
External hardware interrupt- INT0
External hardware interrupt- INT1
Serial communication interrupt- RI/TI
The Timer and Serial interrupts are internally generated by the microcontroller,
whereas the external interrupts are generated by additional interfacing devices or
switches that are externally connected to the microcontroller. These external
interrupts can be edge triggered or level triggered. When an interrupt occurs, the
microcontroller executes the interrupt service routine so that memory location
corresponds to the interrupt that enables it.
Upon ‘RESET’ all the interrupts get disabled, and therefore, all these interrupts must
be enabled by a software. In all these five interrupts, if anyone or all are activated,
this sets the corresponding interrupt flags as shown in the figure. All these
interruptscan be set or cleared by bit in some special function register that is
Interrupt Enabled (IE), and this in turn depends on the priority, which is executed by
IP interrupt priority register.

7. Write an embedded C program to interface analog to digital converter (ADC)


with 8051 microcontroller with a neat circuit diagram.
# include<reg51.h>
#include<stdio.h>
sbit ale=P3^3;
sbit oe=P3^6;
sbit sc=P3^4;
sbit eoc=P3^5;
sbit clk=P3^7;
sbit ADDA=P3^0; //Address pins for selecting input channels.
sbit ADDB=P3^1;
sbit ADDC=P3^2;
#define lcdport P2 //lcd
sbit rs=P2^0;
sbit rw=P2^2;
sbit en=P2^1;
#define input_port P1 //ADC
int result[3],number;
void timer0() interrupt 1 // Function to generate clock of frequency 500KHZ using Timer 0
interrupt.
{
clk=~clk;
}
void delay(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<100;j++);
}
void daten()
{
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
void lcd_data(unsigned char ch)
{
lcdport=ch & 0xF0;
daten();
lcdport=ch<<4 & 0xF0;
daten();
}
void cmden(void)
{
rs=0;
en=1;
delay(1);
en=0;
}
void lcdcmd(unsigned char ch)
{
lcdport=ch & 0xf0;
cmden();
lcdport=ch<<4 & 0xF0;
cmden();
}
lcdprint(unsigned char *str) //Function to send string data to LCD.
{
while(*str)
{
lcd_data(*str);
str++;
}
}
void lcd_ini() //Function to inisialize the LCD
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x0e);
lcdcmd(0x01);
}
void show()
{
sprintf(result,"%d",number);
lcdprint(result);
lcdprint(" ");
}
void read_adc()
{
number=0;
ale=1;
sc=1;
delay(1);
ale=0;
sc=0;
while(eoc==1);
while(eoc==0);
oe=1;
number=input_port;
delay(1);
oe=0;
}
void adc(int i) //Function to drive ADC
{
switch(i)
{
case 0:
ADDC=0; // Selecting input channel IN0 using address lines
ADDB=0;
ADDA=0;
lcdcmd(0xc0);
read_adc();
show();
break;
case 1:
ADDC=0; // Selecting input channel IN1 using address lines
ADDB=0;
ADDA=1;
lcdcmd(0xc6);
read_adc();
show();
break;
case 2:
ADDC=0; // Selecting input channel IN2 using address lines
ADDB=1;
ADDA=0;
lcdcmd(0xcc);
read_adc();
show();
break;
}
}
void main()
{
int i=0;
eoc=1;
ale=0;
oe=0;
sc=0;
TMOD=0x02;
TH0=0xFD;
lcd_ini();
lcdprint(" ADC 0808/0809 ");
lcdcmd(192);
lcdprint(" Interfacing ");
delay(500);
lcdcmd(1);
lcdprint("Circuit Digest ");
lcdcmd(192);
lcdprint("System Ready... ");
delay(500);
lcdcmd(1);
lcdprint("Ch1 Ch2 Ch3 ");
IE=0x82;
TR0=1;
while(1)
{
for(i=0;i<3;i++)
{
adc(i);
number=0;
}
}

8. Explain the basic techniques for reading from I/O port pins for building the
embedded hardware.

In 8051 Microcontroller, I/O operations are performed by using four ports and 40
pins. I/O operation port uses 32 pins with each port having 8 pins. The remaining
8-pins are used for providing.
In a microcontroller there are four Input/output ports P0, P1, P2, and P3, each port
is an 8-bit port having 8 pins each. During RESET, all the ports are used as input
ports. When the port gets first 0, then it becomes an output port. To reconfigure it
as an input, the high signal (1) must be sent to a port.
Port 0 (Pin No 32 - Pin No 39):
Port 0 contains 8 pins. It can be used as input or output. In general we connect P0
with 10K-ohm pull-up resistors for using it as an input or output port being an open
drain.
Port 1 (Pin No 1-Pin No 8):
It is also an 8-bit Port and can be worked as either input or output. It doesn't require
external connected pull-up resistors because they are already present internally.
Upon reset, Port 1 worked as an input port.
Port 2 (Pin No 21-Pin No 28):
Port 2 uses a total of 8 pins and it can also be used as input and output operation.
Same as Port 1, P2 also not require external pull- up resistors. Port 2 can be used
along with P0 to provide 16-bit address for an external memory
Port 3 (Pin No 10-Pin No 17):
Port 3 is also of 8 bits and it can be used as Input/output. This port provides some
important signals.

9. Explain the purpose of TxD and RxD in serial communication of 8051


microcontroller.

Serial Communication is a form of I/O in which the bits of a byte being transferred
appear one after other in a timed sequence on a single wire. Serial Communication
uses two methods, asynchronous and synchronous. The Synchronous method
transfers a block of data at a time, while the asynchronous method transfers a single
byte at a time. In Synchronous Communication the data get transferred based on a
common clock signal. But in Asynchronous communication, in addition to the data
bit, one start bit and one stop bit is added. These start and stop bits are the parity
bits to identify the data present between the start and stop bits.

The 8051 has two pins that are used specifically for transferring and receiving data
serially. These two pins are called TXD and RXD and are part of the Port-3 group
(Port-3.0 and Port-3.1). Pin 11 of the 8051 is assigned to TXD and pin 10 is designated
as RXD.

10. Explain in detail the interfacing of keyboard with 8051microcontroller with


neat diagram.

Same as part B 4th Question.

11. Explain the concept of switch bounce with example and write an embedded
Cprogram for reading switch inputs?

Refer PART-B Q.17


C-Program for reading switch inputs (doubt)

17. Explain in detail about the switch bounce.

When we press a push button or toggle switch or a micro switch, two metal parts
come into contact to short the supply. But they don’t connect instantly but the metal
parts connect and disconnect several times before the actual stable connection is
made. The same thing happens while releasing the button. This results in the false
triggering or multiple triggering like the button is pressed multiple times. Its like
falling from a height and it keeps bouncing on the surface, until it comes to rest.

Simply, we can say that the switch bouncing is the non-ideal behavior of any switch
which generates multiple transitions of a single input. Switch bouncing is not a
major problem when we deal with the power circuits, but it causes problems while
we are dealing with the logic or digital circuits.

18. Explain in detail the differences between ‘C’ and ‘Embedded C’.

You might also like