I/O

VIA

For a computer to be useful, it needs a means of providing input(s) and output(s). To accomplish this, these peripherals need a way of talking to the computer. I will achieve this by using a 6522. The 6522 is known as a VIA, Versatile Interface adapter. This acts as an interface between the computer and the peripheral. As well as the 6502, the 6522 was manufactured by MOS Technology. It has been designed as an I/O port controller for the 6502, so it is an ideal choice for this project!

The 6522 contains 20 I/O lines, organised into two 8-bit bidirectional ports and four control lines. The direction of the 16 lines can be independently programmed.

I will use the 6522 to allow me to have an input and an output device. Because the 6522 has two ports, I plan to use one port for an input device and the other for an output device.

6502N vs 6502S

There are two versions of the 6522, the N and S versions. I will be using the S version and recommend that you do the same, unless you have a specific need for the N version! The 6522N can be used to replace old ones and is open-drain, which allows you to connect without extra logic. The 6522S has a totem-pole configuration

Memory map

I will be using 0x6000 for port B and 0x6001 for port A.

Clock

The 6522 requires a clock signal, which will be provided by connecting pin 25 to the clock signal that the 6502 is using. Data transfer between the 6502 and the 6522 occurs when the clock is high.

Input or output

Each port contains a data direction register, DDRA and DDRB. I plan on using port A for my input device and port B for my output device. To set the pins to inputs, a 0 must be placed into DDRA. To set the pins to outputs, a 1 must be placed into DDRB.

bug

There is a big that is present in some 6522s! The bug occurs when the shift register clock input falls at the same time as the Φ2 clock falls. This makes the shift register lose one data bit and consequently results in errors. There are solutions to this problem, which I will implement later on when it could occur. Although not all 6522s suffer from this problem, I think that it’s a good idea to implement a fix for a circuit that uses a 6522 without the bug, so that it is future-proofed against a 6522 with the bug being used in it!

conclusion

I now have a computer that can run a program and display its output on an LCD. Because the LCD used 11 connections of the 16 available of the 6522s ports, I have only 5 left for PORT A. This will only be a problem if the other peripheral I use need more than 5 connections. There is a way that I could free up four connections. The LCD can be used in 4-bit mode. The advantage of this is that 4 fewer connections are required, the disadvantage is that it will be slower. This is because with the 8-bit mode you send each byte in one go. In 4-bit mode, you send one nibble and then a second. However, in practical terms, this decrease in speed might not be a problem. You also need to write a bit more code. As I add to the circuit to allow for more outputs, I will test out using the LCD in 4-bit mode.