MSP430 - Class 11 - MSP430 Programming
MSP430 - Class 11 - MSP430 Programming
MSP430
Asha.S.Patil
Department of Electrical & Electronics Engineering
MICROCONTROLLER
Asha.S.Patil
Department of Electrical&Electronics Engineering
MICROCONTROLLER
Basic code example1
#include "msp430x22x4.h"
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]