Close
0%
0%

Dice project for ancient PICs

I have a PIC16C55 and 3 PIC16C57s in my junk box from a couple of decades ago. I've been on the lookout for things to do with them.

Similar projects worth following
I want get acquainted with the PIC architecture and toolchain. I came across a project to make dual dice from the PIC16C54, a two digit 7-segment display and a few components. My TL866 chip programmer can handle these MCUs. Thus started the adventure.

The circuit is remarkably simple. Besides the MCU and display, only 4 resistors, a capacitor, and a button are required. I would also toss in 2 decoupling capacitors on the power supply line. You can find the full article republished on many websites by searching for "PIC 16C54 dice".

If you look into the source code, only one current limiting resistor per digit is used by the trick of turning on one segment at a time. This is in addition to the digit multiplexing so each segment runs at 1/14th duty cycle. The PIC can easily source or sink 20mA so this drives the segment at about 1.5mA average which is enough for modern LEDs.

The assembler source code for the dice was readily found on the Internet. A hitch was that it was written for MPASM. Recent releases of XC8, the toolchain for the 8-bit PIC family use PIC-AS instead with slightly different syntax. (This accounts for some expressions of unhappiness on forums.) Fortunately Microchip has written a migration guide. In the case of the dice code, the main differences were:

  • Colon after name of variable or code label.
  • Different syntax for numeric constants.
  • Different syntax for specifying chip config options.

After making these changes and cleaning up the formatting a bit, I was able to assemble with pic-as. You will find the code in the Files section. A tip: to get listings, add -Wa,-a to the pic-as command options in the project configuration.

If you decide to try this on other PIC chips, remember to adapt the reset vector. The 16C54 and 16C55 both have 512B code memory (the 55 has more I/O pins), but the 16C57 has 2kB, and will need adjustment of the ORG for that vector.

Also notice the distribution of the segments to port pins is not a simple segment a is LSB or MSB, but rather motivated by the physical layout of the pins.

But I have decided to shelve this project. I'm doing a quick writeup to publish my cleaned up version. The main reason for shelving is I couldn't find any 2-digit common cathode displays in my junk box. It's not as if I would have to skip lunch to order some, they are so cheap, but I don't really need dual dice in my life, this is all just play, so I might wait until buying some other semiconductors to piggyback an order. The other hitch is that my chips have OTP ROM, so I get only one chance to burn the code. (You can find flash versions of those MCUs readily. Or substitute a modern member of the family). But the dice code should work as-is (famous last words).

dice.s

PIC assembler code for dice

x-asm - 11.75 kB - 08/15/2021 at 14:35

Download

  • Finally giving up on those ancient PICs

    Ken Yap03/17/2025 at 08:36 0 comments

    Still on the lookout for what to do with these ancient MCUs so I decided to try the most recent 3.0 release of the xc8-cc compiler. This can be run from the command line, the most important thing is to use the -mcpu=16c57 argument (for example) to specify the model one is compiling for. The language implmentation is actually quite decent and I could compile a source file from a project for another MCU with small changes.

    But here's the brick wall I hit:

    Only two levels of PC stack! What were they thinking? The compiler did warn me that the program required more stack than available. In a post, I think it was on StackExchange, someone wrote that early PIC programmers had to do heroic things to flatten the program to fit, inlining, state machines, and other tricks. It would be more difficult to do in C compared to assembler but a PITA in any language. It seems like they only intended the early PICs to be used for small simple applications, e.g. to replace discrete logic.

    To Microchip's belated credit they've increased the stack size in newer PICs to 8 and programming is no longer a pain.

    Even if I accepted the challenge to mangle my programs to fit the stack and I could order a flash counterpart to the OTP 16C57, the 16F57, to debug programs, why pay a few bucks for one NOS 16F57 when that can buy 10 far more capable RISC-V MCUs for that money?

    The other thing I could do is flash an already tested program onto the chips. Besides the dice program, I also discovered an IR decoder program for the schematic above. But I don't have a pressing need for either a dice or an IR decoder in my life. So these ancient chips will continue to languish in my junk box.

View project log

Enjoy this project?

Share

Discussions

Florian Wilhelm Dirnberger wrote 08/20/2021 at 04:59 point

"If you look into the source code, only one current limiting resistor per digit is used by the trick of turning on one segment at a time."

As I've build a lot of stuff with 7-Segment-Displays recently (without knowing what I am doing exactly), this is basically a very good idea that I will try to implement in further projects.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates