Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Montes Pacheco Juan Carlos Universidad Autónoma de Querétaro

HW#: 4 Facultad de Ingeniería

Date: 16 of February of 2011 Digital Systems 2

Create and simulate a code to turn on or off the six LEDs of the figure 1, one each time with
the sequence D1, D2, D3, D4, D5, D6.

Figure 1. Electric circuit of the sequence.

CODE

// Sequence of 5 LEDs turned on or off, one each time. Using pins b0, b1 and b2.

# INCLUDE<18F4550.H> //directives
# FUSES XT, NOWDT, NOPROTECT
# USE DELAY(CLOCK = 4 MHZ)

void main() { //main function


// infinite loop
while(true){

output_low(pin_b0); //led 1 turned on, 2,3,4,5,6 turned off


output_high(pin_b1);
output_float(pin_b2);
delay_ms(1000); // wait for 1 second

output_high(pin_b0); //led 2 turned on, 1,3,4,5,6 turned off


output_low(pin_b1);
delay_ms(1000); // wait for 1 second

output_float(pin_b0); //led 3 turned on, 1,2,4,5,6 turned off


output_low(pin_b1);
output_high(pin_b2);
delay_ms(1000); // wait for 1 second
output_high(pin_b1); //led 4 turned on, 1,2,3,5,6 turned off
output_low(pin_b2);
delay_ms(1000);

output_low(pin_b0); //led 5 turned on, 1,2,3,4,6 turned off


output_float(pin_b1);
output_high(pin_b2);
delay_ms(1000); // wait for 1 second

output_high(pin_b0); //led 6 turned on, 1,2,3,4,5 turned off


output_low(pin_b2);
delay_ms(1000); // wait for 1 second
}} //end of the program

SIMULATION
In next images, we can see each LED turned on and the others turned off starting from D1 to D6.
The pins used are b0, b1 and b2.

LED D1 on and off others.


LED D2 on and off others.

LED D3 on and off others.


LED D4 on and off others.

LED D5 on and off others.


LED D6 on and off others.

You might also like