Documente Academic
Documente Profesional
Documente Cultură
1 Einleitung
Nun endlich schreiben Sie Ihr erstes komplettes ´C´-Programm, durch das der
CC03er mit seiner Umwelt in Kontakt tritt.
Dazu benötigen Sie zunächst einmal die ´C´-Funktion „printf(…)“ zur Ausgabe
von Texten und Zahlen. Verschiedene Steuerzeichen ermöglichen es Ihnen danach,
die Bildschirmgestaltung optimal für Ihre Zwecke und nach Ihren Vorstellungen
aufzubauen.
Jetzt kommen Sie auch mit einem etwas unangenehmen Kapitel in Berührung: mit
Programmfehlern und deren Beseitigung.
Danach geht es weiter mit Zahlen und Zahlensystemen. Sie lernen, welche Daten
bzw. Variablen-Typen es unter ´C´ gibt und welche Rechenfunktionen vorhanden
sind.
Dann betrachten wir die umgekehrte Richtung: Wie gelangen Eingabe-Informatio
nen von der Tastatur zum CC03er?
Sie lernen auch neue ´C´-Strukturen kennen, wie die if-Anweisung, die switch
case-Konstruktion, die while-, die do … while- und die for-Schleife.
Logische Operatoren und Verknüpfungen runden die Betrachtungen zu ´C´ ab.
Selbstverständlich behandeln wir wieder Themen rechts und links vom Mikrocon
troller, wie der Boot-Modus, ESC-Steuersequenzen, logische Grundverknüpfungen
etc.
Chapter 2
2 Lesson 5 'C' Practice 1 - Building a 'C' program
In this lesson you will first learn some basic facts about the
Programming language 'C': about the basic structure of a 'C' program, over which
'C' libraries.
2.1 General
Take a look at the world of microcontroller programming languages You can see very quickly that the
front runner is the language 'C', the Meanwhile, the most original microcontroller language, the
assembler, on has displaced many areas.
- The code optimization, that is, the translated programs are getting shorter and shorter and
exploiting the subtleties of microcontroller-specific hardware programming to the last,
- The running speed, i.e. the programs are running faster and faster and reach almost the
execution speeds of optimal written assembler programs.
"Remember!"
The programming language 'C' does not come with a professional programmer
The industry nowadays more over and also for the committed
Practitioners from other technical fields who want to use microcontrollers are engaging with 'C'
Got to.
Beginners, however, must be aware that the first one Getting into 'C' can sometimes be a bit bumpy.
- At first we introduce you to "C" only as far as it does for the first
low in frustration and ready to run without too much theoretical ballast.
- You can then get to know, exploit and program all the functions of our 8051er with your 'C'
knowledge. More effective for writing
- We will familiarize you step by step with the higher ordinations of 'C' do.
The thing started with 'C' in the seventies of the last century
Messrs. Brian W. Kernigham and Dennis M. Ritchie, who use 'C' as a language, among others.
From then on,'C' gradually turned into a universal programming language that finally emerged in
1988 in its basic elements of the American National
Standard Institute (ANSI) was quasi internationally standardized. This is how the core language ANSI-
C was born.
Over time, when microcontrollers were born, the ANSI-C core has been enhanced with
microcontroller-specific commands to optimally support the properties of these computational
devices. On the microcontroller level you need i.Allg. no large database or Windows applications, but
for example fast-running I / O routines to on-site processes too control and regulate. These aspects
were then supplemented by 'C' for Microcontroller taken into account.
Therefore, we subsequently rely on the ANSI-C core and gradually add microcontroller (8051er) -
specific peculiarities.
# ...
-------------------------------------------------- ----------------------------------------------
-------------------------------------------------- ----------------------------------------------
Start of the main program Start the main function main ():
} (5)
Thus, e.g. The preprocessor automatically replaces the comments in the program with blanks, or
special program libraries with already completed functions are integrated.
Such direct instructions to the preprocessor always start with the "#"-Character.
because you are able to make your programs modular and this exactly to your needs.
From now on, you should always have this structure in front of your inner eye, because
internationally standardized elements and the later added microcontroller specific components,
which are not internationally standardized.
Comments
are essential in every program to
"Through increases".
names
within the program are very important because you identify your variables,
data types
are numbers known from mathematics:
In addition, there are character types, bit types and so-called strings
"If" for programming a conditional branch. They are therefore not allowed
Name a variable with the name if, because then error messages occur.
operators
are shortcuts (one or two pieces) that use certain operations
- Etc.
instructions
of which there are three different types:
a) Simple instructions:
c=a+b
referred to as functions (more precisely, as library functions, since they are all in
y = sin (x);
string processing
At this point, the user will find functions for handling and processing Strings, however, e.g. not so
common in process automation be used.
Microcontroller specific adjustments
Supplement the ANSI-C standard so that 'C' programs can make the most of the special features of
the microcontroller and the user
interrupts
The processing of unpredictable program interruptions (so-called interrupts) represents one of the
most essential and performance-enhancing features of any microcontroller.
Be able to optimally support such "exceptional situations", i. programmatically to realize and work
off as quickly as possible.
pointer
Working with Pointers is another essential feature of 'C',
Preprocessor directives
are commands to the preprocessor that do a certain "preprocessing" of the program text before the
'C' compiler translates that program text.
Each library includes a specific area of expertise. So there are e.g. a Library for purely mathematical
functions, one with functions for string processing, one for input / output functions, etc.
So you never need to "reinvent the wheel", but you can already Use ready-made functions for your
purposes.
In the respective lessons, we will then introduce you to the scope of the most important libraries and
work with them.