You are on page 1of 29

R RP PC C1 1 H He ex xa ab bo ot t

D De es si ig gn n R Re ep po or rt t


www.digilentinc.com/events/DDC2011


page 1 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.




RPC1 Hexabot

Electrical Engineer (student) Robert Rou
robert.rosu89@gmail.com


Submitted for the 2011 Digilent Design Contest

Cluj-Napoca, Romania

May 14
th
15
th
, 2011

Advisor: Assist. Dr. Eng. Adrian - Vasile Duka

Petru Maior University
Trgu Mure











RPC1 Hexabot Design Report


www.digilentinc.com page 2 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.


RPC1
Hexabot

Radio controlled
6 legs
LCD display

RPC1 Hexabot Design Report


www.digilentinc.com page 3 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.


Introduction



RPC1 Hexabot is an 18 servo driven, 6 legged robot, controlled using the Cerebot 32MX4
development board. The user will be able to choose different sequences for the mechanical system to
execute and an LCD will display different messages during the execution. These sequences include
forward and sideways motion as well as a remote controlled movement. This type of movement will
allow the robot to navigate in a certain area, driving itself towards a certain object (a laser beam dot or
a colored ball) based on the information provided by a web cam and a PC software which survey that
area.
Wireless radio transmission will be used for sending the robot coordinates. The reason behind the
development of this project represents the challenge provided by both the programming and the
implementation of the mechanic design. Also it is a great example of how you can combine the
functionality of PIC microcontrollers with the utility of servomotors and the control of the system from
the distance using wireless radio transmission.
The name RPC1 Hexabot comes from Roberts PIC Controlled first 6 legged robot



Objectives


The objectives of the project where:

1. Improvement of programming skills
Implement timers
Access different Ports of the Cerebot MX4 using the SWT Pmod
Display any given message on the CLP Pmod
Generate a PWM signal for servo command
Write a sequence for a certain type of movement
Transmit wireless data to the Cerebot MX4 from a PIC 18F4455 microcontroller
2. Designing a structure for the RPC1 hexabot
Create Base plates for the robot using a light material (ABS)
Create connector elements for each leg using the same material (ABS)
Design the PCB for the PIC 18F4455 microcontroller and other circuits










RPC1 Hexabot Design Report


www.digilentinc.com page 4 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.



Project Summary

In order for a proper design to be implemented, a suitable way for cutting and fitting all the
elements has to be found. If possible, a CNC machine can relief us from a lot of headache. If not,
other cutting tools can be used as seen below. As a material for the mechanical parts, metal
(aluminum, steel), wood or ABS can be used, but take into consideration the overall weight of the
robot and also of each servo, as the servos can only lift a certain amount. For the RPC1 Hexabot I
decided upon ABS due to the fact that it is easy to work with and it is a light material which doesnt
add any unnecessary weight to the project.

For the wireless transmission, a PIC 18F4455 microcontroller is used and also another circuit to lower
the voltage from 5V that the PIC 184455 has on its pins to 3V needed for the Pmod RF1.

Regarding the hardware design of the project, this didnt prove out to be as effective as expected due
to several issues that are presented further on.



Digilent Products Required


In the table below you can find the Digilent components required for the project:



















Table 1. Digilent products required




1

RPC1 Hexabot Design Report


www.digilentinc.com page 5 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.


Tools Required


No Tool Quantity Notes
1 Cutting tool (CNC ideally ) 1
Used to machine the parts ( For this
project a saw was used)
2 ABS plates 3
2 20 mm thick
1 50 mm thick
3 Glue 1
Needed if the parts are machined from
ABS, as each leg is made of a
transparent plate between other two
thinner plates which you can glue for a
better look or also can use s
4 Black Paint 1 In case the plates have a different color
5 Wires For wiring the electronics
6 Nuts and bolts For holding in place all the elements
7 Soldering Iron
For soldering the components required for
the PIC 18F4455 microcontroller and
other circuits

Table 2. Tools required



Design Status


The design of the project is mostly completed; the main problem with it is the fact that the robot is not
stable enough for a proper movement sequence to be implemented and adding the battery packs as
planned is not recommended.


Background


Why This Project?

The idea behind this project was to gain experience with new products and also this was an idea for a
thesis.









RPC1 Hexabot Design Report


www.digilentinc.com page 6 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.

Reference Material

The PWM Signal:
The signal that we need to create in order to control the servos is called a Pulse Width
Modulation signal or PWM for short. The general requirements are:

Frequency: 50Hz
Up - time: 0.9ms -> 2.1ms
Down - time: 19.1ms - 17.9ms


At first glance these definitions & numbers might make little or no sense, so below you can see
a simple PWM wave at 50Hz:


Figure 1. PWM signal

So a PWM wave is just a signal that changes between 0 volts & 5 volts (digital logic 0 and 1).
We see that the wave is symmetrical; uptime is 10mS & downtime is 10mS which when added
together give us the period (10mS + 10mS = 20mS). This means that controlling the servos is fairly
simple:

1. Implement a timer that generates an interrupt service routine (ISR) after every 20ms
2. In the ISR function add your code for the PWM

Also the Cerebot MX4 enables us to implement the PWM signal in software or hardware mode. This
project illustrates a software mode for an implementation.





RPC1 Hexabot Design Report


www.digilentinc.com page 7 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
Design

Features and Specifications


The RPC1 Hexabot has a structure made of ABS, this is a material which is both light weight
(comparing to metal for example) and rigid enough to support all the components. As a power source
for the Cerebot MX4 four AA, 2300mA, 1.2V batteries are used which provide enough voltage and
current for the microcontroller.
One of the most interesting feature of the project is the RF1 Pmod which is attached to the
Cerebot MX4, enabling the robot to be controlled wirelessly using another Pmod RF1 and a PIC
18F4455 microcontroller connected to a PC. Also using a simple SWT Pmod, the user can chose a
sequence of movements implemented.


Design Overview

1. Block Diagram:



Figure 2. Block Diagram forRPC1 Hexabot

As you can see in the diagram above, each leg is made of 3 servos, and each leg is connected to
the base plates be one servo. The Pmod SWT enables the selection of a certain sequence and the
Pmod CLP displays the corresponding message. In the front you can see the proximity sensors that
allow the detection of nearby objects so that the RPC1 Hexabot doesnt hit anything in its way.






RPC1 Hexabot Design Report


www.digilentinc.com page 8 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
2. PIC 18F4455 microcontroller:

This microcontroller was chosen as a processing unit for the radio transceiver because it has a
similar bit configuration with the Cerebot MX4 and also it is easy to program. Below you can see the
schematic and Bottom Layer for the PCB:


o Schematic:









Figure 3. PIC 18F4455 schematic




RPC1 Hexabot Design Report


www.digilentinc.com page 9 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
o Bottom Layer:

Figure 4. Bottom Layer

Detailed Design Description

Parts for the structure of RPC1 Hexabot



























Figure 5. Base Plate and leg parts
140.00 mm
Battery
Holder
(4 x AA)
Battery
Pack

RPC1 Hexabot Design Report


www.digilentinc.com page 10 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.


In Figure 5 the position of the servos that connect each leg to the base plate is illustrated. Also, in
the middle of the base plate, two power supplies are shown which can be removed if not available.


Detailed leg structure:

















The picture above illustrates how the servos are positioned. This is just an example, as this leg
structure can be altered by changing the position of servo 1.

Top view




GWS servos: 1, 4, 7, 10, 13 and 16 will be
the base joints of the RPC1 Hexabot, their
role being that of moving each leg structure
back and forth. The GWS servos: 2, 5, 8, 11,
14 and 17 will lift the 3, 6, 9, 12, 15 and 18
GWS servos of each leg structure from the
ground and also the 3, 6, 9, 12, 15 and 18
GWS servos will ensure a smoother up and
down movement of each leg. In a sequence
these servos will ensure the movement of the
RPC1 Hexabot.





Figure 6. Leg structure

RPC1 Hexabot Design Report


www.digilentinc.com page 11 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.



Discussion

Problems Encountered

The design of the project didnt prove out to be as effective as expected due to several issues:

Lack of experience in designing mechanical systems lead to a structure which wasnt as sturdy
as it should have been, the main concern being the way each servo that links the leg to the
base plates was connected. If your personal knowledge is not enough for designing the
mechanics for the project, do turn to experienced people for expertise.
Lack of proper cutting tools for creating the parts lead to parts that were not perfectly
symmetrical. As an advice, if possible use a CNC machine or any kind of vertical bench saw
that can do the work for you.
Lack of datasheets for the servos was a very big issue as the power consumption of the
servos and other specs were not available. This lead to problems when trying to power all the
robot using battery packs. As an advice, calculate the power consumption for all components
or try to properly estimate so when buying the battery packs unpleasant situations can be
avoided.
Another factor which didnt work in our favor was the time period for the project
Also a problem was the fact that the components arrived after three weeks into the project so
a lot of the designing, manufacturing and programming time was delayed. Try to organize your
time and also delegate the work needed during the project. This way you will have time to
finish the project in time. Also try to team up with colleagues, it will make spare you a lot of
effort.



Engineering Resources Used

The designing and manufacturing of the parts lasted around 3 weeks and the rest of the time on the
project was invested in programming the components.


References

In the designing process the following software was used:

CorelDraw used to design the mechanical parts
Sprint Layout used to design the PCBs used
Roborealm used for image processing needed to determine the coordinates



RPC1 Hexabot Design Report


www.digilentinc.com page 12 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
Appendix A: RPC1

/************************************************************************/
/*
*/
/* main.c -- */
/*
*/
/************************************************************************/
/* Author: Robert Rou
*/ Contact: robert.rosu89@gmail.com
/* Copyright
*/
/************************************************************************/
/* This code implements a sequence using the servos connected
/* to the base plates of the robot and displays the proper message
*/ on the LCD.
/************************************************************************/
// Required hardware:
/* - Cerebot 32MX4
- PmodCON3 - R/C servo connectors
- GWS Servo Kit
- PmodCLP - Character LCD w/ parallel
Interface
- PmodSWT - Slide switches
- Battery Holder (4 x AA )
- PmodRF1 - Wireless Radio Transceiver
*/
/************************************************************************/

/* ------------------------------------------------------------ */
/* Include File Definitions
*/
/* ------------------------------------------------------------ */

#include <p32xxxx.h>
#include <plib.h>


/* ------------------------------------------------------------ */
/* Local Type Definitions
*/
/* ------------------------------------------------------------ */

#define RS LATAbits.LATA2 // Register select: high for data
transfer, low for instruction register
#define R_W LATAbits.LATA3 // Read/write signal: high for read
mode, low for write mode
#define E LATAbits.LATA6 // Read/write strobe: high for read OE;
falling edge writes data

#define D0 LATDbits.LATD14 // ----------------------------
#define D1 LATDbits.LATD15
#define D2 LATFbits.LATF2

RPC1 Hexabot Design Report


www.digilentinc.com page 13 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
#define D3 LATFbits.LATF8
#define D4 LATDbits.LATD13 // Data Bus for LCD
#define D5 LATDbits.LATD3
#define D6 LATDbits.LATD11
#define D7 LATCbits.LATC3 // ----------------------------
// Variables for the servos
// All directions ar from
the back view of the robot
// Lower servos
#define servo1 LATFbits.LATF0 // Back left lower servo
#define servo2 LATGbits.LATG15 // Middle left lower servo
#define servo3 LATGbits.LATG13 // Front left lower servo
#define servo4 LATGbits.LATG12 // Front right lower servo
#define servo5 LATGbits.LATG14 // Middle right lower servo
#define servo6 LATGbits.LATG1 // Back right lower servo


// Middle servos
#define servo7 LATEbits.LATE4 // Back left middle servo
#define servo8 LATEbits.LATE6 // Middle left middle servo
#define servo9 LATDbits.LATD5 // Front left middle servo
#define servo10 LATBbits.LATB14 // Front right middle servo
#define servo11 LATAbits.LATA9 // Middle right middle servo
#define servo12 LATDbits.LATD12 // Back right middle servo

// Base servos
#define servo13 LATCbits.LATC4 // Back right base servo
#define servo14 LATAbits.LATA10 // Middle right base servo
#define servo15 LATDbits.LATD4 // Front right base servo
#define servo16 LATBbits.LATB15 // Front left base servo
#define servo17 LATEbits.LATE7 // Middle feft base servo
#define servo18 LATEbits.LATE5 // Back left base servo

/* ------------------------------------------------------------ */
/* Global Variables */
/* ------------------------------------------------------------ */

int count_f; // Forward movement sequence
counter variable
int count_s;
int count; // Gives us the 40us and 20ms
loops
int n; // Variable used in the
delay functions
char s1, s2, s3, s4; // Variables for the switches

