0% found this document useful (0 votes)
58 views

Unit-2-2 Mark

The document discusses embedded C programming and provides details about embedded systems, embedded software engineers, object oriented programming in C, project headers, port headers, and real-time operating systems. Key aspects covered include defining embedded programming, reasons for using embedded C, what constitutes an embedded system and embedded software engineer, how to add structure to code, and uses of project and port headers.

Uploaded by

sharmilakumari s
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Unit-2-2 Mark

The document discusses embedded C programming and provides details about embedded systems, embedded software engineers, object oriented programming in C, project headers, port headers, and real-time operating systems. Key aspects covered include defining embedded programming, reasons for using embedded C, what constitutes an embedded system and embedded software engineer, how to add structure to code, and uses of project and port headers.

Uploaded by

sharmilakumari s
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIT-2 – Embedded C

1. Define the term Embedded Programming.


• Embedded systems programming, also known as embedded programming, facilitates the
development of consumer-facing devices that don't use conventional operating systems the way that
desktop computers and mobile devices do.
2. Why do you require Embedded C
• The cost of the hardware used in the embedded c is typically so much low.
• The applications of embedded are incredibly appropriate in industries.
• It takes less time to develop an application program.
• Embedded C can run pre-defined programming.
3. What is an embedded system?
• An embedded system is a computer system with a dedicated function within a larger mechanical or
electrical system, often with real-time computing constraints. It is embedded as part of a complete
device often including hardware and mechanical parts.
4. What is an embedded software engineer?
• Embedded software is computer software, written to control machines or devices that are not
typically thought of as computers. It is typically specialized for the particular hardware that it runs on
and has time and memory constraints.
5. How will you add structure to your code?
 To support these activities, three things to be discussed with respect to it:
o Object-Oriented style of programming with C programs
o To create and use a ‘Project Header’ file
o To create and use a ‘Port Header’ file
6. How to create and use project header file?
 This file encapsulates key aspects of the hardware environment, such as the type of processor to be
used, the oscillator frequency and the number of oscillator cycles required to execute each
instruction.
 This helps to document the system, and makes it easier to port the code to a different processor.

7. How to create and use port header file?


 This brings together all details of the port access from the whole system.
 Like the Project Header, this helps during porting and also serves as a means of documenting
important system features.
8. What is Object Oriented Programming in C?
 Object-Oriented Programming (OOP) is a programming paradigm based on the concept of
"objects", which are data structures that contain data, in the form of fields, often known
as attributes; and code, in the form of procedures, often known as methods.
 A distinguishing feature of objects is that an object's procedures can access and often modify the data
fields of the object with which they are associated (objects have a notion of "this").
 In object-oriented programming, computer programs are designed by making them out of objects
that interact with one another.
 There is significant diversity in object-oriented programming, but most popular languages are class-
based, meaning that objects are instances of classes, which typically also determines their type.
9. What is the classification of programming languages?
The different programming languages may be classified is as a series of generations.
Language generation Example languages
– Machine Code
First-Generation Language (1GL) Assembly Language.
Second-Generation Languages (2GLs) COBOL, FORTRAN
Third-Generation Languages (3GLs) C, Pascal, Ada 83
Fourth-Generation Languages (4GLs) C++, Java, Ada 95
10. Mention the strengths and weaknesses of C++.
• The C++ version has both strengths and weaknesses.
o In the C++ code, the data (_Xyz) are encapsulated in the class: access to these data is
controlled because it is possible only via the two member functions.
o By contrast, the data (Xyz) in the C version are „global‟ variables and can be altered
anywhere in the program. From a design perspective, the C++ code is more elegant. It may
also prove easier to maintain.
o There is a CPU time overhead associated with the C++ code.

11. What is File Based Class?


 It is possible to create „file based classes‟ in C without imposing a significant memory or CPU load:
// BEGIN: File XYZ.C
static int Xyz;
Xyz = 3;
...
printf("%d", Xyz);
// END: File XYZ.C
12. How to split the program into number of classes?
• The functions defined within the file become the member functions in our class, and our whole
program may be split into a number of clearly-defined (file-based) classes.

13. What is Private Member Function?


 Member functions which are accessible only by functions defined within a particular file is called as
private member function.
14. What are the public and private member functions?
 Public „member‟ functions, such as PC_LINK_IO_Write_String_To_Buffer(). Such functions have
their prototypes in the H file.
 A private „member‟ function, PC_LINK_IO_Send_Char(). Such static functions have their
