留学生辅导 MEC302 Embedded Computer Systems – cscodehelp代写
MEC302 Embedded Computer Systems
Basics of Embedded C Program
Dr. Sanghyuk Lee
Copyright By cscodehelp代写 加微信 cscodehelp
Embedded C
• Embedded C, the most popular and most used Programming Languages in the development of Embedded Systems.
• This is not a programming module so we will just look at some of the Basics of an Embedded C Program and the Programming Structure of Embedded C.
Programming Embedded Systems
• Embedded Software or Program allow Hardware to monitor external events (Inputs) and control external devices (Outputs) accordingly.
• During this process, the program for an Embedded System may have to directly manipulate the internal architecture of the Embedded Hardware (usually the processor) such as Timers, Serial Communications Interface, Interrupt Handling, and I/O Ports etc.
Introduction to Embedded C
• Embedded C Programming Language is an extension of C Program Language.
• The Embedded C Programming Language uses the same syntax and semantics of the C Programming Language like main function, declaration of datatypes, defining variables, loops, functions, statements, etc.
Introduction to Embedded C
• The extension in Embedded C from standard C Programming Language include I/O Hardware Addressing, fixed point arithmetic operations, accessing address spaces, etc.
• C Programming Language is generally used for developing desktop applications whereas Embedded C is used in the development of Microcontroller based applications.
Basic of Embedded C Program
• Keywords in Embedded C
• A Keyword is a special word with a special meaning to the compiler (a C Compiler for example, is a software that is used to convert program written in C to Machine Code). For example, if we take the Keil’s Cx51 Compiler (a popular C Compiler for 8051 based Microcontrollers) the following are some of the keywords:
• sbit • small • Large
These are few of the many keywords associated with Cx51 C Compiler along with the standard C Keywords.
Basic of Embedded C Program
• To facilitate many of the features of the 8051, the Cx51 Compiler adds a number of new keywords to the scope of the C language:
•_at_ •alien •bdata •bit •code •compact •data
•idata •interrupt •large •pdata •_priority_ •reentrant
•sbit •sfr •sfr16 •small •_task_ •using •xdata
Confer : https://www.keil.com/support/man/docs/c51/c51_le_keywords.htm
Data Types in Embedded C Program
Data Types in C Programming Language (or any programming language for that matter) help us declaring variables in the program. There are many data types in C Programming Language like signed int, unsigned int, signed char, unsigned char, float, double, etc. In addition to these there are few more data types in Embedded C. The following are the extra data types in Embedded C associated with the Keil’s Cx51 Compiler.
• bit • sbit(type defines a bit within a SFR)• sfr(special function register) • sfr16(16-bit special function register)
Following table shows some of the data types in Cx51 compiler along with their ranges
Basic Structure of Embedded C Program
Basic Structure of Embedded C Program
• Comments: Comments are readable text that are written to help us (the reader) understand the code easily. They are ignored by the compiler and do not take up any memory in the final code (after compilation).
• There are two ways you can write comments: one is the single line comments denoted by // and the other is multiline comments denoted by /*….*/.
Basic Structure of Embedded C Program
• Preprocessor Directive: A Preprocessor Directive in Embedded C is an indication to the compiler that it must look in to this file for symbols that are not defined in the program.
• In C Programming Language (also in Embedded C), Preprocessor Directives are usually represented using #include… or #define….
Basic Structure of Embedded C Program
• In Embedded C Programming, we usually use the preprocessor directive to indicate a header file specific to the microcontroller, which contains all the SFRs and the bits in those SFRs.
• In case of 8051, has the file “reg51.h”, which must be written at the beginning of every Embedded C Program.
=> It is header file made by Keil, it includes various register definition inside of header file. It is specified tool for the 8051 family.
Basic Structure of Embedded C Program
• Global Variables: Global Variables, as the name suggests, are Global to the program i.e. they can be accessed anywhere in the program.
• Local Variables: Local Variables, in contrast to Global Variables, are confined to their respective function.
• Main Function: Every C or Embedded C Program has one main function, from where the execution of the program begins.
Example of Embedded C Program
• The image shows the circuit diagram that contains an 8051 based Microcontroller (AT89S52) along with its basic components (like RESET Circuit, Oscillator Circuit, etc.) and components for blinking LEDs (LEDs and Resistors).
Embedded vs General Computing Software
• Typically, an Embedded System program will continue running (in a loop) and not reset.
• This can cause some subtle problems. – ex. wrong priority order from outside
See you in the next class
程序代写 CS代考 加微信: cscodehelp QQ: 2235208643 Email: kyit630461@163.com