To develop and demonstrate individual proficiency in:
Using SPI communication to control LEDs connected to a shift register
Displaying binary numbers on LEDs connected to a shift register, updated periodically by a timer-driven interrupt.
PIC18F47Q10 Curiosity Nano Microchip Main Page
All About Serial page on the Embedded Systems Design Resources blog
Scherz, P., & Monk, S. (2016). Practical electronics for inventors, fourth edition. New York: McGraw Hill. ISBN: 978-1259587542
Serial Peripheral Interface (pages 890 - 891)
Shift Registers (Chapter 12.8)
Canvas Discussion Board
Item | Quantity |
---|---|
Breadboard | 1 |
PIC18F47Q10 Curiosity Nano -or- | 1 |
PIC18F47Q10 DIP IC | |
8-bit serial-in, parallel-out shift register | 1 |
LEDs | 8 |
Current-limiting resistors for LEDs | 8 |
Jumper wires | Many |
Critical Information and Concepts | Importance and Source |
---|---|
a. What a shift register is, why you would want to use one, and how it works | Needed to conceptually understand this assignment and figure out which connections to make. Can be found in Scherz & Monk Section 12.8, and also in The Shift Register: Explained video. |
b. How to wire a SN74HC595N serial in, parallel out shift register | Needed to create serially-addressable LEDs. See the SN74HC595N datasheet for wiring information |
c. How the SN74HC595N works | See Section 9.1 and Table 1 of the SN74HC595N datasheet for information on how the shift register clock and storage register clock work. |
d. How the SPI peripheral works in the PIC18F47Q10 | Needed to understand how to wire and write SPI code for the PIC. Can be found in Section 27.2 of the PIC18F47Q10 Datasheet |
e. Which pins on the PIC18F47Q10 can be used for SPI | Needed to understand how to wire a SPI device to the PIC. The default locations for SPI communication can be found in Table 4 of the PIC18F47Q10 Datasheet |
In this assignment, you may use either the PIC18F47Q10 Curiosity Nano or a PIC18F47Q10 DIP IC connected to your breadboard.
Place the Curiosity Nano board as far to one edge of the breadboard as possible such that the micro USB port is accessible from the edge of the board. Connect 3.3V and GND from the Nano to the power rails of the breadboard.
Place the SN74HC595N shift register near the Curiosity on the breadboard and wire it to 3.3V power and ground.
Place 8 LEDs on the breadboard near the shift register.
Connect the 8 output pins of the shift register to appropriately-sized current-limiting resistors connected to each of the 8 LEDs.
Connect the serial clear pin of the shift register to 3.3V. This prevents the shift register from resetting due to electrical noise.
Connect the output enable pin of the shift register to ground. This enables the register outputs so they can be seen on the LEDs.
Connect the SPI 1 output pin on the Curiosity to the serial input pin on the shift register. (Hint: See Table 4 in the PIC18F47Q10 datasheet).
Connect the SPI 1 serial clock pin on the Curiosity to the shift register clock pin on the shift register. (Hint: See Table 4 in the PIC18F47Q10 datasheet and Table 1 of the ).
Connect the storage register clock pin on the shift register to a GPIO digital output pin on the same port as the other SPI 1 pins above.
Launch MPLAB® X and create a new project for your PIC IC. Note: Please remember that this is an individual assignment. The only way to learn to code independently is to work through coding problems and figure them out.
Configure your system clock to use the HFINTOSC at 4 MHz with a clock divider of 4.
In the Pin Manager, make sure that the Package matches the package of the PIC you are using.
Add a SPI interface on serial port module 1. In the Registers tab, change SSPEN (serial port enable) to enabled. Leave all other settings default.
In the Pin Manager, configure the SCK, SDO, and RCLK pins to match how you wired your breadboard. Make sure none of the pins are set to analog, that all pins are correctly set as inputs or outputs accordingly.
Generate your MCC code. Then go to spi.h and identity the function that opens the SPI port along with the struct that contains the default operating mode. This is required to enable the SPI port.
Please use MCC Classic. We can support it better, it has more advanced configuration options, but is also still relatively easy to use.
Write code to do the following:
Prior to the while() loop add the function to open the SPI port in its default configuration.
Set the storage register clock pin to low (meaning that the storage registers will not yet store the values in the shift register).
Write an 8-bit byte to illuminate some of the LEDs.
(See spi1.h for the API function to do this)
Wait 1 ms for the send operation to complete.
Set the storage register clock pin to high (this low to high transition will cause the storage registers to store the current values in the shift register and output them to the LEDs).
Wait 500 ms before the next operation.
Compile, test, and (if necessary) debug the above code and hardware until you are able to light up LEDs connected to the shift register.
If this step doesn’t work, debug by first checking all connections against the data sheet, looking for error messages in the IDE, and analyzing your code. If you’re still stuck, see the teaching team for help.
Modify the above code to display a pattern where a single LED “chases” from one end of the row to the other, and then reverses direction. See video example.
proceed to Part 2 of this tutorial…