prototypes in the C file.
15. Write an example code for file based C class.
An example for file-based C class (H file) is,
#ifndef _PC_IO_H
#define _PC_IO_H
// Public constants
// Value returned by PC_LINK_Get_Char_From_Buffer if
// no character is available in buffer
#define PC_LINK_IO_NO_CHAR 127
// ------ Public function prototypes --------------------------
void PC_LINK_IO_Write_String_To_Buffer(const char* const);
void PC_LINK_IO_Write_Char_To_Buffer(const char);
char PC_LINK_IO_Get_Char_From_Buffer(void);
// Must call this function frequently...
void PC_LINK_IO_Update(void);
#endif

16. What is The Project Header?


 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 – in one file.
 It is a practical implementation of a standard software design guideline: „Do not duplicate
information in numerous files; place the information in one place, and refer to it where necessary.‟
17. Draw the schematic representation of the project header file.

18. What is a Device Header?


 The first entry in the project header is the link to the appropriate „device header‟ file.
 These files will have been produced by your compiler manufacturer, and will include the addresses
of the special function registers (SFRs) used for port access, plus similar details for other on-chip
components such as analog-to-digital converters.
19. What is Oscillator frequency?
 If we create an application using a particular 8051 device operating at a particular oscillator
frequency, with a particular number of oscillations per instruction, this information will be required
when compiling many of the different source files in our project.
20. What are the Common data types?
 It includes three types of typedef statements: They are,
o typedef unsigned char tByte;
o typedef unsigned int tWord;
o typedef unsigned long tLong;
21. What are the two reasons of typedef statements?
 The two main reasons for using typedef statements are,
o The 8051 does not support signed arithmetic and extra code is required to manipulate signed
data: this reduces your program speed and increases the program size. Wherever possible, it
makes sense to use unsigned data, and these typedef statements make this easier.
o Use of bitwise operators generally makes sense only with unsigned data types: use of
„typedef‟ variables reduces the likelihood that programmers will inadvertently apply these
operators to signed data.
22. What is a real time operating system?
 A real-time operating system (RTOS) is an operating system (OS) intended to serve real-
time application requests.
 It must be able to process data as it comes in, typically without buffering delays.
 Processing time requirements (including any OS delay) are measured in tenths of seconds or shorter.
23. List out some examples for time based interrupts.
 The following lines in the Project Header are intended to make it easier to use (timer-based)
interrupts in our projects:
o #define INTERRUPT_Timer_0_Overflow 1
o #define INTERRUPT_Timer_1_Overflow 3
o #define INTERRUPT_Timer_2_Overflow 5
24. What is the Use of a Project Header?
 Use of Project Header can help to make your code more readable, not least because anyone using
your projects knows where to find key information, such as the model of microcontroller and the
oscillator frequency required to execute the software.
 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.
25. Define Port Header.
 In a typical embedded project, you may have a user interface created using an LCD, a keypad, and
one or more single LEDs.
 There may be a serial (RS-485) link to another microcontroller board.
 There may be one or more high-power devices (3-phase industrial motors) to be controlled.
 Each of these (software) components in your application will require exclusive access to one or more
port pins.
26. Draw the schematic representation of the port header file.

27. Write an example code for port header file.


 Here, all of the port access requirements are spread over multiple files. Instead of this, 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;

 Each of the remaining project files will then „#include‟ the file „Port.H‟.
28. How to meet real time constraints? What is the significance of meet RT constraints.
 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.
 As many other real-time applications, the key characteristic is deterministic processing.
 What this means is that in many real-time embedded systems we need to be able to guarantee that a
particular activity will always be completed within 2 ms: if the processing does not match this
specification, then the application is not simply slower than we would like, it is useless.

29. Draw a high-level schematic view of a simple autopilot system.

30. How to identify problems using some simple switch-interface code?


bit SWITCH_Get_Input(const tByte DEBOUNCE_PERIOD)
{
tByte Return_value = SWITCH_NOT_PRESSED;
if (Switch_pin == 0) {
// Switch is pressed
// Debounce – just wait...
DELAY_LOOP_Wait(DEBOUNCE_PERIOD); // POTENTIAL PROBLEM
// Check switch again
if (Switch_pin == 0) {
// Wait until the switch is released.
while (Switch_pin == 0); // POTENTIAL CATASTROPHE
Return_value = SWITCH_PRESSED;
}}
// Now (finally) return switch value
return Return_value;
}

