SlideShare a Scribd company logo
Basics of Embedded C Program and
Programming Structure for
Beginners
BY
G.KAMESHWARAN.B.E.M.Tech.MISTE.
FOTRONICHS,VELLORE
9791899533
Embedded C Programming is the soul of the processor functioning inside each and
every embedded system we come across in our daily life, such as mobile phone,
washing machine, and digital camera.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
2
 Each processor is associated with an embedded software.
 The first and foremost thing is the embedded software that decides
functioning of the embedded system.
 Embedded C language is most frequently used to program the
microcontroller.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
3
 Earlier, many embedded applications were developed using assembly level
programming. However, they did not provide portability.
 This disadvantage was overcome by the advent of various high level languages
like C, Pascal, and COBOL. However, it was the C language that got extensive
acceptance for embedded systems, and it continues to do so.
 The C code written is more reliable, scalable, and portable; and in fact, much
easier to understand.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
4
About C Language
•C language was developed by Dennis Ritchie in 1969.
•It is a collection of one or more functions, and every function is a collection of
statements performing a specific task.
•C language is a middle-level language as it supports high-level applications
and low-level applications.
•Before going into the details of embedded C programming, we should know
about RAM memory organization.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
5
∗ Salient features of the language
 C language is a software designed with different keywords, data types, variables,
constants, etc.
 Embedded C is a generic term given to a programming language written in C,
which is associated with a particular hardware architecture.
 Embedded C is an extension to the C language with some additional header files.
These header files may change from controller to controller.
 The microcontroller 8051 #include<reg51.h> is used.
∗ The embedded system designers must know about the hardware architecture to write programs.
These programs play prominent role in monitoring and controlling external devices. They also directly
operate and use the internal architecture of the microcontroller, such as interrupt handling, timers,
serial communication and other available features.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
6
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
7
Data typesData types
The data type refers to an extensive system for declaring variables of
different types like integer, character, float, etc.
The embedded C software uses four data types that are used to store data
in the memory.
The ‘char’ is used to store any single character; ‘int’ is used to store integer
value, and ‘float’ is used to store any precision floating point value.
The size and range of different data types on a 32-bit machine is given in
the following table. The size and range may vary on machines with different
word sizes.
The basic additional features of the embedded software
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
8
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
9
KeywordsKeywords
There are certain words that are reserved for doing specific tasks. These
words are known as keywords.
They are standard and predefined in the Embedded C.
Keywords are always written in lowercase. These keywords must be defined
before writing the main program.
The basic keywords of an embedded software are given below:
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
10
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
11
∗ sbit: This data type is used in case of accessing a single bit of
SFR register.
∗ Syntax: sbit variable name = SFR bit ;
∗ Ex: sbit a=P2^1;
∗ Explanation: If we assign p2.1 as ‘a’ variable, then we can use
‘a’ instead of p2.1 anywhere in the program, which reduces
the complexity of the program.
∗ Bit: This data type is used for accessing the bit addressable
memory of RAM (20h-2fh).
∗ Syntax: bit variable name;
∗ Ex: bit c;
∗ Explanation: It is a bit sequence setting in a small data area
that is used by a program to remember something.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
12
∗ SFR: This data type is used for accessing a SFR register by another name. All
the SFR registers must be declared with capital letters.
∗ Syntax: SFR variable name = SFR address of SFR register;
∗ Ex: SFR port0=0x80;
∗ Explanation: If we assign 0x80 as ‘port0’, then we can use 0x80 instead of
port0 anywhere in the program, which reduces the complexity of the
program.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
13
SFR Register:SFR Register:
∗The SFR stands for ‘Special Function Register’. Microcontroller
8051 has 256 bytes of RAM memory.
∗This RAM is divided into two parts: the first part of 128 bytes is
used for data storage, and the other of 128 bytes is used for SFR
registers.
∗All peripheral devices like I/O ports, timers and counters are
stored in the SFR register, and each element has a unique
address.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
14
∗ The Structure of an Embedded C Program
∗ comments
∗ preprocessor directives
∗ global variables
∗ main() function
∗ {
∗ local variables
∗ statements
∗ …………..
∗ …………..
∗ }
∗ fun(1)
∗ {
∗ local variables
∗ statements
∗ …………..
∗ …………..
∗ }
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
15
Comments:
∗In embedded C programming language, we can place
comments in our code which helps the reader to understand
the code easily.
C=a+b; /* add two variables whose value is stored in another variable C*/
Preprocessor directives:Preprocessor directives:
∗All the functions of the embedded C software are included in
the preprocessor library like “#includes<reg51.h>, #defines”.
These functions are executed at the time of running the
program.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
16
Global variableGlobal variable
∗A global variable is a variable that is declared before the
main function, and can be accessed on any function in the
program.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
17
Local variableLocal variable
∗A local variable is a variable declared within a function,
and it is valid only to be used within that function.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
18
Main () functionMain () function
∗The execution of a program starts with the main function.
Every program uses only one main () function.
Advantages of embedded C programAdvantages of embedded C program
∗Its takes less time to develop application program.
∗It reduces complexity of the program.
∗It is easy to verify and understand.
∗It is portable in nature from one controller to another.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
19
∗ Examples of a few Embedded C Programs
∗ The following are a few simple Embedded C programs
used for microcontroller-based projects.
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
20
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
21
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
22
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
23
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
24
 We hope that we have been successful in providing an easy and approachable
