donderdag 10 februari 2011

Mini-Tutorial 1; Blink-a-LED

Today I finally managed it to get my CCS version (code composer studio) working, it was stuck somewhere with the updating system, after reinstalling it, it finally worked =)

I haven’t done a lot, but I know how the basic works (at least I hope) and I fully commented the demo blink-a-led application so I know exactly what every instruction does.

The you can download the demo code from the site of TI (look for slac463a.zip) and the 'lab 1: Blink launchpad's leds' pdf written by Adrian Fernandez can be found here.

//******************************************************************************
// MSP430G2xx1 Demo - Software Toggle P1.0
//
// Description; Toggle P1.0 by xor'ing P1.0 inside of a software loop.
// ACLK = n/a, MCLK = SMCLK = default DCO
//
// ***code cut***
//
// D. Dang
// Texas Instruments, Inc
// October 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//
//Remade and comments added by watchout3
// mailto:
// watchout.3
// ***anti spam line*** tralalalaa
// @hot
// ***anti spam line*** badaboem
// mail.com
//
//******************************************************************************


#include <msp430g2231.h>

void main(void)
{

//****************************************************************
// PROGRAM INITIALISATION
//****************************************************************


WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
// See user manual (slau144f) p. 360


P1DIR |= 0x01; // Set P1.0 to output direction
P1DIR |= 0x40; // Set P1.4 to output direction

// If you wish to set a single bit to '0' without changing the state
// of the other bit-registers, you have to perform a "OR"-operation.
//
// You can do this on 2 ways, the short or the long one
//
// P1DIR |= 0x01; (short) (0x01 = bin "0000 0001")
// P1DIR = P1DIR | 0x01 (long )
//
// which results in xxxx xxx1 (where x means no state change)

// If you wish to reset a single bit to '1' without changing the state
// of the other bit-registers, you have to perform a "AND"-operation.
//
// P1DIR &= 0xFE (short) (0xFE = bin "1111 1110")
// P1DIR = P1DIR & 0xFE (long )
//
// which results in xxxx xxx0 (where 0 means no state change)



P1OUT = 0x40; // The two leds will toggle each on their turn
// ***Chose only one of both!!!***
//P1OUT = 0x00; // The two leds will toggle together

// You must preset the output registers.
// When you are debugging with your IDE open and don't repower the target aka
// launchpad (disconnect and reconnect it) the output registers won't be resetted.
//
// This will cause an unpredictable 'boot-up' state of the outputs (in my case they
// didn't toggled together)
//
// Probaly this comes beacause the ram is volatile memory witch only loses it's state
// when the power is shutted off (a reset didn't helped in my case)
//
// Also I noticed a sort of 'bug' when you go in debug mode and upload the code to your
// device, the reset ain't working until you remove the VCC jumper (once placed back
// the reset won't work anymore), remove the RST/TEST-jumpers or again, fully disconnect
// the device so the PC connection is interrupted
// Which method the correct one is, I don't know...

//****************************************************************
// MAIN PROGRAM
//****************************************************************


for (;;) // Start the infinitive loop
{
volatile unsigned int i;
// Reserving RAM memory

i = 50000; // Delay

// I suggest to initialise the memory as fast a s possible and not 'somewhere' in the code,
// because the possible errors like I mentioned above.


P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR (0x01 = bin 0000 0001)
P1OUT ^= 0x40; // Toggle P1.4 using exclusive-OR (0x40 = bin 0000 1000)

// Logic Table of an 'EXOR' function
//
// Input||Output
// A B || Q
//------||----
// 0 0 || 0
// 0 1 || 1
// 1 0 || 1
// 1 1 || 0


do (i--); // Delay function, increase 'i' aslong it is not differs from 0
while (i != 0); //
}
}

Geen opmerkingen:

Een reactie posten