The first problem is that we wait for a „debounce‟ period in order to confirm that the switch has been
pressed:
DELAY_LOOP_Wait(DEBOUNCE_PERIOD);
31. Write program to create ‘hardware delays’ using Timer 0 and Timer 1. Write the syntax using
Timer 0 and Timer 1.
void DELAY_LOOP_Wait(const unsigned int DELAY)
{ unsigned int x, y;
for (x = 0; x <= DELAY; x++)
{
for (y = 0; y <= 120; y++);
}}
32. What are the timers used to create delay?
 If you want to create more accurate delays, then we can do so using one of the 8051‟s on-chip
timers. These timers can be used to generate accurate delays.
o The TCON SFR
o The TMOD SFR
33. How to calculate hardware delays?
 Building on the calculations of hardware delays generally takes the following form:
o We calculate the required starting value for the timer.
o We load this value into the timer.
o We start the timer.
o The timer will be incremented, without software intervention, at a rate determined by the
oscillator frequency; we wait for the timer to reach its maximum value and „roll over‟.
o The timer signals the end of the delay by changing the value of a flag variable.
34. What is SFR? (Or) Define SFR.
 SFR stands for Special Function Register.
 A Special Function Register or (Special Purpose Register or simply Special Register) is
a register within a microprocessor, which controls or monitors various aspects of the
microprocessor's function.
35. Draw the format of TCON SFR.
 TCON SFR stands for TCON special function register (SFR). The various bits in the TCON SFR
have the following functions:

36. What are the fields available in TCON SFR?


The fields available in TCON SFR are,
 TR0, TR1 Timer Run Control Bits
 TF0, TF1 Timer Overflow Flags
 IE0, IE1 Interrupt Flags
 IT0, IT1 Interrupt Type Control Bit
37. What are Timer Overflow Flag?
 TF0 and TF1 are called as timer overflow flags.
 These bits are set to 1 (by the microcontroller) when the corresponding timer overflows. They need
to be manually cleared (set to 0) by the programmer. Default value (after reset) is 0.
38. What is Interrupt Flag?
 IE0 and IE1 are called as interrupt flags.
 It is set by hardware when an (external) interrupt is detected on Pin 12 or Pin 13, respectively.
 These features are not related to Timer 0 or Timer 1 and are not used in this book (these bits can be
left at their default value).
39. What is Interrupt Control Bit?
 IT0 and IT1 are called as interrupt type control bit.
 It is used to determine with the external interrupt flags (above) are set in response to a falling edge
(„edge triggered‟) or a low-level („level triggered‟) input on the relevant port pins.
 These features are not related to Timer 0 or Timer 1 and are not used in this book (these bits can be
left at their default value).
40. What is TMOD SFR?
 There are three modes of operation (for each timer), set using the M1 and M0 bits.
 Let us consider with Mode 1 and Mode 2, which operate in the same way for both Timer 0 and
Timer 1.

41. What are the fields available in TMOD SFR?


 The fields available in TMOD SFR are,
o Mode 1 (M1 = 1; M2 = 0)
o Mode 2 (M1 = 0; M2 = 1)
o GATE Gating Control
o C / T– Counter or Timer Select Bit
42. What are THx and TLx Registers?
 The final components we need to be aware of are the two 8-bit registers associated with each timer:
these are known as TL0 and TH0, and TL1 and TH1. Here, „L‟ and „H‟ refer to „low‟ and „high‟
bytes, as will become clear shortly.
 If we are using Timer 1 to generate the delays, then the values loaded into TL1 and TH1 at the start
of the delay routine will determine the delay duration.
43. What is Loop Timeout? How to create loop timeouts.
 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.
44. What is Hardware Timeouts? (Nov/Dec 23)
 Consider the ability to meet real-time requirements by code without timeouts and code with a loop
timeout; it is clear that the loop timeout solution is significantly better.
 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.
45. What is Interrupt Service Routine (ISR)?
 An interrupt service routine (ISR) is a software routine that hardware invokes in response to
an interrupt.
 ISRs examine an interrupt and determine how to handle it. ISRs handle the interrupt, and then
return a logical interrupt value.
46. Write an example code for automatic timer reloads.
 In the hardware delay code, we used a code structure like this:
// Preload values for 50 ms delay
TH0 = 0x3C; // Timer 0 initial value (High
Byte) TL0 = 0xB0; // Timer 0 initial value (Low
Byte) TF0 = 0; // Clear overflow flag
TR0 = 1; // Start timer 0
while (TF0 == 0); // Loop until Timer 0 overflows (TF0 ==
1) TR0 = 0; // Stop Timer 0

You might also like