way for the beginners of Embedded C programming.
 Better understanding of the Embedded C programming is the most essential
prerequisite for designing embedded based projects.
 In addition to this, a better understanding and proper knowledge about
embedded C programming help students immensely in the selection of a
rewarding career.
 We encourage and welcome queries, suggestions and comments from our
readers.
 Therefore, you can post your queries and feedback about this article in the
comments section given below. Follow the below link for:
fotronichsvellore@gmail.com, www,fotronichs.com
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
25
G.KAMESHWARAN.B.E,M.Tech,MISTE
www.fotronichs.com
26

More Related Content

What's hot (20)

PDF
Typical Embedded System
anand hd
 
PPTX
Register transfer language
Sanjeev Patel
 
PPTX
Embedded system design process
RAMESHBABU311293
 
PPTX
Intel 8051 Programming in C
Sudhanshu Janwadkar
 
PPSX
Lect 2 ARM processor architecture
Dr.YNM
 
PPT
Ccp
babak danyal
 
PPTX
WCDMA
Harshal Tiwari
 
PDF
Programed I/O Modul..
Myster Rius
 
PPTX
PIC Microcontrollers
Abdullah Saghir Ahmad
 
PPTX
Salient featurs of 80386
aviban
 
PPTX
Ch 1 introduction to Embedded Systems (AY:2018-2019--> First Semester)
Moe Moe Myint
 
PPTX
Input & Output
Dilum Bandara
 
PPTX
Finite State Machine.ppt.pptx
SKUP1
 
PPTX
Instruction cycle &amp; machine cycle
ManishTadhiyal
 
PDF
Unit7 & 8 performance analysis and optimization
leenachandra
 
PDF
VHDL- gate level modelling
VandanaPagar1
 
PPTX
Design challenges in embedded systems
mahalakshmimalini
 
PPT
8086-instruction-set-ppt
jemimajerome
 
PPTX
Introduction to System verilog
Pushpa Yakkala
 
PDF
Digital and Logic Design Chapter 1 binary_systems
Imran Waris
 
Typical Embedded System
anand hd
 
Register transfer language
Sanjeev Patel
 
Embedded system design process
RAMESHBABU311293
 
Intel 8051 Programming in C
Sudhanshu Janwadkar
 
Lect 2 ARM processor architecture
Dr.YNM
 
Programed I/O Modul..
Myster Rius
 
PIC Microcontrollers
Abdullah Saghir Ahmad
 
Salient featurs of 80386
aviban
 
Ch 1 introduction to Embedded Systems (AY:2018-2019--> First Semester)
Moe Moe Myint
 
Input & Output
Dilum Bandara
 
Finite State Machine.ppt.pptx
SKUP1
 
Instruction cycle &amp; machine cycle
ManishTadhiyal
 
Unit7 & 8 performance analysis and optimization
leenachandra
 
VHDL- gate level modelling
VandanaPagar1
 
Design challenges in embedded systems
mahalakshmimalini
 
8086-instruction-set-ppt
jemimajerome
 
Introduction to System verilog
Pushpa Yakkala
 
Digital and Logic Design Chapter 1 binary_systems
Imran Waris
 

Viewers also liked (20)

PDF
Embedded C - Lecture 1
Mohamed Abdallah
 
PDF
Embedded c
Nandan Desai
 
PPTX
Embedded c
Ami Prakash
 
PPT
Introduction To Embedded Systems
Vishwa Mohan
 
PPT
Embedded System Basics
Dr M Muruganandam Masilamani
 
DOC
Basic construction of c
kinish kumar
 
PPTX
Overview of embedded system
Dhruwank Vankawala
 
DOCX
15 el83 automatic washing machine using microchip pic18f series microcontro...
amjad ali janwari
 
PPT
Embedded system - embedded system programming
Vibrant Technologies & Computers
 
PPTX
States & Capitals 111
Bermanburgh
 
PPT
C++ for Embedded Programming
Colin Walls
 
PPTX
Embedded c programming
PriyaDYP
 
ODP
C prog ppt
xinoe
 
PPTX
Embedded C
Krunal Siddhapathak
 
PDF
Programming with c language practical manual
Anil Bishnoi
 
PPT
Embeded system by Mitesh Kumar
Mitesh Kumar
 
PPTX
Embedded C workshop
Mostafa El-koumy
 
PPTX
Embeded system
sanjay joshi
 
PPT
Embedded systems
Rajanikanth U
 
PPTX
S3 Individual Presentation - Washing Machine
no suhaila
 
Embedded C - Lecture 1
Mohamed Abdallah
 
Embedded c
Nandan Desai
 
Embedded c
Ami Prakash
 
Introduction To Embedded Systems
Vishwa Mohan
 
Embedded System Basics
Dr M Muruganandam Masilamani
 
Basic construction of c
kinish kumar
 
Overview of embedded system
Dhruwank Vankawala
 
15 el83 automatic washing machine using microchip pic18f series microcontro...
amjad ali janwari
 
Embedded system - embedded system programming
Vibrant Technologies & Computers
 
States & Capitals 111
Bermanburgh
 
C++ for Embedded Programming
Colin Walls
 
Embedded c programming
PriyaDYP
 
C prog ppt
xinoe
 
Programming with c language practical manual
Anil Bishnoi
 
Embeded system by Mitesh Kumar
Mitesh Kumar
 
Embedded C workshop
Mostafa El-koumy
 
Embeded system
sanjay joshi
 
Embedded systems
Rajanikanth U
 
S3 Individual Presentation - Washing Machine
no suhaila
 
Ad

Similar to Embedded c program and programming structure for beginners (20)

PPTX
Embedded C.pptx
MusthafaKadersha
 
PPTX
Unit-2.pptx
sidhantkulkarni1
 
PDF
Introduction To C++ programming and its basic concepts
ssuserf86fba
 
PPTX
C programming
Rohan Gajre
 
PDF
C Tutorials
Sudharsan S
 
PPTX
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
rajkumar490591
 
PDF
Unit 2 introduction to c programming
Mithun DSouza
 
PDF
Consider the following interrupting system. The active-edge inputs o.pdf
fasttrackscardecors
 
PPTX
Introduction to c language
BAKRANIYA KALPESH
 
DOCX
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
Rajeshkumar Reddy
 
PPTX
C language
marar hina
 
PDF
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Batra Centre
 
PPTX
Introduction to computers, input and output devices
kavyashrikp
 
DOCX
Resume
Anil Kumar
 
DOCX
C tutorials
Amit Kapoor
 
PPT
Embedded systems
PROVAB TECHNOSOFT PVT. LTD.
 
PDF
C programming session9 -
Keroles karam khalil
 
PPTX
Unit-1_c.pptx you from the heart of the day revision
MohammedAnas871930
 
PDF
CS8251_QB_answers.pdf
vino108206
 
DOCX
Programming In C- (1)jhgjhgjhgjhghj.docx
Dpak Chavan
 
Embedded C.pptx
MusthafaKadersha
 
Unit-2.pptx
sidhantkulkarni1
 
Introduction To C++ programming and its basic concepts
ssuserf86fba
 
C programming
Rohan Gajre
 
C Tutorials
Sudharsan S
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
rajkumar490591
 
Unit 2 introduction to c programming
Mithun DSouza
 
