RVS COLLEGE OF ENGINEERING & TECHNOLOGY
Department of Electrical and Electronics Engineering
EE3017-EMBEDDED C PROGRAMMING
5th SEM / III-EEE
TWO MARKS QUESTION & ANSWER
Part –A
UNIT -1 BASIC C PROGRAMMING
Typical C Program Development Environment - Introduction to C
Programming - Structured Program Development in C - Data Types and
Operators- C Program Control - C Functions -Introduction to Arrays.
1. What is the use of C? (CO1) (K1)
C is widely used to develop systems that demand performance, such as
operating systems, embedded systems, real-time systems and communications
systems.
2. What are the six phases of C program execution? (CO1) (K1)
C programs typically go through six phases to be executed—edit,
preprocess,Compile, link, load and execute.
3. Define the term variable and constant. (CO1) (K1)
Variable:
A variable is a data name that is used to store a value. A variable may take
different values at different times. A variable can be chosen by the programmer in
a meaningful way. So as to reflect its function or nature in the program.
Eg:
city college a1
Total_mark Name Avg
Constant:
A constant is a value that does not change during the program execution. A
constant used in C does not occupy memory.
4. Specify the use of printf( ) and scanf( ) functions. (CO1) (K3)
The function scanf() is used for formatted input from the standard input and
provides many of the conversion facilities.
It is used for formatted output to standard output device,( screen) . The
format specification contains string and the data to be output, as the
arguments(parameter) to the printf() function.
5. What is an unary operator? Give example. (CO1) (K1)
The operators that act upon a single operand to produce a new value is
known as unary operator.
Eg: minus operator(-) ,Increment operator (++)
6. What are bitwise operators? List the types. (CO1) (K1)
The bitwise operator performs the operation on bits (i.e, bit by bit). Using
the bitwise operators we can set/ reset/ check any bit in the value of the variable.
Operator Meaning
& Bitwise AND
| Bitwise OR
<< Shift left
>> Shift right
7. What are keywords? Give example. (CO1) (K1)
Keywords have fixed meaning and these meaning cannot be changed. These
keywords can be used only for their intended purpose, they cannot be used as
programmer-defined identifiers.
The following are examples of few keywords are predefined by C
auto double int struct
break else if switch
case enum do while
8. Specify the syntax used for ‘for’ statement. (CO1) (K3)
The for loop is entry controlled loop the provides a more concise loop
control structure. The general format of the loop is
for(intilialization;test-condition;increment/
decrement)
{
Body of the loop;
}
9. What are library functions? (CO1) (K1)
The function that are predefined and supplied along with the compiler are
known as built in functions. They are also known as library function.
10.Define an array. (CO1) (K1)
Array is the collection of elements.
Collection of the elements of the same data type.
All elements are stored in the contiguous memory locations.
11.What is Relational Operator in C? (CO1) (K1)
The relational operators are used to compare arithmetic, logical and
character expressions. We often compare two similar quantities and depending on
their relation, take some decisions. Each of these operator compares their left hand
side with their right hand side. The whole expression involving the relational
operator then evaluates to an integer. It evaluates to zero if the condition is false,
and one if it is true
Operator Meaning
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
!= Not equal to
12.What is the purpose of conditional operator? (CO1) (K1)
The conditional operator consists of two symbols the question mark (?) and
the colon (:). The conditional expression of the form
variable = exp1?exp2:exp3;
conditional expression
where exp1 is test expression, exp2 is expression or constant or variable, exp3 is
expression or constant or variable.
13.What is character set? (CO1) (K1)
The C Character set consists of upper and lower case alphabets, digits,
special character and white spaces. The alphabet and digits are together called the
alphanumeric characters.
Alphabets:
A,B,C,D,E………………………X,Y,Z
a,b,c,d,e………………………..x,y,z
Digits:
0,1,2,3,4,5,6,7,8,9
Special Character
+ *& ^ % $ # @ ! ~ ` -- = > < .\ , : ;
14.What are logical operators? (CO1) (K1)
A logical operator is used to compare or evaluate logical and relational
expressions. There three logical in C language. They are
Operator Meaning
&& AND
|| OR
! NOT
15.Write the general form of structure of C functions. (CO1) (K1)
A C program basically has the following form
pre-processor commands
type definitions
function prototype
variable declaration
function body
16.Give the syntax of if-else statement. (CO1) (K1)
The if-else statement performs one of the two possible actions. The general
format is
if(test expression)
{
true-statement block;
}
else
{
false-statement block;
}
next statement.
17.What is an operator? (CO1) (K1)
In C operator can be classified into various categories based on their utility
and action, a list operator types are given below
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment operators
6. Conditional operators
7. Bitwise operators
8. Comma operators
18.Write the syntax of while statement in C. (CO1) (K1)
The general format of the while statement is
while(test_condition)
{
Body of the loop;
}
19.Write a note on do-while statement. (CO1) (K1)
In the do statement, the program proceeds to executes the body of the loop
first. At the end of the loop the test condition is evaluated. If the condition is true,
the program continues to execute the body of the loop. This process continues as
long as the condition is true.
20.Mention the two categories of function. (CO1) (K1)
Library function
User – Defined function
UNIT II EMBEDDED C
Adding Structure to 'C' Code: Object oriented programming with C. Header files
for Project and Port, Examples. Meeting Real-time constraints: Creating hardware
delays -Need for timeout mechanism - Creating loop timeouts - Creating hardware
timeouts.
1. How do you develop embedded software? (CO2) (K2)
The process of compiling, linking and executing the program.
The code will be ‘cross-compiled’ on a desktop PC, generating machine code that
is compatible with the 8051 family.
Created the required executable code, we need to test it and refine it. To do this,
We need to do the following:
Build the hardware for the embedded system.
Transfer the executable code to the embedded hardware and test the system.
2. Why you should choose a low oscillator frequency? (CO2) (K3)
In most modern (CMOS-based) 8051s, there is an almost linear relationship
between the oscillator frequency and the power supply current. As a result, by
using the lowest frequency necessary it is possible to reduce the power
requirement: this can be useful, particularly in battery-powered applications.
3. Give the importance of memory and mention its type. (CO2) (K1)
In this context, new memory devices appeared that could be used to store
data while the computer was running, but which lost these data when the power
was removed. These read-write memory devices were referred to as ‘random
access memory’ (RAM) devices.
Dynamic RAM (DRAM)
Static RAM (SRAM)
Mask Read-Only Memory (ROM)
Programmable Read-Only Memory (PROM)
UV Erasable Programmable Read-Only Memory (UV EPROM)
EEPROM and Flash ROM
4. Classification of programming languages into different generations. (CO2) (K3)
5. Give the advantage of Object-oriented programming with C. (CO2) (K1)
One main claimed advantage of using object orientation is that an OO model
closely represents the problem domain, which makes it easier to produce and
understand designs.
6. What is project header file? (CO2) (K1)
The ‘Project Header’ is simply a header file, included in all projects, that
groups the key information about the 8051 device you have used, along with other
key parameters – such as the oscillator frequency.
7. What is the use of Project Header? (CO2) (K1)
The use of a Project Header can help to make your code more easily
portable, by placing some of the key microcontroller- dependent data in one place:
if you change the processor or the oscillator used then – in many cases – you will
need to make changes only to the Project Header.
8. What is Port Header? (CO2) (K1)
The software components in your application will require exclusive access
to one or more port pins.
Using a Port Header, you pull together the different port access features for the
whole project into a single (header) file. Use of this technique can ease project
development, maintenance and porting.
There are many advantages obtained by integrating all port access in a single
Port.H header file:
// ----- Port.H -----
// Port access for File B
#define Port_B P0
// Port access for File A
sbit Pin_A = P3^2;
// Port access for File C
sbit Pin_C = P2^7;
9. What is Meeting real-time constraints with an example? (CO2) (K1)
Consider the issues involved in the accurate measurement of time. These issues are
important because many embedded systems must satisfy real-time constraints.
For example, consider the aircraft autopilot application, we assume that the pilot
has entered the required course heading, and that the system must make regular
and frequent changes to the rudder, elevator, aileron and engine settings, in order
to keep the aircraft following this path.
An important characteristic of this embedded system is the need to process inputs
and generate outputs very rapidly, on a time-scale measured in milliseconds. In this
case, even a slight delay in making changes to the rudder setting may cause the
plane to oscillate very unpleasantly or, in extreme circumstances, even to crash.
10.How to creating ‘hardware delays’ using Timer 0 and Timer 1? (CO2) (K2)
To create more accurate delays, then we can do using one of the 8051’s on-
chip timers.
All members of the 8051 family have at least two 16-bit timer / counters, known as
Timer 0 and Timer 1. These timers can be used to generate accurate delays.
TCON Special Function Register;
TMOD Special Function Register; and,
THx and TLx registers.
11.What is the advantage of a portable hardware delay? (CO2) (K1)
In a portable hardware delay the operating frequencies can be changed
dynamically and it is easy for the maintenance of the system.
12.Give the need for timeout mechanism. (CO2) (K1)
When a system has to be created as reliable then it should assure that the
system will not get into an indefinite loop. To do this assurance, we need the
timeout mechanism. They are loop timeout which is software based and hardware
timeout which is based on hardware.
13.Give the uses of timer 2. (CO2) (K1)
It is used to produce the delay. It is employed in
1. Creation of an operating system 2. Real time applications.
14.How to creating loop timeouts? (CO2) (K2)
A loop timeout may be easily created. The basis of the code structure is a
form of loop delay, created as follows:
tWord Timeout_loop = 0;
…
while (++Timeout_loop != 0);
This loop will keep running until the variable Timeout_loop reaches its maximum
value (assuming 16-bit integers) of 65535, and then overflows. When this happens,
the program will continue.
15.What is the use of Loop Timeouts? (CO2) (K1)
Loop timeouts are particularly well suited to applications involving long
timeout delays (typically measured in seconds). Where we require shorter delays,
with very precise timing, we can often gain a further improvement in performance
through the use of hardware-based timeouts.
UNIT III 8051 PROGRAMMING IN C
Data types and time delay in 8051- I/O programming in 8051- Logic
operations in 8051- Data conversion program in 8051 -Accessing code ROM
space in 8051- Data serialization using 8051
1. What is micro controller? (CO3) (K1)
Micro controller is a microprocessor with limited number of RAM, ROM,
I/O ports and timer on a single chip i.e. all the required hardware for a system is
combined together on a single chip.
2. Mention any two real time micro controllers. (CO3) (K1)
Micro oven
Washing machine
3. What is the size of data in 8051? (CO3) (K1)
8051 is an 8-bit microcontroller built with 40 pins DIP (dual inline
package).
8051 has internal RAM (128 Bytes) and ROM (4K Bytes)
4. Draw the Pin diagram of 8051. (CO3) (K2)
5. List the features of 8051 microcontroller. (CO3) (K1)
Features of 8051 microcontroller are given as follows.
8-bit CPU
16-bit Program Counter
8-bit Processor Status Word (PSW)
8-bit Stack Pointer
Internal RAM of 128bytes
Special Function Registers (SFRs) of 128 bytes
32 I/O pins arranged as four 8-bit ports (P0 - P3)
Two 16-bit timer/counters : T0 and T1
Two external and three internal vectored interrupts
6. Why oscillator circuit is used? (CO3) (K2)
Oscillator circuit is used to generate the basic timing clock signal for the
operation of the circuit using crystal oscillator.
7. Justify why the crystal oscillator frequency in 8051 is chosen as 11.0592 MHZ.
(CO3) (K5)
When an 8051 microcontroller based system is connected to an external
serial communication device, the speed of the data transfer should be in
standard baud rates such as 4800, 9600, etc.
Only XTAL (Crystal Oscillator) of 11.0592 MHz can provide such standard
baud rates, after down scaling down by 12 MHZ.
8. What are the ways to create a time delay in 8051? (CO3) (K1)
There are two ways to create a time delay in 8051 C:
Using a simple for loop
Using the 8051 timers
9. What is time delay in 8051 microcontroller? (CO3) (K1)
That means the the timer advances once in every 1uS and the maximum time
delay possible using a single 8051 timer is ( 2^16) x (1µS) = 65536µS. Delays
longer than this can be implemented by writing up a basic delay program using
timer and then looping it for a required number of time
10.What is I/O structure of 8051? (CO3) (K1)
8051 microcontrollers have 4 I/O ports each of 8-bit, which can be
configured as input or output. Hence, total 32 input/output pins allow the
microcontroller to be connected with the peripheral devices.
11.What is memory mapped I/O? (CO3) (K1)
This is one of the techniques for interfacing I/O devices with μp. In memory
mapped I/O, the I/O devices assigned and identified by 16-bit addresses. To
transfer the data between MPU and I/O devices memory related instructions (such
as LDA, STA etc.) and memory control signals (MEMR, MEMW) are used.
12.Which register in 8051 microcontroller is used for arithmetic and logical
operations? (CO3) (K2)
8051 microcontroller has 2 registers, namely Register A and Register B.
Register A serves as an accumulator while Register B functions as a general
purpose register. These registers are used to store the output of mathematical and
logical instructions.
13.What is the arithmetic logic unit of the 8051? (CO3) (K1)
ALU performs arithmetic like addition, subtraction, multiplication and
Logical Operations like NAND, NOR etc. Since 8051 is an 8 bit microcontroller,
it takes input from two 8 bit registers namely A and B and processes them
14.Define Baud rate. (CO3) (K1)
It is the speed of serial data transfer, expressed in bits/sec. The standard baud
rates are110, 150, 300, 600, 1200, 2400, 4800, 9600, 19200
15.Give the addressing modes of 8051. (CO3) (K1)
There are six addressing modes in 8051.They are
Direct addressing
Indirect addressing
Register instruction
Register specific (register implicit)
Immediate mode
Indexed addressing
16.Write a program to add two 8-bit numbers using 8051. (CO3) (K3)
MOV A,#30H
ADD A,#50H
17.What is the ROM space in 8051? (CO3) (K1)
Some family members of 8051 have only 4K bytes of on-chip ROM (e.g.
8751, AT8951); some have 8K ROM like AT89C52, and there are some family
members with 32K bytes and 64K bytes of on-chip ROM such as Dallas
Semiconductor.
18.How to access internal memory in 8051? (CO3) (K2)
The internal data memory of 8051 is divided into two groups. These are a set
of eight registers and a scratch pad memory. These eight registers are R0
toR7. The address range 00H to 07H is used to access the registers, and the rest
are scratch pad memory.
19.How to convert ASCII to BCD in 8051? How to convert BCD to binary in 8051?
(CO3) (K2)
ASCII to packed BCD conversion
To convert ASCII to packed BCD, it is first converted to unpacked BCD (to
get rid of the 3), and then combined to make packed BCD. For example, 4 and 7
on the keyboard give 34H and 37H, respectively. The goal is to produce 47H or
“0100 0111″, which is packed BCD.
BCD to binary
We are just multiplying the digit of 10th place of the BCD number with
0AH. Then adding the second digit with the result to get the number. If the
number is 94, then it is multiplying 0AH with 9. (9 * 0AH) = 5AH, then adding 4
with 5AH
20.What is data serialization in 8051? (CO3) (K1)
Serializing data is a way of sending a byte of data one bit at a time through a
single pin of microcontroller. There are two ways to transfer a byte of data
serially: using serial port. Transferring data one bit at a time through a single pin
UNIT IV 8051 SERIAL PORT AND INTERRUPT PROGRAMMING IN C
Basics of serial communication- 8051 interface to RS232- serial port programming
in 8051- 8051 interrupts and programming- Programming for timer configuration.
1. How to interface serial communication with 8051? (CO4) (K2)
For serial data communication to work, the byte of data must be converted to
serial bits using a parallel-in-serial-out shift register, then it can be transmitted
over a single data line. At the receiving end there must be a serial-in-parallel-out
shift register to receive the serial data and pack them into a byte.
2. What are the types of serial communication? (CO4) (K1)
The serial communication can be,
Synchronous (continuous)
Iso-Synchronous (with regular time intervals)
Asynchronous (with irregular time intervals)
3. What is RS-232? (CO4) (K1)
A serial communication protocol which has been universally referred to as
‘RS-232’ since its first ‘Recommended Standard’ appeared in the 1960s. Similar
standards (V.28) are published by the International Telecommunications Union
(ITU) and by CCITT (The Consultative Committee International Telegraph and
Telephone).
The ‘RS-232’ standard includes details of:
The protocol to be used for data transmission.
The voltages to be used on the signal lines.
The connectors to be used to link equipment together.
4. What is UART in 8051? (CO4) (K1)
The microcontroller MCS51 has an inbuilt UART for carrying out serial
communication. The serial communication is done in the asynchronous mode. A
serial port, like other PC ports, is a physical interface to establish data transfer
between a computer and external hardware or device
5. How is RS232 connected to microcontroller? (CO4) (K1)
While connecting an RS232 to microcontroller system, a voltage converter is
required. This converter converts the microcontroller output level to the RS232
voltage levels, and vice versa. IC MAX232, also known as line driver, is very
commonly used for this purpose.
6. What is serial port programming? (CO4) (K1)
A serial port is an interface that allows a PC to transmit or receive data one
bit at a time. It is one of the oldest types of interfaces and at one time was
commonly used to connect printers and external modems to a PC.
7. How many serial ports are available in 8051 microcontroller? (CO4) (K2)
For serial communication there are two separate pins known as serial port of
8051.
8. What is a port? (CO4) (K1)
A Port is a buffered IC, which is used to hold the data transmitted from
microprocessor to I/O device or vice-versa.
9. What is the need for port? (CO4) (K1)
The I/O devices are generally slow devices and their timing characteristics
do not match with processor timings. Hence the I/O devices are connected to
system bus through the ports.
10.What are the interrupts in 8051? (CO4) (K1)
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.
8051 has 6 interrupt signals,
RESET,INT0, INT1, TFO, TF1, SPI (RI/TI).
Each interrupt can be enabled or disabled by setting bits of the IE register and the
whole interrupt system can be disabled by clearing the EA bit of the same register.
11.What is serial port interrupt in 8051? (CO4) (K1)
8051 MCU has a serial communication port and have related serial interrupt
flags (TI/RI). When the last bit (stop bit) of a byte is transmitted, the TI serial
interrupt flag is set, and when the last bit (stop bit) of the receiving data byte is
received, the RI flag gets set.
12.What is stack pointer in 8051? (CO4) (K1)
In the 8051, the stack pointer (SP) points to the last used location of the
stack. When data is pushed onto the stack, the stack pointer (SP) is incremented
by 1. When PUSH is executed, the contents of the register are saved on the stack
and SP is incremented by 1.
13.What is timer in 8051 microcontroller? (CO4) (K1)
8051 microcontrollers have two timers and counters which work on the
clock frequency. Timer/counter can be used for time delay generation, counting
external events, etc.
14.List the modes of Timer in 8051. (CO4) (K1)
The modes of timer in 8051 are chosen with the help of two bits, viz., M0 &
M1 in TMOD register. The different modes of timer are as follows.
15.What are the applications of timers? (CO4) (K1)
Timers are used to measure specific time intervals. But in electrical
engineering terms, timers are also referred to as counters often. The timer is a
component which is extensively used in different embedded systems. They are
used to keep a record of time for different events occurring in the embedded
systems.
UNIT V 8051 INTERFACING
8051: ADC interfacing-DAC interfacing-Sensor interfacing- LCD interfacing-
Stepper motor Interfacing.
1. What is an interfacing circuit? (CO5) (K1)
An interfacing circuit is an electronic circuit, which is used to connect the
peripherals to the computer.
2. What is serial interface in 8051? (CO5) (K1)
Serial communication is mostly used for transmitting and receiving the
signal. The 8051 microcontroller is consisting of Universal Asynchronous
Receiver Transmitter (UART) used for serial communication. The signals are
transmitted and received by the Rx and Tx pins of microcontroller.
3. Mention any two applications of 8051 microcontrollers. (CO5) (K1)
The 8051 has been in use in a wide number of devices, mainly because it is
easy to integrate into a project or build a device around. The following are the
main areas of focus:
Automobiles: The 8051 finds wide acceptance in providing automobile
solutions. They are widely used in hybrid vehicles to manage engine variants.
Additionally, functions such as cruise control and anti-brake system have
been made more efficient with the use of microcontrollers.
Medical Devices: Portable medical devices such as blood pressure and
glucose monitors use microcontrollers will to display data, thus providing
higher reliability in providing medical results.
Energy Management, Washing machines and all Electronics Equipments.
4. How is ADC interfacing with 8051? (CO5) (K2)
The ADC 0808/0809 is the 8-bit analog to digital converter. It has 8-
channels IN0-IN7. ADC 0808 has 3 control signals: SOC [Start of conversion]:
When High to low signal is appears to this pin of ADC, ADC then starts
conversion.
5. How is DAC interfacing with 8051? (CO5) (K2)
In these systems microcontroller generates output which is in digital form
but the controlling system requires analog signal as they don't accept digital data
thus making it necessary to use DAC which converts digital data into equivalent
analog voltage.
6. What is sensor interfacing with 8051? (CO5) (K1)
Sensor interfacing with 8051 deals how the temperature sensor (LM35)
interfaces with micro controller in different applications.
For interfacing a sensor with an 8051 microcontroller, we need ADC in
between because output of sensor is analog and microcontroller works on
digital signals only.
7. How temperature sensor is interfacing with 8051? (CO5) (K2)
LM35 sensor produces voltage corresponding to temperature. This voltage is
converted to digital (0 to 256) by ADC0804 and it is fed to 8051
microcontroller. 8051 microcontroller converts this digital value into temperature
in degree Celsius.
8. Give the Full Form of LCD and commonly used LCD’s. (CO5) (K1)
LCD- Liquid Crystal Display
The LCD's are very simple to interface with the controller as well as are cost
effective and more advantage than 7 segment display.
Its shows clear display to the users
The most commonly used ALPHANUMERIC displays are
1x16 (Single Line & 16 characters),
2x16 (Double Line & 16 character per line),
4x20 (four lines & Twenty characters per line).
9. How the LCD is interfacing with 8051 with diagram? (CO5) (K2)
The LCD requires 3 control lines (RS, R/W & EN) & 8 (or 4) data lines. The
number on data lines depends on the mode of operation.
When R/W is low (0), the information on the data bus is being written to the
LCD.
When RW is high (1), the program is effectively reading from the LCD.
Most of the times there is no need to read from the LCD so this line can
directly be connected to Gnd thus saving one controller line.
The ENABLE pin is used to latch the data present on the data pins. A HIGH
- LOW signal is required to latch the data. The LCD interprets and executes
our command at the instant the EN line is brought low. If you never bring
EN low, your instruction will never be executed.
10.How the stepper motor interfacing with 8051 with diagram? (CO5) (K2)
Using Port C of 8051 for connecting the stepper motor. Here ULN2003 is
used. This is basically a high voltage, high current Darlington transistor array.
Each ULN2003 has seven NPN Darlington pairs. It can provide high voltage
output with common cathode clamp diodes for switching inductive loads.