PIC Micro-controllers and 74HC595 Shift Registers

I recently converted to Microchip Tech PIC micro-controllers after using AVR from Atmel, I found myself enjoying the learning process and challenges that came with it. Getting my head around MPLAB is an on going process. I often see people bag MPLAB but honestly, it works. It’s not as nice as AVR Studio (which I’m use to given that I use Visual Studio too)

Developing for desktop applications then moving to micro controllers, I realised just how much more there was to learn and just how much some development environments hand to the developer, its easy to forget the back ground code that goes into a lot of functions. Moving to Microchip PIC / MPLAB X has meant that libraries that were otherwise provided by some IDE’s are not there so it means creating them. That’s not a bad thing I don’t think. At the end of the day it’s all part of learning.

7 Segment LED on a 74HC595 Shift Register.
7 Segment LED on a 74HC595 Shift Register.

Anyway, I started to use 7 segment LED’s and realised that running out of outputs on a smaller chip would happen really quick. I’ve played a little with Multiplexing and Charlieplexing (I recommend you Google both), however I used shift registers on Arduino and AVR in the past for LCD screens and LED’s so figured, can’t be that hard for the PIC.

Well, this is what I came up with. After putting a screen shot on G+ it has been slightly modified from the original and I’m sure there is still room for improvement. But it works for me on MPLAB X with XC8 on a PIC18F2550, though it should be easy enough to modify for any PIC micro-controller.

simply include the file, initialise_74HC595(); and then write_74HC595(LED_numbers[5]); to display the number 5 for example.

I hope this helps others out in their learning process, Understanding Bitwise operators is going to make life easier too. I have this same code but for Atmel AVR Studio if anyone is wanting an AVR version.

[code lang=”c”]/*

About kimberly 190 Articles
I'm an Electronics Service Technician by day. By night I'm an Application Developer, Embedded Software Developer, Mountain Biking chic. Currently starting to put together some home automation projects which I'll be posting progress on the site.


  1. This is great! I’m really new to microcontrollers in general and I was having a heck of a time finding out how to do this in XC8. So many tutorials for HiTech C, CPP and Assembly but so few for XC8. Makes it difficult to learn. Many thanks.

  2. Been playing around with this for a few days and I’m having a really hard time getting it to work with multiplexing. Any ideas?

  3. Hey, I’ve been playing around with your code for a little while now, and I found a little mistake in the info you posted!

    you mention using initialise_74hc595, but in the header has this function named initalise_74HC595!

    To the other people having trouble, this may be your problem 🙂

    Anyway, thanks for the useful library, I’m just starting off with PICs and the lack of pre-written code (when compared to arduino) is a bit of a shock to the system!

    Many thanks,
    Another kiwi EE student

Leave a Reply