// pozitions for the servos
- these numbers
// will give us the width of
the signal
// thus the position of the
servos - this value
// will have to be between 0
- 100 (ms)


RPC1 Hexabot Design Report


www.digilentinc.com page 14 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
unsigned char poz[18]; // Vector for servo positions

/* ------------------------------------------------------------ */
/* Local Variables */
/* ------------------------------------------------------------ */


/* ------------------------------------------------------------ */
/* Set Up of System Clock */
/* ------------------------------------------------------------ */

// Configuration Bit settings
// SYSCLK = 80 MHz (8MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV)
// PBCLK = 40 MHz
// Primary Osc w/PLL (XT+,HS+,EC+PLL)
// WDT OFF
// Other options are don't care
//
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1

// Let compile time pre-processor calculate the PR1 (period)

#define SYS_FREQ (80000000L)
#define PB_DIV 1
#define PRESCALE 256
#define TOGGLES_PER_SEC 1
#define T1_TICK (SYS_FREQ/PB_DIV/PRESCALE/TOGGLES_PER_SEC)

/* ------------------------------------------------------------ */
/* Forward Declarations */
/* ------------------------------------------------------------ */

void Pulse (void);
void Delay1_5ms (void);
void Delay50us (void);
void Delay200ms (void);
void LCD_data (char data); // Function to transmit data to the LCD
void LCD_init (void);
void Print_Text (char s[15]); // Function for displaying messages
void Position (char col); // Function which gives us the position of
each character to be displayed
void Timer_init (void);
void Default (void);
void Default2 (void);


/* ------------------------------------------------------------ */
/* Interrupt Service Routines */
/* ------------------------------------------------------------ */

void __ISR(_TIMER_1_VECTOR, ipl2) Timer1Handler(void)
{
// clear the interrupt flag
mT1ClearIntFlag();

RPC1 Hexabot Design Report


www.digilentinc.com page 15 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.

count++; // Increment the counter
if(count == 2000) // This will give us a period of 20ms (2000 * 10us)
{
char i;
count = 0;

servo1 = 1; // Start ("1")
servo2 = 1;
servo3 = 1;
servo4 = 1;
servo5 = 1;
servo6 = 1;
servo7 = 1;
servo8 = 1;
servo9 = 1;
servo10 = 1;
servo11 = 1;
servo12 = 1;
servo13 = 1;
servo14 = 1;
servo15 = 1;
servo16 = 1;
servo17 = 1;
servo18 = 1;

}

if(count == poz[9] + 100)
{
servo9 = 0; // Stop ("0")
}

if(count == poz[10] + 100)
{
servo10 = 0;
}

if(count == poz[11] + 100)
{
servo11 = 0;
}

if(count == poz[12] + 100)
{
servo12 = 0;
}

if(count == poz[17] + 100)
{
servo17 = 0;
}

if(count == poz[18] + 100)
{

RPC1 Hexabot Design Report


www.digilentinc.com page 16 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
servo18 = 0;
}

if(count == poz[7] + 100)
{
servo7 = 0;
}

if(count == poz[8] + 100)
{
servo8 = 0;
}

if(count == poz[9] + 100)
{
servo9 = 0;
}

if(count == poz[10] + 100)
{
servo10 = 0;
}

if(count == poz[11] + 100)
{
servo11 = 0;
}

if(count == poz[12] + 100)
{
servo12 = 0;
}

if(count == poz[13] + 100)
{
servo13 = 0;
}

if(count == poz[14] + 100)
{
servo14 = 0;
}

if(count == poz[15] + 100)
{
servo15 = 0;
}

if(count == poz[16] + 100)
{
servo16 = 0;
}

if(count == poz[17] + 100)
{

RPC1 Hexabot Design Report


www.digilentinc.com page 17 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
servo17 = 0;
}

if(count == poz[18] + 100)
{
servo18 = 0;
}

count_s++;
if(count_s == 100000)
{
count_s = 0;
Default2();
}

} // End Interrupt Handler

