0% found this document useful (0 votes)
36 views

MSP430 - Class 11 - MSP430 Programming

The document provides examples of basic code for programming a MSP430 microcontroller, including toggling an LED using C and assembly language. It includes code snippets to initialize ports for output, toggle an LED using exclusive OR, and use delays to blink the LED. The document is authored by Asha S. Patil from the Department of Electrical and Electronics Engineering.

Uploaded by

atul
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

MSP430 - Class 11 - MSP430 Programming

The document provides examples of basic code for programming a MSP430 microcontroller, including toggling an LED using C and assembly language. It includes code snippets to initialize ports for output, toggle an LED using exclusive OR, and use delays to blink the LED. The document is authored by Asha S. Patil from the Department of Electrical and Electronics Engineering.

Uploaded by

atul
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Microcontroller

MSP430

Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER

Beginning Programming for MSP430

Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Basic code example1

#include "msp430x22x4.h"

volatile unsigned int i; // volatile to prevent optimization

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction

for (;;)
{
P1OUT ˆ= 0x01; // Toggle P1.0 using exclusive-OR
i = 50000; // Delay
do (i--);
while (i != 0);
}
}
MICROCONTROLLER
Basic code example2

1.LED BLINKING:
Note:for delay :_delay_cycles(2500);
#include <msp430g2553.h>
 
int main(void)
{
 
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
 
P1DIR =0X01; //toggle the bit
P1OUT=0X01;
unsigned int i;
while(1)
{
P1OUT ^=0X01; //toggle the bits
for(i=0;i<20000;i++)
{
}
}

return(0);
}
MICROCONTROLLER
Basic code example2
1.LED BLINKING:.To turn on LED using assembly language programming
;;-------------------------------------------------------------------------------
.cdecls C,LIST,"msp430.h" ; Include device header file

;-------------------------------------------------------------------------------
.def RESET ; Export program entry-point to
; make it known to linker.
;-------------------------------------------------------------------------------
.text ; Assemble into program memory.
.retain ; Override ELF conditional linking
; and retain current section.
.retainrefs ; And retain any sections that have
; references to current section.
 
;-------------------------------------------------------------------------------
RESET mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
  ;-------------------------------------------------------------------------------
; Main loop here
;------------------------------------------------------------------------------
 
 -------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack

;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
 
THANK YOU
Asha.S.Patil
Department of Electrical & Electronics Engineering
[email protected]

You might also like