Thanks for your reply. I tried to do it as you explained but failed. Can you help me? Here’s my first code…
#include <msp430x16x.h>
void checkMes (char );
void delay(); // delay
void blinker(); // blink led
char message; // check received data
unsigned int delm=1; // # of delays
int t=0; // led’s not blinking when it is 0
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0xC0; // P3.6,7 = USART1 option select
ME2 |= UTXE1 + URXE1; // Enable USART1 TXD/RXD
UCTL1 |= CHAR; // 8-bit character
UTCTL1 |= SSEL0; // UCLK = ACLK
UBR01 = 0x0D; // 32k/2400 - 13.65
UBR11 = 0x00;
UMCTL1 = 0x6B; // Modulation
UCTL1 &= ~SWRST; // Initialize USART state machine
IE2 |= URXIE1; // Enable USART1 RX interrupt
P1DIR |=BIT0;
P1OUT =~BIT0;
// Mainloop
for (;
{
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt
#if 1
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = RXBUF1;
#endif
}
}
#if 1
// UART1 RX ISR will for exit from LPM3 in Mainloop
#pragma vector= USART1RX_VECTOR
__interrupt void usart1_rx (void)
{
_BIC_SR_IRQ( LPM3_bits) ;// Clear LPM3 bits from 0(SR)
t=0;
message=RXBUF1;
checkMes (message); //checks received message
}
#endif
void delay()
{
unsigned int i;
i=10000;
while(i>0)
i–;
}
void blinker () // blinks led
{
while (t==1){
int i=delm;
P1OUT ^=BIT0;
while (i>0) // waits for delay * # of delays
{
i–;
delay();
}
}
}
void checkMes (char m)
{
char c2;
int com;
if ((m & 0x80) == 0x80) //Check if it is command
{
if ((m & 0x10) == 0x10){ //check if it is blink button
t=1;
blinker();}
else
{
c2=(m & 0x07);
delm=c2; // # of delays
}
}
}
Besides this, I got a c# interface. When I press a button, led on board will start blinking. And with the help of a trackbar, I will change delays (blinking speed). The problem is When I press blink button, program is stuck. I can change blinking speed, before I press button. How can I fix it?