Consider the following interrupting system. The active-edge inputs o.pdf
fasttrackscardecors
 
Introduction to c language
BAKRANIYA KALPESH
 
C LANGUAGE UNIT-1 PREPARED BY MVB REDDY
Rajeshkumar Reddy
 
C language
marar hina
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
Batra Centre
 
Introduction to computers, input and output devices
kavyashrikp
 
Resume
Anil Kumar
 
C tutorials
Amit Kapoor
 
Embedded systems
PROVAB TECHNOSOFT PVT. LTD.
 
C programming session9 -
Keroles karam khalil
 
Unit-1_c.pptx you from the heart of the day revision
MohammedAnas871930
 
CS8251_QB_answers.pdf
vino108206
 
Programming In C- (1)jhgjhgjhgjhghj.docx
Dpak Chavan
 
Ad

More from Kamesh Mtec (10)

PDF
Water level indicator abstract
Kamesh Mtec
 
PDF
Voltage doubler
Kamesh Mtec
 
PDF
Over voltage abstract
Kamesh Mtec
 
PDF
Letter box abstract
Kamesh Mtec
 
PDF
Cell abstract
Kamesh Mtec
 
PDF
11.automatic water tap control abstract
Kamesh Mtec
 
PDF
4.fire detector abstract
Kamesh Mtec
 
PDF
3.automatic street light abstract
Kamesh Mtec
 
PDF
2.pir based abstract
Kamesh Mtec
 
PDF
Project titles 2015 16
Kamesh Mtec
 
Water level indicator abstract
Kamesh Mtec
 
Voltage doubler
Kamesh Mtec
 
Over voltage abstract
Kamesh Mtec
 
Letter box abstract
Kamesh Mtec
 
Cell abstract
Kamesh Mtec
 
11.automatic water tap control abstract
Kamesh Mtec
 
4.fire detector abstract
Kamesh Mtec
 
3.automatic street light abstract
Kamesh Mtec
 
2.pir based abstract
Kamesh Mtec
 
Project titles 2015 16
Kamesh Mtec
 

Recently uploaded (20)

PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PPT
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
PPTX
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
DOCX
DLL english grade five goof for one week
FlordelynGonzales1
 
