Download presentation
Presentation is loading. Please wait.
Published byCalvin McLaughlin Modified over 8 years ago
1
TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE
2
Installing MPLAB ● Use C-Bot CD to install: ● Step 1: MPLAB IDE ● Step 2: C18 Compiler ● Download IFI Loader from TU-STROM Web site and install it. ● Download default TU- STORM Project code for TU-STORM Web site.
3
● Start MPLAB IDE ● File -> Open Workspace… ● Select the.mcw file from the TU-STORM project you downloaded. ● Double-click user_routines.c in project window. ● Scroll down and edit Default_Routine(). ● Project -> Make ● Verify BUILD SUCCEEDED
4
Download Code to Robot Controller ● Connect serial cable from PC to IFI Controller. ● Power up IFI Controller ● Start IFI_Loader. ● Browse to find the.hex file that was just compiled. ● Click DOWNLOAD.
5
Why C? ● Modular ● Powerful ● Industry standard ● Fast and efficient
6
TU-STROM Project ●.c-Source Files ●.h-Header Files ●.lib-Library Files ●.lkr-Linker Scripts ● Edit the.c and.h files ● Compile ● Link TUStormCode.hex
7
Variables in C unsigned char left_motor; /* range: 0 to 255 */ char left_motor; /* range: -128 to 127 */ unsigned int Left_BW_Sensor; /* range: 0 to 65535 */ int Left_BW_Sensor; /* range: -32768 to 32767 */
8
C is case-sensitive int left_motor; (is not the same as) int Left_motor;
9
Assignments = operator Shoulderx = 0.0; count = count + 1; General assignment: variable_name = expression ;
10
Arithmetic Operations C arithmetic operators: +, -, *, / Can group together expression with parentheses. result = (a + b) * c;
11
Control Structures if ( condition ) {...... // The "then" block of statements.... } else {...... // The "else" block of statements.... }
12
Control Structures if ( condition_1 ) {...... <-- "then" block_1;... } else if ( condition_2 ) {...... <-- "then" block_2;... } else {... <-- "else" block; }
13
Conditionals Conditionals are either true or false. Conditionals <- relational / logical operators. Relational operators: ==, !=, >, =, <=. logical operators: &&, ||, and !
14
Control Structures if ((TopSw==ON)&&(MidSw==OFF)&&(BotSw==OFF)){ if ((RightBW < RgtBWThreshold) || (Flag == 1)){ RightMotor = RightIdle; LeftMotor = LeftIdle; } else { RightMotor = RightIdle + Speed; LeftMotor = LeftIdle - Speed; }
15
Definition of C Functions return_value_type func_name( declaration_of_arguments list ) {... return_value_type return_value; // declare return value variable and type.... //Block of function statements.... return return_value; }
16
Sample Function int Doubled_Number(int num2double ) { unsigned int result; // Local variable result = 2 * num2double; // Funtion Calculations return result; // Return value }
17
Output to the Screen printf() command to display the values of Lmotor, Rmotor. /* printf example */ unsigned char Lmotor, Rmotor;.... printf("Lmotor = %d, Rmotor = %d\n", (int)Lmotor,(int)Rmotor); Note: ( Lmotor, Rmotor ) are of type unsigned char. Must be typecast as int to work with printf().
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.