Apéritif: RoboSlam

Blink program example

Save this as “main.c”:

//
// Blinking LED example for MSP430G2553
// Last updated 24-9-2014
//

#include <msp430.h>

// main function
int main()
{
    // stop watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;

    // make P1.0 a digital output (all other Port 1 pins are inputs)
    P1DIR = 0b00000001;

    // repeat the following 4 statements indefinitely
    while(1)
    {
        P1OUT = 0b00000001;      // turn LED on (set P1.0 high)
        __delay_cycles(1000000); // 1 second delay
        P1OUT = 0b00000000;      // turn LED off (set P1.0 low)
        __delay_cycles(1000000); // 1 second delay
    }

    return 0;
}

Save this as “build_for_g2553.bat” in same folder as “main.c”:

@setlocal
@PATH=Y:\Ted.Burke\RoboSlam\mspgcc-20120406-p20120911\bin\;Y:\Ted.Burke\RoboSlam\MSP430Flasher_1.2.1\

@REM Compile the C code
msp430-gcc -mmcu=msp430g2553 main.c
@if errorlevel 1 goto end

@REM Convert compiled program to hex format
msp430-objcopy -O ihex a.out a.hex
@if errorlevel 1 goto end

@REM Copy hex file onto microcontroller
msp430flasher -n MSP430G2553 -w a.hex

:end
@pause

ZigZag motor example

//
// ZigZag motors example for MSP430G2553
// Last updated 24-9-2014
//

#include <msp430.h>

// main function
int main()
{
    // stop watchdog timer to prevent timeout reset
    WDTCTL = WDTPW + WDTHOLD;

    // make P1.0 an output to control indicator LED
    P1DIR = 0b00000001;

    // make P2.0 and P2.1 outputs to control left motor
    // make P2.3 and P2.4 outputs to control right motor
    P2DIR = 0b00011011;

    // repeat the following statements indefinitely
    while(1)
    {
        P2OUT = 0b00010010;      // motors: both forward
        P1OUT = 0b00000001;      // turn LED on
        __delay_cycles(2000000); // 2 second delay

        P2OUT = 0b00001010;      // motors: left forward, right reverse
        P1OUT = 0b00000000;      // turn LED off
        __delay_cycles(1000000); // 1 second delay

        P2OUT = 0b00010010;      // motors: both forward
        P1OUT = 0b00000001;      // turn LED on
        __delay_cycles(2000000); // 2 second delay

        P2OUT = 0b00010001;      // motors: left reverse, right forward
        P1OUT = 0b00000000;      // turn LED off
        __delay_cycles(1000000); // 1 second delay
    }

    return 0;
}
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s