User`s manual

ROBOT . HEAD to TOE
Product User’s Manual – SD02B
Created by Cytron Technologies Sdn. Bhd. – All Rights Reserved
23
6.2 Sample Program for PIC18F4520
Driving stepper motor is common necessity in most robotic project based on the embedded
system which uses microcontroller. Considering this reason, Cytron Technologies has also
developed the sample source code for PIC18F microcontroller using MPLAB C18 C
Compiler. This sample program is developed for PIC18F4520. If user uses different PIC
microcontroller, user may need to modify the sample program based on that particular
microcontroller by referring to its datasheet released by Microchip Technology Inc.
The sample program will control two SD02Bs. Since this PIC only has one hardware UART,
we have to generate another additional UART using software approach to control the second
SD02B.
a. The sample program can be downloaded from Cytron website, (www.cytron.com.my), in
SD02B product page.
b. Extract the file named “Dual UART sample program.zip”.
c. There are 4 files available for the user; 18F sample program.mcp (MPLAB project
file)., 18F sample program.mcw (MPLAB workspace file), 18F4520-dual uart
sample.c (source code in C language) and 18F sample program.hex (HEX file). For
immediate testing, user may load 18F sample program.hex to PIC18F4520 and plug into
microcontroller board which was being completed in step c.
d. The sample program is based on SK40B startup kit. We will discuss about how to control
two SD02Bs and two stepper motor using a SK40B through UART interface.
e. Ensure the hardware interface for microcontroller to SD02B is setup properly. Besides,
the power for stepper motor is also needed. Please refer to section 5.4 for example
connection of SD02B to microcontroller through UART interface.
f. Power indicator LED on SD02B will turn ON when power is supply to microcontroller
board.
g. Please refer to 18F4520-dual uart sample.c for details on method to send/receive
command to SD02B.
h. User must install MPLAB and C18 Compiler if user wants to modify and compile this
sample program. The free MPLAB and C18 Compiler for PIC18 MCU can be obtained
from Microchip official website.