+ All Categories
Home > Documents > RPC1 Hexabot

RPC1 Hexabot

Date post: 03-Jun-2018
Category:
Upload: niels-saavedra
View: 214 times
Download: 0 times
Share this document with a friend

of 29

Transcript
  • 8/12/2019 RPC1 Hexabot

    1/29

    RRPPCC11HHeexxaabboottDDeessiignnRReepoorrtt

    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 [email protected]

    Submitted for the 2011 Digilent Design Contest

    Cluj-Napoca, Romania

    May 14th15th, 2011

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

    Petru Maior UniversityTrgu Mure

  • 8/12/2019 RPC1 Hexabot

    2/29

    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

  • 8/12/2019 RPC1 Hexabot

    3/29

    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 32MX4development board. The user will be able to choose different sequences for the mechanical system toexecute and an LCD will display different messages during the execution. These sequences includeforward and sideways motion as well as a remote controlled movement. This type of movement willallow the robot to navigate in a certain area, driving itself towards a certain object (a laser beam dot ora colored ball) based on the information provided by a web cam and a PC software which survey thatarea.

    Wireless radio transmission will be used for sending the robot coordinates. The reason behind thedevelopment of this project represents the challenge provided by both the programming and theimplementation of the mechanic design. Also it is a great example of how you can combine thefunctionality of PIC microcontrollers with the utility of servomotors and the control of the system fromthe 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 microcontroller2. 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

  • 8/12/2019 RPC1 Hexabot

    4/29

    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 theelements 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 therobot and also of each servo, as the servos can only lift a certain amount. For the RPC1 Hexabot Idecided upon ABS due to the fact that it is easy to work with and it is a light material which doesntadd any unnecessary weight to the project.

    For the wireless transmission, a PIC 18F4455 microcontroller is used and also another circuit to lowerthe 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 dueto 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

  • 8/12/2019 RPC1 Hexabot

    5/29

    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 ) 1Used to machine the parts ( For this

    project a saw was used)

    2 ABS plates 3220 mm thick150 mm thick

    3 Glue 1

    Needed if the parts are machined fromABS, as each leg is made of a

    transparent plate between other twothinner 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 electronics6 Nuts and bolts For holding in place all the elements

    7 Soldering IronFor soldering the components required for

    the PIC 18F4455 microcontroller andother 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 notstable enough for a proper movement sequence to be implemented and adding the battery packs asplanned 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 athesis.

  • 8/12/2019 RPC1 Hexabot

    6/29

    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 seea 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 addedtogether give us the period (10mS + 10mS = 20mS). This means that controlling the servos is fairlysimple:

    1. Implement a timer that generates an interrupt service routine (ISR) after every 20ms2. 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. Thisproject illustrates a software mode for an implementation.

  • 8/12/2019 RPC1 Hexabot

    7/29

    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 sourcefor the Cerebot MX4 four AA, 2300mA, 1.2V batteries are used which provide enough voltage andcurrent for the microcontroller.

    One of the most interesting feature of the project is the RF1 Pmod which is attached to theCerebot MX4, enabling the robot to be controlled wirelessly using another Pmod RF1 and a PIC18F4455 microcontroller connected to a PC. Also using a simple SWT Pmod, the user can chose asequence 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 tothe base plates be one servo. The Pmod SWT enables the selection of a certain sequence and thePmod CLP displays the corresponding message. In the front you can see the proximity sensors thatallow the detection of nearby objects so that the RPC1 Hexabot doesnthit anything in its way.

  • 8/12/2019 RPC1 Hexabot

    8/29

    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 asimilar 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

  • 8/12/2019 RPC1 Hexabot

    9/29

    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

    BatteryHolder

    (4 x AA)

    BatteryPack

  • 8/12/2019 RPC1 Hexabot

    10/29

    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, inthe 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 legstructure can be altered by changing the position of servo 1.

    Top view

    GWS servos: 1, 4, 7, 10, 13 and 16 will bethe base joints of the RPC1 Hexabot, theirrole being that of moving each leg structureback and forth. The GWS servos: 2, 5, 8, 11,14 and 17 will lift the 3, 6, 9, 12, 15 and 18GWS servos of each leg structure from theground and also the 3, 6, 9, 12, 15 and 18GWS servos will ensure a smoother up anddown movement of each leg. In a sequencethese servos will ensure the movement of theRPC1 Hexabot.

    Figure 6.Leg structure

  • 8/12/2019 RPC1 Hexabot

    11/29

  • 8/12/2019 RPC1 Hexabot

    12/29

    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: [email protected]/* 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/ parallelInterface-PmodSWT - Slide switches- Battery Holder (4 x AA )- PmodRF1 - Wireless Radio Transceiver

    *//************************************************************************/

    /* ------------------------------------------------------------ */

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

    #include #include

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

    #define RS LATAbits.LATA2 // Register select: high for datatransfer, low for instruction register#define R_W LATAbits.LATA3 // Read/write signal: high for readmode, 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

  • 8/12/2019 RPC1 Hexabot

    13/29

    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 sequencecounter variableint count_s;int count; // Gives us the 40us and 20msloopsint n; // Variable used in thedelay functionschar s1, s2, s3, s4; // Variables for the switches

    // pozitions for the servos- these numbers

    // will give us the width ofthe signal

    // thus the position of theservos - this value

    // will have to be between 0- 100 (ms)

  • 8/12/2019 RPC1 Hexabot

    14/29

    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 LCDvoid LCD_init (void);void Print_Text (char s[15]); // Function for displaying messagesvoid Position (char col); // Function which gives us the position ofeach character to be displayedvoid Timer_init (void);void Default (void);void Default2 (void);

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

    void __ISR(_TIMER_1_VECTOR, ipl2) Timer1Handler(void){

    // clear the interrupt flagmT1ClearIntFlag();

  • 8/12/2019 RPC1 Hexabot

    15/29

    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 counterif(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){

  • 8/12/2019 RPC1 Hexabot

    16/29

    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){

  • 8/12/2019 RPC1 Hexabot

    17/29

    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 PortTRISAbits.TRISA6 = 0; // ----------

    TRISDbits.TRISD14 = 0; // ----------TRISDbits.TRISD15 = 0;TRISFbits.TRISF2 = 0; // Output bits for the LCD Data BusTRISFbits.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 SwitchesTRISFbits.TRISF4 = 1; // JH PortTRISFbits.TRISF5 = 1; // --------------------------------

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

  • 8/12/2019 RPC1 Hexabot

    18/29

    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 servoTRISGbits.TRISG1 = 0; // signal pinsTRISFbits.TRISF0 = 0; // --------------------------------

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

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

    TRISAbits.TRISA9 = 0; // ----------TRISAbits.TRISA10 = 0; // Output bits for the servo signal pins

    TRISDbits.TRISD12 = 0; // JK PortTRISCbits.TRISC4 = 0; // --------------------------------

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

    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 bituluis2 = PORTFbits.RF13;s3 = PORTFbits.RF4; //pt intrare se foloseste reg PORTs4 = PORTFbits.RF5;

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

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

  • 8/12/2019 RPC1 Hexabot

    19/29

    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){

  • 8/12/2019 RPC1 Hexabot

    20/29

    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 bitD3 = 1; // Two linesD2 = 1; // 5x8 dotsD1=0;D0=0;

    Pulse();Delay50us();

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

    Pulse();

    Delay50us(); // Display ClearRS = 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;

  • 8/12/2019 RPC1 Hexabot

    21/29

    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 AddressR_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 characterR_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

  • 8/12/2019 RPC1 Hexabot

    22/29

    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

  • 8/12/2019 RPC1 Hexabot

    23/29

    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 2ConfigIntTimer1(T1_INT_ON | T1_INT_PRIOR_2);

    // enable multi-vector interruptsINTEnableSystemMultiVectoredInt();

    // configure PORTD.RD0 = outputmPORTDSetPinsDigitalOut(BIT_0);

    }

    void Default (void){

    char i;switch(count_f)

    {case 1:for (i = 1; i

  • 8/12/2019 RPC1 Hexabot

    24/29

    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;

  • 8/12/2019 RPC1 Hexabot

    25/29

    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;

  • 8/12/2019 RPC1 Hexabot

    26/29

    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 = 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

  • 8/12/2019 RPC1 Hexabot

    27/29

    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;

  • 8/12/2019 RPC1 Hexabot

    28/29

    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;

  • 8/12/2019 RPC1 Hexabot

    29/29

    RPC1 Hexabot Design Report

    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 = 64){

    count_f = 1;

    }count_f++; // Increment by one the counter of the sequence

    } // End Default 2


Recommended