0% found this document useful (0 votes)
26 views8 pages

Code 2

The document contains C code for controlling LED effects using a microcontroller. It defines several functions to create different lighting patterns by manipulating output pins and introducing delays. The main function initializes the pins and continuously executes one of the lighting effects in an infinite loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views8 pages

Code 2

The document contains C code for controlling LED effects using a microcontroller. It defines several functions to create different lighting patterns by manipulating output pins and introducing delays. The main function initializes the pins and continuously executes one of the lighting effects in an infinite loop.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

#include "io430.

h"

void clock();

void chot();

void hieu_ung5();

void clock()

P1OUT |= BIT0;

__delay_cycles(200);

P1OUT &= ~BIT0;

__delay_cycles(200);

void clock2(int sobit)

{ for (int i=1;i<=sobit;i++)

{ clock();}

void chot()

P1OUT |= BIT2;

__delay_cycles(200);

P1OUT &= ~BIT2;

__delay_cycles(200);
}

void chot2(int sobit)

{ for (int i=1;i<=sobit;i++)

{ chot();}

void hieu_ung1()//dich phai 1 sang 1 tat

int n=1;

for (int i=1;i<=16;i++){

P1OUT |= BIT1;

clock2(n);

__delay_cycles(25000);

chot();

P1OUT &=~ BIT1;

clock2(n);

__delay_cycles(25000);

chot();

void hieu_ung2() // dich phai

{ P1OUT |= BIT1;
for ( int i=0; i<=32; i++)

clock();

__delay_cycles(25000);

chot();

P1OUT &= ~BIT1;

for ( int i=0; i<=32; i++)

clock();

__delay_cycles(25000);

chot();}

void hieu_ung3() //dich trai

int n=0;

for(int i=0;i<=32;i++)

P1OUT |= BIT1;
clock2(n);

P1OUT &=~ BIT1;

clock2(32-n);

chot();

n++;}

P1OUT &=~ BIT1;

clock2(32);

chot();

void hieu_ung4() //chot tat 32 led

for (int i=1;i<=5;i++){

P1OUT |= BIT1 ;

for ( int i=0;i<=32;i++)

{clock();}

chot();

__delay_cycles(25000);

P1OUT &=~ BIT1 ;

for ( int i=0;i<=32;i++)

{clock();}

chot();

__delay_cycles(25000);
}

void hieu_ung5() /// 4 led sang 4 led tat

for(int i=0; i<5;i++)

P1OUT |= BIT1;

for ( int i=0; i< 4;i++)

clock();

chot();

__delay_cycles(20000);

P1OUT &=~ BIT1;

for ( int i=0; i< 8;i++)


{

clock2(8);

chot();

__delay_cycles(20000);

void hieu_ung6()

int n=32;

for(int i=0;i<=32;i++)

P1OUT |= BIT1;

clock2(1);

__delay_cycles(25000);

P1OUT &=~ BIT1;

clock2(n-1);

__delay_cycles(25000);

chot();

n--;

}
__delay_cycles(25000);

P1OUT |= BIT1;

for ( int i=0; i<=32; i++)

clock();

__delay_cycles(25000);

chot();

__delay_cycles(25000);

void main( void )

// Stop watchdog timer to prevent time out reset

WDTCTL = WDTPW + WDTHOLD;


//khai bao P1.0, P1.1 va P1.2 la ngo ra

P1DIR |= (BIT0+BIT1+BIT2);

while(1)

//hieu_ung1();

//hieu_ung2();

//hieu_ung3();

// hieu_ung4();

//hieu_ung5( );

hieu_ung6();

You might also like