• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
Retro Game Coders

Retro Game Coders

Retro computer/console game + dev community

  • Home
  • About
  • Blog
  • Retro Resources
    • Retro Gaming Timeline
    • Browser C64 Emulator
    • Best Retro YouTube Channels
    • New Retro Books
    • Raspberry Pi Amiga Emulation
    • MiSTer FPGA Tutorial
    • BMC64 C64 Pi
  • Contact
Home » Hardware

Programming Electronics with the Commodore User Port Part 1: Blinking an LED

Part 1 of a series of electronics projects using the Commodore User Port. In this first lesson we blink an LED on and off with C64 BASIC

In the 1980s, instead of Arduino and Raspberry Pi, there were the 8-bit micros such as the Vic 20, the Commodore 64, the BBC, and the Apple II. A generation of electronics and robotics inventors got their start with these machines.

While I mainly do electronics over on my Maker Hacks site, I asked the community if anyone was interested in retro hardware programming and there was enough interest that I thought it was worth testing the waters!

1980s Electronics Tinkering Versus Today

Practical Things to Do with a Microcomputer book published by Usborne - they had some of the best books for Micros in the 1980s
Usborne had some of the best books for Micros in the 1980s

It’s worth pointing out that the generation of computer nerds before mine got into computers either at University or by building kits. For many, electronics skills came first.

With my generation, things were a little different. Our computers were sold as “easy to use”, and were paid for by our parents. That meant a lot of kids, including me, didn’t dare wire anything up to our computers even though many were meant to be played with in this way. So we read the occasional article or flicked through the books in the library and learned about it, but not by doing anything practical.

That said, a lot of people did use their computers this way, doing everything from hacking the telephone system to rigging up smart homes before “the internet of things” had an internet to connect to.

In particular, the Commodore PET had a thriving cottage industry of sound and joystick interfaces seeing as the computer originally came with neither as standard.

Commodore User Port

Commodore PET and Vic 20

On the Vic 20 the Data Direction Register address is 37138, and input/output on 37136

The Data Direction Register on the Commodore PET is 59459 and it uses 59471 to read/write to the pins.

Like the Arduino and Raspberry Pi, the Commodore series of computers have a “general purpose input and output” expansion. This means there are several pins that can be written to at address 56577 (using POKE) or read (using PEEK).

We can connect directly to the user port but that is not wise, so instead grab yourself some user port adapters. They are cheap even for good quality ones from reliable vendors such as Future Was 8 Bit.

You will see the top row of pins are numbered, the bottom row are lettered from A to N. Beware the top pins has a 5v DC pin toward the left and even 9v +/- AC on the far right!

User Port Adapter from Future Was 8 Bit

The “Data Direction” is set by the register (DDR) on the 6526 chip and you can set each pin individually as input (0) or output (1). The pins we are most interested in right now are the bottom set, and they are controlled by a byte from 0 to 255 POKEd to the memory address 56579 on the C64/128.

As usual, a good reference is the C64 Programmer’s Reference guide.

PinName
AGND
BFLAG2
CPB0
DPB1
EPB2
FPB3
HPB4
JPB5
KPB6
LPB7
MPA2
NGND
Commodore C64/128/Vic 20 and PET User Port Pinout
User Port Adapter with Pinout Labelled
BOTTOM of the User Port Adapter with Pinout Labelled

Protect Your Retro Machine!

We don’t want to damage our beloved machines by drawing excessive current (in total devices attached to the C64 can draw 450mA but each individual pin is ~100mA) so I am using a tiny LED and an over-spec resistor (1k).

Even so, this is one of the reasons behind me owning an Ultimate 64 rather than doing this kind of thing on my actual Commodores.

You might want to do initial experimentation using a Raspberry Pi and BMC64, which supports an emulated user port, plus allows you to switch between different Commodore models.

Simple User Port LED Blink Example

Make sure you know which way your user port adapter is oriented with your circuit diagram
Make sure you know which way your adapter is oriented with your circuit diagram

You will notice, as soon as you wire up an LED as in this most simple of examples, the LED lights up. Don’t worry, you probably don’t have a short, it’s just that the default state of the user port pins!

We are using the Ground and Pin PB0, found on the adapter at location “C”. As you can see in the photographs, I have marked the top of my adapter and the ground and 5v pins to ensure I don’t wire up the wrong inputs and outputs.

Wiring up an LED and resistor to the User Port
Wiring up an LED and resistor to the User Port

These labels are helpful because a lot of the projects out there tend to switch between referencing the back of the machine and the pins on the adapter, so it is good to ensure you are orienting correctly.

Rather than solder, for this simple project I have a couple of nice alligator clip jumper wires and a breadboard. When we get to my project where I connect my C64 to the internet I do solder just to ensure good signal integrity.

We connect Ground from the bottom far-left pin on the user port to the breadboard and bridge from that wire to the shorter leg of our LED with the 1k resistor. The long pin of the resistor is then connected to PB0/”C” on the adapter.

When the pin is turned on or off using POKE 56577,1 or POKE 56577,0 we see the LED turn on or off accordingly. While BASIC isn’t super fast, it is fast enough that we need to slow the situation with empty FOR loops.

Blinking an LED using BASIC and the User Port
Blinking an LED using BASIC and the User Port

If you like it, share it! (Please - because it really helps)

  • Tweet
Category: HardwareTag: c64, commodore pet, vic20
Previous Post:Loading Game Data – Commodore BASIC Programming Part 6
Next Post:Cheap and Easy Arduino C64 Keyboard to USB Adapter

Retro Game Coders

Retro computer/console game + dev community by Chris Garrett

  • Facebook
  • Twitter
  • Instagram
  • YouTube

Maker Hacks ・ Geeky Game Master

© Copyright 2021 Chris Garrett

Privacy ﹒ Terms of Service

Return to top