0% found this document useful (0 votes)
22 views

The Code

The code defines a loop that sequentially turns on and off LEDs connected to port B of a microcontroller. It sets the TRISB and PORTB registers to configure port B pins as outputs with initial value 0. The loop then toggles the 8 LEDs on port B individually and in combinations, keeping each state for 5 seconds before changing, before repeating the full sequence.
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)
22 views

The Code

The code defines a loop that sequentially turns on and off LEDs connected to port B of a microcontroller. It sets the TRISB and PORTB registers to configure port B pins as outputs with initial value 0. The loop then toggles the 8 LEDs on port B individually and in combinations, keeping each state for 5 seconds before changing, before repeating the full sequence.
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/ 1

The code :

void main()
{
TRISB=0; PORTB=0;
Loop:
PORTB=0B00000001; delay_ms(5000);
// L0 ON
PORTB=0B00000011; delay_ms(5000);
// L0,L1 ON
PORTB=0B00000111; delay_ms(5000);
// L0,L1,L2 ON
PORTB=0B00001111; delay_ms(500);
// L0,L1,L2,L3 ON
PORTB=0B00011111; delay_ms(5000);
// L0,L1,L2,L3,L4 ON
PORTB=0B00111111; delay_ms(5000);
// L0,L1,L2,L3,L4,L5 ON
PORTB=0B01111111; delay_ms(5000);
// L0,L1,L2,L3,L4,L5,L6, ON
PORTB=0B11111111; delay_ms(5000);
// L0,L1,L2,L3,L4,L5,L6,L7 ON
PORTB=0B00000000; delay_ms(5000);
// ALL LEDs OFF
PORTB=0B00011000; delay_ms(5000); // L3,L4 ON
PORTB=0B00111100; delay_ms(5000); // L2-L5 ON
PORTB=0B01111110; delay_ms(5000); // L1-L5 ON
PORTB=0B11111111; delay_ms(5000); // ALL LEDs ON

PORTB=0B00000000; delay_ms(5000); // ALL LEDs OFF


PORTB=0B11111111; delay_ms(5000); // ALL LEDs ON
PORTB=0B00000000; delay_ms(5000); // ALL LEDs OFF
PORTB=0B11111111; delay_ms(5000); // ALL LEDs ON
PORTB=0B00000000; delay_ms(5000); // ALL LEDs OFF
goto loop;
}

You might also like