Consider the design of a set of GPIO inputs and outputs conn

Consider the design of a set of GPIO inputs and outputs connected to PORTQS. All other bits are unused.

a. What value can be written to DDRQS to set up port QS correctly. ( Unused bits can be set to 0 or X )

b. What will be the logic state of PORTQS[3] when the switch is pressed. ( logic 1 or logic 0 )

c. Which logic state of PORTQS[5] will turn on the LED. ( logic 1 or logic 0 )

d. Write a few lines of code to do the following. if switch1 is released, toggle LED1

+3.3V SW1 +3.3V PortQS[3] LEDI 5]

Solution

GPIO is a generic pin or an integrated circuit- including whether it is input or output pin and is controlled by the user at the run time.

a) The PORTQS data direction register determines whether the pins are inputs or outputs.Clearing the bit makes the corresponding bit an input. Setting the bit makes the corresponding pin as output. Basically the data register latches the I/O data.

b) As the Pin 3 is used as the input , so the logic state for PORTQS[3] will be 1 when the switch is pressed.

c) GPIO[5] is a output pin here , the positive end of the battery is provided by the GPIO pin itself, suppose it is pin 18, so the LED will glow when the pin 5 is 0.

d) import RPi.GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(5, GPIO.OUT)
GPIO.setup(3, GPIO.IN)
# Initialise GPIO 5 to high (true) so that the LED is off.
GPIO.output(5, True)
while 1:
if GPIO.input(3):
GPIO.output( 5, False)
else:
# When the button switch is not pressed, turn off the LED.
GPIO.output( 5, True)

Consider the design of a set of GPIO inputs and outputs connected to PORTQS. All other bits are unused. a. What value can be written to DDRQS to set up port QS

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site