TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip...

17
TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE

description

● 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

Transcript of TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip...

Page 1: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

TU STORM

The TU STORM Robot Controller:Innovation First Mini Robot Controller

(Microchip PIC18F8520)Programmable in CUsing MPLAB IDE

Page 2: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

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.

Page 3: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

● 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

Page 4: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

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.

Page 5: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

Why C?

● Modular● Powerful● Industry standard● Fast and efficient

Page 6: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

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

Page 7: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

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 */

Page 8: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

C is case-sensitive

int left_motor;

(is not the same as)

int Left_motor;

Page 9: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

Assignments= operator

Shoulderx = 0.0;

count = count + 1;

General assignment:

variable_name = expression ;

Page 10: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

Arithmetic Operations

C arithmetic operators: + , - , *, /

Can group together expression with parentheses.

result = (a + b) * c;

Page 11: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

Control Structures

if ( condition ) { ... ... // The "then" block of statements. ... } else { ... ... // The "else" block of statements. ... }

Page 12: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

Control Structures

if ( condition_1 ) { ... ... <-- "then" block_1; ... } else if ( condition_2 ) { ... ... <-- "then" block_2; ... } else { ... <-- "else" block; }

Page 13: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

Conditionals

Conditionals are either true or false. Conditionals <- relational / logical operators. Relational operators: ==, !=, >, <, >=, <=.

logical operators: &&, ||, and !

Page 14: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

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; }}

Page 15: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

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;}

Page 16: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

Sample Function

int Doubled_Number(int num2double ){ unsigned int result; // Local variable result = 2 * num2double; // Funtion Calculations return result; // Return value}

Page 17: TU STORM The TU STORM Robot Controller: Innovation First Mini Robot Controller (Microchip PIC18F8520) Programmable in C Using MPLAB IDE.

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().