/* ------------------------------------------------------------ */
/* Procedure Definitions */
/* ------------------------------------------------------------ */
/*** main
** Description:
** Main program module. Performs basic board initialization
** and then enters the main program loop.
*/
int main(void)
{

char i;

// TRIS REG for configuration
// PORT REG for input
// LAT REG for output

// Set output bits

TRISAbits.TRISA2 = 0; // --------------------------------
TRISAbits.TRISA3 = 0; // JF Port
TRISAbits.TRISA6 = 0; // ----------

TRISDbits.TRISD14 = 0; // ----------
TRISDbits.TRISD15 = 0;
TRISFbits.TRISF2 = 0; // Output bits for the LCD Data Bus
TRISFbits.TRISF8 = 0;
TRISDbits.TRISD13 = 0; // JE Port
TRISDbits.TRISD3 = 0;
TRISDbits.TRISD11 = 0;
TRISCbits.TRISC3 = 0; // --------------------------------

TRISFbits.TRISF12 = 1; // --------------------------------
TRISFbits.TRISF13 = 1; // Input bits for the Switches
TRISFbits.TRISF4 = 1; // JH Port
TRISFbits.TRISF5 = 1; // --------------------------------

TRISGbits.TRISG12 = 0; // --------------------------------

RPC1 Hexabot Design Report


www.digilentinc.com page 18 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
TRISGbits.TRISG13 = 0;
TRISGbits.TRISG14 = 0;
TRISGbits.TRISG15 = 0; // Output bits for the onboard servo
TRISGbits.TRISG1 = 0; // signal pins
TRISFbits.TRISF0 = 0; // --------------------------------

TRISEbits.TRISE4 = 0; // --------------------------------
TRISEbits.TRISE5 = 0; // Output bits for the servo signal pins
TRISEbits.TRISE6 = 0; // JA Port
TRISEbits.TRISE7 = 0; // ----------

TRISBbits.TRISB15 = 0; // ----------
TRISDbits.TRISD5 = 0; // Output bits for the servo signal pins
TRISDbits.TRISD4 = 0; // JB Port
TRISBbits.TRISB14 = 0; // ----------

TRISAbits.TRISA9 = 0; // ----------
TRISAbits.TRISA10 = 0; // Output bits for the servo signal pins
TRISDbits.TRISD12 = 0; // JK Port
TRISCbits.TRISC4 = 0; // --------------------------------


// for (i = 0; i < 18; i++)
// {
// poz[i] = 50; // Initial value for the position
variables
// }

E=0;
count_f = 1;
count_s = 0;
count = 0;

Timer_init();
LCD_init();

Print_Text("Loading ");
Delay200ms();
Print_Text("Loading. ");
Delay200ms();
Print_Text("Loading.. ");
Delay200ms();
Print_Text("Loading... ");
Delay200ms();

while(1)
{
s1 = PORTFbits.RF12; // s va lua valoarea initiala a bitului
s2 = PORTFbits.RF13;
s3 = PORTFbits.RF4; //pt intrare se foloseste reg PORT
s4 = PORTFbits.RF5;

if ((s1 == 1)|(s2 == 1)|(s3 == 1)|(s4 == 1))
{
if ((s1 == 1)&(s2 == 0)&(s3 == 0)&(s4 == 0))

RPC1 Hexabot Design Report


www.digilentinc.com page 19 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
{
Print_Text("SEQUENCE 1 ");
//Default();
}

if ((s1 == 0)&(s2 == 1)&(s3 == 0)&(s4 == 0))
{
Print_Text("SEQUENCE 2 ");
}

if ((s1 == 0)&(s2 == 0)&(s3 == 1)&(s4 == 0))
{
Print_Text("SEQUENCE 3 ");
}

if ((s1 == 0)&(s2 == 0)&(s3 == 0)&(s4 == 1))
{
Print_Text("SEQUENCE 4 ");
}
else if (((s1 == 1)&(s2 == 1))|((s1 == 1)&(s3 == 1))
|((s1 == 1)&(s4 == 1))|((s2 == 1)&(s3 == 1))
|((s2 == 1)&(s4 == 1))|((s3 == 1)&(s4 == 1))
|((s1 == 1)&(s2 == 1)&(s3 == 1))
|((s1 == 1)&(s2 == 1)&(s3 == 1)&(s4 == 1)))
{
Print_Text("Error ");
}
}
else
{
Print_Text("Select SEQUENCE ");
}
}
} // end main
/* ------------------------------------------------------------ */

void Pulse (void)
{
E = 1;
for (n = 0; n < 400; n++) { ; }
E = 0;
}

void Delay50us (void)
{
for (n = 0; n < 4000; n++) { ; }
}

void Delay1_5ms (void)
{
for (n = 0; n < 12000; n++) { ; }
}

void Delay200ms (void)
{

RPC1 Hexabot Design Report


www.digilentinc.com page 20 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
for (n = 0; n < 1600000; n++) { ; }
}

void LCD_init(void)
{
RS = 0;
R_W = 0;
D7 = 0;
D6 = 0;
D5 = 1;
D4 = 1; // 8 bit
D3 = 1; // Two lines
D2 = 1; // 5x8 dots
D1=0;
D0=0;

Pulse();
Delay50us();

RS = 0; // Display Control
R_W = 0;
D7 = 0;
D6 = 0;
D5 = 0;
D4 = 0;
D3 = 1;
D2 = 1;
D1 = 0;
D0 = 0;

Pulse();
Delay50us();
// Display Clear
RS = 0;
R_W = 0;
D7 = 0;
D6 = 0;
D5 = 0;
D4 = 0;
D3 = 0;
D2 = 0;
D1 = 0;
D0 = 1;

Pulse();
Delay1_5ms();
// Entry Mode
RS = 0;
R_W = 0;
D7 = 0;
D6 = 0;
D5 = 0;
D4 = 0;
D3 = 0;
D2 = 1;

RPC1 Hexabot Design Report


www.digilentinc.com page 21 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
D1 = 1;
D0 = 0;

Pulse();
Delay50us();

RS = 0; // Set DDRAM Address
R_W = 0;
D7 = 1;
D6 = 1;
D5 = 0;
D4 = 0;
D3 = 0;
D2 = 0;
D1 = 0;
D0 = 0;
}

void LCD_data (char data)
{
Pulse();
Delay50us();

RS = 1; // Write character
R_W = 0;

if((data & 0x01) == 0) D0 = 0;
else D0 = 1;

if(((data & 0x02) >> 1) == 0) D1 = 0;
else D1 = 1;

if(((data & 0x04) >> 2) == 0) D2 = 0;
else D2 = 1;

if(((data & 0x08) >> 3) == 0) D3 = 0;
else D3 = 1;

if(((data & 0x10) >> 4) == 0) D4 = 0;
else D4 = 1;

if(((data & 0x20) >> 5) == 0) D5 = 0;
else D5 = 1;

if(((data & 0x40) >> 6) == 0) D6 = 0;
else D6 = 1;

if(((data & 0x80) >> 7) == 0) D7 = 0;
else D7 = 1;
}

void Print_Text(char s[15]) // s - character variable
{
int i;
for (i = 0; i <= 15; i++)

RPC1 Hexabot Design Report


www.digilentinc.com page 22 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
{
if (s[i] == 0) i = 15;
else
{
Position(i);
LCD_data(s[i]);
}
}
}

void Position (char col)
{
Pulse();
Delay50us();

RS = 0;
R_W = 0;

if((col & 0x01) == 0) D0 = 0;
else D0 = 1;

if(((col & 0x02) >> 1) == 0) D1 = 0;
else D1 = 1;

if(((col & 0x04) >> 2) == 0) D2 = 0;
else D2 = 1;

if(((col & 0x08) >> 3) == 0) D3 = 0;
else D3 = 1;

if(((col & 0x10) >> 4) == 0) D4 = 0;
else D4 = 1;

if(((col & 0x20) >> 5) == 0) D5 = 0;
else D5 = 1;

if(((col & 0x40) >> 6) == 0) D6 = 0;
else D6 = 1;

D7 = 1;
}

void Timer_init (void)
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//STEP 1. Configure cache, wait states and peripheral bus clock
// Configure the device for maximum performance but do not change the PBDIV
// Given the options, this function will change the flash wait states, RAM
// wait state and enable prefetch cache but will not change the PBDIV.
// The PBDIV value is already set via the pragma FPBDIV option above..
SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// STEP 2. configure Timer 1 using internal clock, 1:1 prescale


RPC1 Hexabot Design Report


www.digilentinc.com page 23 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
// OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_256, T1_TICK);
OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_1, 800); // The
timer will trigger after every 10us

// set up the timer interrupt with a priority of 2
ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2);

// enable multi-vector interrupts
INTEnableSystemMultiVectoredInt();

