em không biết tại sao led sáng từng led được 1 vòng r` sáng mãi led đầu mà nó ko lặp lại đc
#include <msp430.h>
#include "stdbool.h"
/*
* main.c
*/
int i = 0;
int s = 0;
int k = 0;
unsigned int a = 0x01;
unsigned int b = 0x03; // để tăng lượng led
void main(void)
{
// GPIO Init
WDTCTL = WDTPW + WDTHOLD; // Stop watch dog timer
P2SEL = 0;
P2SEL2=0;
P2DIR|=0XFF;
P2OUT |=0XFF;
//P1DIR |= BIT0 + BIT6; // Set P1.0 and P1.6 to output
// P1OUT &= ~(BIT0 + BIT6);
P1DIR &= ~BIT3; // Set P1.3 to input
P1REN |=BIT3;
P1OUT |=BIT3;
// Interrupt config
P1IE |= BIT3; // Enable P1.3 Interrupt
P1IES |= BIT3; // Falling Edge Interrupt
P1IFG &= ~BIT3; // Clear Interrupt Flags
_BIS_SR(GIE); // enable global interrupt
i = 0;
s = 0;
int m = 2;
int B = 0; // tăng lượng led
while(1)
{
if(i == 1)
{
if(s <= 8 )
{
a = 0x01 << s++;
P2OUT = ~a;
__delay_cycles(200000);
}
else if(s > 8)
{
a = 0x80 >> k++;
P2OUT = ~a;
__delay_cycles(200000);
}
if(k == 8)
{
s = 0;
}
if(s == 8)
{
k = 0;
}
}
}
}
/******************************************************************************
* INTERRUPT
*****************************************************************************/
#pragma vector = PORT1_VECTOR
__interrupt void P1_ISR (void)
{
switch (P1IFG & BIT3)
{
case BIT3:
{
i++;
}
}
__delay_cycles(200000);
P1IFG &= ~BIT3; // Clear Interrupt Flags
}
#include <msp430.h>
#include "stdbool.h"
/*
* main.c
*/
int i = 0;
int s = 0;
int k = 0;
unsigned int a = 0x01;
unsigned int b = 0x03; // để tăng lượng led
void main(void)
{
// GPIO Init
WDTCTL = WDTPW + WDTHOLD; // Stop watch dog timer
P2SEL = 0;
P2SEL2=0;
P2DIR|=0XFF;
P2OUT |=0XFF;
//P1DIR |= BIT0 + BIT6; // Set P1.0 and P1.6 to output
// P1OUT &= ~(BIT0 + BIT6);
P1DIR &= ~BIT3; // Set P1.3 to input
P1REN |=BIT3;
P1OUT |=BIT3;
// Interrupt config
P1IE |= BIT3; // Enable P1.3 Interrupt
P1IES |= BIT3; // Falling Edge Interrupt
P1IFG &= ~BIT3; // Clear Interrupt Flags
_BIS_SR(GIE); // enable global interrupt
i = 0;
s = 0;
int m = 2;
int B = 0; // tăng lượng led
while(1)
{
if(i == 1)
{
if(s <= 8 )
{
a = 0x01 << s++;
P2OUT = ~a;
__delay_cycles(200000);
}
else if(s > 8)
{
a = 0x80 >> k++;
P2OUT = ~a;
__delay_cycles(200000);
}
if(k == 8)
{
s = 0;
}
if(s == 8)
{
k = 0;
}
}
}
}
/******************************************************************************
* INTERRUPT
*****************************************************************************/
#pragma vector = PORT1_VECTOR
__interrupt void P1_ISR (void)
{
switch (P1IFG & BIT3)
{
case BIT3:
{
i++;
}
}
__delay_cycles(200000);
P1IFG &= ~BIT3; // Clear Interrupt Flags
}