PPTX
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
PPTX
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PPTX
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
PDF
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
PDF
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
PDF
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
PPTX
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
PDF
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
PPTX
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
PDF
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PPTX
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
DLL english grade five goof for one week
FlordelynGonzales1
 
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
The Power of Compound Interest (Stanford Initiative for Financial Decision-Ma...
Stanford IFDM
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 

Embedded c program and programming structure for beginners

  • 1. Basics of Embedded C Program and Programming Structure for Beginners BY G.KAMESHWARAN.B.E.M.Tech.MISTE. FOTRONICHS,VELLORE 9791899533
  • 2. Embedded C Programming is the soul of the processor functioning inside each and every embedded system we come across in our daily life, such as mobile phone, washing machine, and digital camera. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 2
  • 3.  Each processor is associated with an embedded software.  The first and foremost thing is the embedded software that decides functioning of the embedded system.  Embedded C language is most frequently used to program the microcontroller. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 3
  • 4.  Earlier, many embedded applications were developed using assembly level programming. However, they did not provide portability.  This disadvantage was overcome by the advent of various high level languages like C, Pascal, and COBOL. However, it was the C language that got extensive acceptance for embedded systems, and it continues to do so.  The C code written is more reliable, scalable, and portable; and in fact, much easier to understand. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 4
  • 5. About C Language •C language was developed by Dennis Ritchie in 1969. •It is a collection of one or more functions, and every function is a collection of statements performing a specific task. •C language is a middle-level language as it supports high-level applications and low-level applications. •Before going into the details of embedded C programming, we should know about RAM memory organization. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 5
  • 6. ∗ Salient features of the language  C language is a software designed with different keywords, data types, variables, constants, etc.  Embedded C is a generic term given to a programming language written in C, which is associated with a particular hardware architecture.  Embedded C is an extension to the C language with some additional header files. These header files may change from controller to controller.  The microcontroller 8051 #include<reg51.h> is used. ∗ The embedded system designers must know about the hardware architecture to write programs. These programs play prominent role in monitoring and controlling external devices. They also directly operate and use the internal architecture of the microcontroller, such as interrupt handling, timers, serial communication and other available features. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 6
  • 8. Data typesData types The data type refers to an extensive system for declaring variables of different types like integer, character, float, etc. The embedded C software uses four data types that are used to store data in the memory. The ‘char’ is used to store any single character; ‘int’ is used to store integer value, and ‘float’ is used to store any precision floating point value. The size and range of different data types on a 32-bit machine is given in the following table. The size and range may vary on machines with different word sizes. The basic additional features of the embedded software G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 8
  • 10. KeywordsKeywords There are certain words that are reserved for doing specific tasks. These words are known as keywords. They are standard and predefined in the Embedded C. Keywords are always written in lowercase. These keywords must be defined before writing the main program. The basic keywords of an embedded software are given below: G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 10
  • 12. ∗ sbit: This data type is used in case of accessing a single bit of SFR register. ∗ Syntax: sbit variable name = SFR bit ; ∗ Ex: sbit a=P2^1; ∗ Explanation: If we assign p2.1 as ‘a’ variable, then we can use ‘a’ instead of p2.1 anywhere in the program, which reduces the complexity of the program. ∗ Bit: This data type is used for accessing the bit addressable memory of RAM (20h-2fh). ∗ Syntax: bit variable name; ∗ Ex: bit c; ∗ Explanation: It is a bit sequence setting in a small data area that is used by a program to remember something. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 12
  • 13. ∗ SFR: This data type is used for accessing a SFR register by another name. All the SFR registers must be declared with capital letters. ∗ Syntax: SFR variable name = SFR address of SFR register; ∗ Ex: SFR port0=0x80; ∗ Explanation: If we assign 0x80 as ‘port0’, then we can use 0x80 instead of port0 anywhere in the program, which reduces the complexity of the program. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 13
  • 14. SFR Register:SFR Register: ∗The SFR stands for ‘Special Function Register’. Microcontroller 8051 has 256 bytes of RAM memory. ∗This RAM is divided into two parts: the first part of 128 bytes is used for data storage, and the other of 128 bytes is used for SFR registers. ∗All peripheral devices like I/O ports, timers and counters are stored in the SFR register, and each element has a unique address. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 14
  • 15. ∗ The Structure of an Embedded C Program ∗ comments ∗ preprocessor directives ∗ global variables ∗ main() function ∗ { ∗ local variables ∗ statements ∗ ………….. ∗ ………….. ∗ } ∗ fun(1) ∗ { ∗ local variables ∗ statements ∗ ………….. ∗ ………….. ∗ } G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 15
  • 16. Comments: ∗In embedded C programming language, we can place comments in our code which helps the reader to understand the code easily. C=a+b; /* add two variables whose value is stored in another variable C*/ Preprocessor directives:Preprocessor directives: ∗All the functions of the embedded C software are included in the preprocessor library like “#includes<reg51.h>, #defines”. These functions are executed at the time of running the program. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 16
  • 17. Global variableGlobal variable ∗A global variable is a variable that is declared before the main function, and can be accessed on any function in the program. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 17
  • 18. Local variableLocal variable ∗A local variable is a variable declared within a function, and it is valid only to be used within that function. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 18
  • 19. Main () functionMain () function ∗The execution of a program starts with the main function. Every program uses only one main () function. Advantages of embedded C programAdvantages of embedded C program ∗Its takes less time to develop application program. ∗It reduces complexity of the program. ∗It is easy to verify and understand. ∗It is portable in nature from one controller to another. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 19
  • 20. ∗ Examples of a few Embedded C Programs ∗ The following are a few simple Embedded C programs used for microcontroller-based projects. G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 20
  • 25.  We hope that we have been successful in providing an easy and approachable way for the beginners of Embedded C programming.  Better understanding of the Embedded C programming is the most essential prerequisite for designing embedded based projects.  In addition to this, a better understanding and proper knowledge about embedded C programming help students immensely in the selection of a rewarding career.  We encourage and welcome queries, suggestions and comments from our readers.  Therefore, you can post your queries and feedback about this article in the comments section given below. Follow the below link for: [email protected], www,fotronichs.com G.KAMESHWARAN.B.E,M.Tech,MISTE www.fotronichs.com 25