// configure PORTD.RD0 = output
mPORTDSetPinsDigitalOut(BIT_0);
}

void Default (void)
{
char i;
switch(count_f)
{
case 1:
for (i = 1; i <= 18; i++)
{
poz[i] = 50;
}

break;

case 2:
poz[9] = 55;

break;

case 4:
poz[10] = 55;

break;

case 6:
poz[11] = 55;

break;

case 8:
poz[12] = 55;

break;

case 10:
poz[17] = 55;

break;

case 12:
poz[18] = 55;


RPC1 Hexabot Design Report


www.digilentinc.com page 24 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
break;

case 14:
poz[9] = 60;

break;

case 16:
poz[10] = 60;

break;

case 18:
poz[11] = 60;

break;

case 20:
poz[12] = 60;

break;

case 22:
poz[17] = 60;

break;

case 24:
poz[18] = 60;

break;

case 26:
poz[9] = 65;

break;

case 28:
poz[10] = 65;

break;

case 30:
poz[11] = 65;

break;

case 32:
poz[12] = 65;

break;

case 34:
poz[17] = 65;


RPC1 Hexabot Design Report


www.digilentinc.com page 25 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
break;

case 36:
poz[18] = 65;

break;

case 38:
poz[9] = 70;

break;

case 40:
poz[10] = 70;

break;

case 42:
poz[11] = 70;

break;

case 44:
poz[12] = 70;

break;

case 46:
poz[17] = 70;

break;

case 48:
poz[18] = 70;

break;

case 50:
poz[9] = 75;

break;

case 52:
poz[10] = 75;

break;

case 54:
poz[11] = 75;

break;

case 56:
poz[12] = 75;


RPC1 Hexabot Design Report


www.digilentinc.com page 26 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
break;

case 58:
poz[17] = 75;

break;

case 60:
poz[18] = 75;

break;

case 62:
for (i = 1; i <= 18; i++)
{
poz[i] = 50;
}
break;

} // End switch

if(count_f >= 64)
{
count_f = 1;
}
count_f++; // Increment by one the counter of the sequence

} // End Default



void Default2 (void)
{
char i;
switch(count_f)
{
case 1:
for (i = 1; i <= 18; i++)
{
poz[i] = 50;
}

break;

case 2:
{
poz[10] = 40;
poz[13] = 45;
}
break;

case 4:
{
poz[11] = 55;
poz[18] = 65;

RPC1 Hexabot Design Report


www.digilentinc.com page 27 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.
}
break;
/*
case 6:
poz[11] = 55;

break;

case 8:
poz[12] = 55;

break;

case 10:
poz[17] = 55;

break;

case 12:
poz[18] = 55;

break;

case 14:
poz[9] = 60;

break;

case 16:
poz[10] = 60;

break;

case 18:
poz[11] = 60;

break;

case 20:
poz[12] = 60;

break;

case 22:
poz[17] = 60;

break;

case 24:
poz[18] = 60;

break;

case 26:
poz[9] = 65;

RPC1 Hexabot Design Report


www.digilentinc.com page 28 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.

break;

case 28:
poz[10] = 65;

break;

case 30:
poz[11] = 65;

break;

case 32:
poz[12] = 65;

break;

case 34:
poz[17] = 65;

break;

case 36:
poz[18] = 65;

break;

case 38:
poz[9] = 70;

break;

case 40:
poz[10] = 70;

break;

case 42:
poz[11] = 70;

break;

case 44:
poz[12] = 70;

break;

case 46:
poz[17] = 70;

break;

case 48:
poz[18] = 70;

RPC1 Hexabot Design Report


www.digilentinc.com page 29 of 29

Copyright Digilent, Inc. All rights reserved. Other product and company names mentioned may be trademarks of their respective owners.

break;

case 50:
poz[9] = 75;

break;

case 52:
poz[10] = 75;

break;

case 54:
poz[11] = 75;

break;

case 56:
poz[12] = 75;

break;

case 58:
poz[17] = 75;

break;

case 60:
poz[18] = 75;

break;
*/
case 6:
for (i = 1; i <= 18; i++)
{
poz[i] = 50;
}
break;

} // End switch

if(count_f >= 64)
{
count_f = 1;
}
count_f++; // Increment by one the counter of the sequence

} // End Default 2

You might also like