41081 Chapter Notes - Chapter 2: Operand, C Data Types, Embedded System

67 views5 pages
5 Jun 2018
School
Department
Course
Professor
Chapter 2 Embedded Programming
C in Embedded Systems
C and C++ combined represent 81% of embedded programmers and have their
current programs in these languages.
On a global scale, C and C++ have a combined popularity rating of 13%.
It was not originally created for embedded systems but rather for mainframe and
desktop computers which tend to manipulate data in files such as integers or
characters. Thus it was useful for embedded systems which manipulate bits and
occasionally other data types.
C Data Types
Several C datatypes are commonly used to represent integers in embedded system
programs.
Different data types have different sizes and ranges so it is important to select the
smallest possible data type that can be used based on knowledge of the variable to
be used. This ensures that the limited space available in embedded systems are
conserved.
Unsigned data types represent positive integers while signed types represent
positive and negative.
If a variable is used to represent a series of bits rather than a number, an unsigned
data type should be used.
Embedded systems commonly deal with 1-bit data items however C does not have a
1-bit data type. So, 1-bit items are typically represented using an unsigned char, and
the programmer will only assign the variable a 0 or 1.
C also has float and double data types for floating point numbers however their use
is avoided as microcontrollers commonly lack the software required to process these
numbers in order to stay small, low cost, and low power.
When naming variables, it is common practise to use a lower case prefix to indicate
the data type. This helps to esure that larger ostats or ariales aret assiged
to smaller variables.
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in
The char datatype was given the name as it is commonly used to represent the
integer value of an 8-bit ASCII character. NOTE that char is actually an integer.
8 bits is sometimes called a byte.
The use of type it is aoided due to its upreditaility. This ireases the code
portability which is the ability to recompile code for a different microprocessor
without undesirable changes in the program behaviour.
The underlying representation of each datatype is binary.
Siged data types i C use tos opleet represetatio. The iary
representation of a negative uer i tos opleet is otaied y
represetig the uers agitude i iary, opleetig all the its, ad
adding 1.
o Eg. -1
00000001 (magnitude 1)
11111110 (complement)
11111111 (add 1)
Knowing whether an item is signed or unsigned is important when assigning values
and when determining a variables range.
RIMS implicitly defined I/O variables
In RIMS, each microcontroller input and output is implicitly defined as a global
variable. It implicitly defines two additional global variables. A represents the 8-bit
input as a decimal number and B, the 8-bit output.
The RIMS.h file contains these definitions, so a programmer can enable their use
through a #include statement.
As B is a global variable, a program can write as well as read that variable. However,
variable A is automatically written by the microcontroller and should never be
written by a program, only read in RIMS. Writing to A will cause a runtime error,
causing execution to terminate.
C variables can be initialised when declared.
o unsigned char i1 = 5;
The keyword const short for constant, can precede any variable declaration. A
ostat ariales alue aot e haged y later ode, thus helpig to preet
the introduction of future errors. A constant variable must therefore be initialised
when declared.
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows pages 1-2 of the document.
Unlock all 5 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents