[C14] nạp code cho KIT

Rum

Thành Viên PIF
Bạn dễ thương quá. Nó sáng đc r nhưng mà lại thực hiện lệnh từ dưới lên. Bạn giải thích giùm mình đc k
 

Nhat Duy

Trứng gà
mình chạy thử code của mấy ac thì bị lỗi ko nhận dạng đc i ở dòng for (i=0;i<8;i++) @@ có ai biết cách sửa ko
Code:
int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;    // Stop watchdog timer
    P1SEL = 0;        //
        P1SEL2 = 0;        // Input/Output function is selected
        P2SEL = 0;        //
        P2SEL2 = 0;        //
 
        P1DIR = 0x00;    // P1.3 & P1.4 are used for input, so lazy so I set 0 for entire Port 1
        P2DIR = 0xFF;    // Port 2 is used for LEDs
 
        P1REN = 0x18;    // Turn on pull up resistor P1.3 & P1.4
 
        /******* LEDs show ******/
        for (i=0;i<8;i++)
        {
            P2OUT = ~(0x01<<i);
            __delay_cycles(50000);
        }
        for (i=0;i<8;i++)
        {
            P2OUT = ~(0x80>>i);
            __delay_cycles(50000);
        }
        for (i=0;i<8;i++)
        {
            P2OUT = ~(0x01<<i);
            __delay_cycles(50000);
        }
        for (i=0;i<8;i++)
        {
            P2OUT = ~(0x80>>i);
            __delay_cycles(50000);
        }
        /**** End of LEDs Show *****/
 
        P2OUT = ~(0x10);    // Turn on center leds
        i = 4;                // and ready for button
 
        while(1)    // loop forever
        {
            if ((P1IN & 0x10) == 0)        // Button P1.4 is being pressed
                i++;
            if ((P1IN & 0x08) == 0)        // Button P1.3 is being pressed
                i--;
 
            if (i == -1)    // Scroll
                i = 7;
            if (i == 8)
                i = 0;
 
            P2OUT = ~(0x01 << i);
 
            __delay_cycles(100000);        // Chong rung phim
            }
}
 

thảo quả

Thành Viên PIF
mình chạy thử code của mấy ac thì bị lỗi ko nhận dạng đc i ở dòng for (i=0;i<8;i++) @@ có ai biết cách sửa ko
Code:
int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;    // Stop watchdog timer
    P1SEL = 0;        //
        P1SEL2 = 0;        // Input/Output function is selected
        P2SEL = 0;        //
        P2SEL2 = 0;        //
 
        P1DIR = 0x00;    // P1.3 & P1.4 are used for input, so lazy so I set 0 for entire Port 1
        P2DIR = 0xFF;    // Port 2 is used for LEDs
 
        P1REN = 0x18;    // Turn on pull up resistor P1.3 & P1.4
 
        /******* LEDs show ******/
        for (i=0;i<8;i++)
        {
            P2OUT = ~(0x01<<i);
            __delay_cycles(50000);
        }
        for (i=0;i<8;i++)
        {
            P2OUT = ~(0x80>>i);
            __delay_cycles(50000);
        }
        for (i=0;i<8;i++)
        {
            P2OUT = ~(0x01<<i);
            __delay_cycles(50000);
        }
        for (i=0;i<8;i++)
        {
            P2OUT = ~(0x80>>i);
            __delay_cycles(50000);
        }
        /**** End of LEDs Show *****/
 
        P2OUT = ~(0x10);    // Turn on center leds
        i = 4;                // and ready for button
 
        while(1)    // loop forever
        {
            if ((P1IN & 0x10) == 0)        // Button P1.4 is being pressed
                i++;
            if ((P1IN & 0x08) == 0)        // Button P1.3 is being pressed
                i--;
 
            if (i == -1)    // Scroll
                i = 7;
            if (i == 8)
                i = 0;
 
            P2OUT = ~(0x01 << i);
 
            __delay_cycles(100000);        // Chong rung phim
            }
}
bạn chưa khai báo biến i kìa, thử thêm dòng int i; vào coi :5cool_still_dreaming:
 
Top