msp430 embedded c programming part 1 --- Blinking a LED



/*
  Blinking a LED which is connected to port 5.5 of the MSP430F2618
*/

//step1 : include the microcontroller header file

#include <msp430f2618.h>

int main(void)
{

//step2 :  stop the watchdog timer,otherwise it will reboot the system if the timer fires
WDTCTL=WDTPW+WDTHOLD;
//WDTCTL is  a 2 byte register in which the least 8 bits are used for controlling the watchdog timer and 8 most significant bits are for setting the password for the watchdog timer as it is password protected.Setting the 7 lsb bit will stop the watchdog timer which is the value of WDTHOLD(0x0080) and the password for the Watchdog timer is 0x5a which WDTPW(0x5a00) has in it


//step3: setting up the pins
/*
There are basically 5 registers for each port
PxSEL -> Select the functionality
PxDIR -> Selecting the direction of pin whether it is input(0) or output(1)
PxIN  -> Input Register of the port
PxOUT -> Output Register of the port
PxREN -> Selects if a pull-up or pull-down resistor is used.

P1xxx registers are for the first 8(0-7)pins
*/

P5DIR = 0x20; //setting the pin 5.5 as output(0010 0000)

// P5OUT = 0x20; //setting the pin 5.5 as high IF the anode is connected to the gpio pin and send  a low signal if cathode is connected to the gpio pin

return 0;
}


For compiling the program use the msp430-gcc

msp430-gcc -mmcu=msp430f2618 -Wall -Os -o led.elf led.c

Arguments passed to msp430-gcc are
mmcu=microntroller used
-Wall stands for warnings
-Os to optimize

Then convert into the hex form understand by the microcontroller
msp430-objcopy --output-target=ihex led.elf led.ihex

mv led.ihex led.ihex.out

Now use the tos-bsl provided by the TI to burn the code

tos-bsl --telosb -c /dev/ttyUSB0 -r -e -I -p led.ihex.out

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto