Download presentation
Presentation is loading. Please wait.
Published byEverett Floyd Modified over 8 years ago
1
Tulsanus Hurricanus Digitalus Mus Controller EDU Processor 10 MIPS Variable space: 2K SRAM Program space: 32K FLASH Serial port Interrupts Timers Direct control of the hardware
2
C Concepts " Modular " Powerful " Industry standard " Fast and efficient
3
Programming in dialect of C No native floating point math. No built in trig functions. optional Assembly Macros GetData() PutData() Get_Analog_Value() function Digital I/O (user chooses) Sixteen 10-bit analog inputs
4
One project, many files
.c-Source Files .h-Header Files .lib-Library Files .lkr-Linker Scripts Edit the.c and.h files Compile Link
5
Variables unsigned char wheel_count; /* range: 0 to 255 */ char wheel_count; /* range: -128 to 127 */ unsigned int wheel_count; /* range: 0 to 65535 */ int wheel_count; /* range: -32768 to 32767 */
6
unsigned int Doubled_Number (unsigned int num2double) { unsigned int result; result = 2 * num2double; return result; } Sample Function LOCAL VARIABLES CODE TO EXECUTE RETURN VALUE Sample Function
7
Pre-Processor Directive The # symbol denotes a pre-processor directive that is evaluated before the compiler takes over. #include ifi_aliases.h MUST be in left-most column!
8
#define preprocessor directive #define identifier replacement-text occurrences of identifier is replaced by replacement- text before compilation " Symbolic constants #define PI 3.14159 all subsequent occurrences of symbol constant PI are replaced with 3.14159 #define FIELD_WIDTH 125 #define FIELD_LENGTH 300
9
#define preprocessor directive #define macro-identifier replacement-text occurrences of macro-identifier is replaced by replacement-text before compilation " Macros #define CIRCLE_AREA(x) (PI*(x)*(x)) when CIRCLE_AREA(x) appears: " The value of x is substituted for x " Then the macro is expanded #define macro-identifier replacement-text occurrences of macro-identifier is replaced by replacement-text before compilation " Macros #define CIRCLE_AREA(x) (PI*(x)*(x)) when CIRCLE_AREA(x) appears: " The value of x is substituted for x " Then the macro is expanded
10
#define preprocessor directive #define CIRCLE_AREA(x) (PI*(x)*(x)) area= CIRCLE_AREA(7) ; // becomes: area= ( 3.14159 * (7) *(7)); area = CIRCLE_AREA(rd +2); //becomes: area = (3.14159 * (rd+2)*(rd+2)); #define FIELD_PERIMETER FIELD_WIDTH*2+FIELD_LENGTH*2 #define CIRCLE_AREA(x) (PI*(x)*(x)) area= CIRCLE_AREA(7) ; // becomes: area= ( 3.14159 * (7) *(7)); area = CIRCLE_AREA(rd +2); //becomes: area = (3.14159 * (rd+2)*(rd+2)); #define FIELD_PERIMETER FIELD_WIDTH*2+FIELD_LENGTH*2
11
Output in C " printf("pwM01 = ",pwd, \n)
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.