6522 / 65C22 VIA

Pinout

Vss --- 1 -6522 VIA- 40 <-- ca1
pa0 <-> 2 39 <-- ca2
pa1 <-> 3 38 <-- rs0
pa2 <-> 4 37 <-- rs1
pa3 <-> 5 36 <-- rs2
pa4 <-> 6 35 <-- rs3
pa5 <-> 7 34 <-- !rst
pa6 <-> 8 33 <-> d0
pa7 <-> 9 32 <-> d1
pb0 <-> 10 31 <-> d2
pb1 <-> 11 30 <-> d3
pb2 <-> 12 29 <-> d4
pb3 <-> 13 28 <-> d5
pb4 <-> 14 27 <-> d6
pb5 <-> 15 26 <-> d7
pb6 <-> 16 25 <-- ph2
pb7 <-> 17 24 <-- cs1
cb1 <-> 18 23 <-- !cs2
cb2 <-> 19 22 <-- r/!w
Vcc --- 20 21 <-- !irq

Software structure

struct VIA	=	// a standard 6522 chip
{
	byte	PORTB;	// Port B
	byte	PORTA;	// Port A
	byte	DDRA;	// Port B Control (Data Direction Register B)
	byte	DDRB;	// Port A Control (Data Direction Register A)
			// Write (R/W = L) | Read (R/W = H)
	byte	T1C_L;	// T1 Low-Order Latches | T1 Low-Order Counter
	byte	T1C_H;	// T1 High-Order Counter| T1 High-Order Counter
	byte	T1L_L;	// T1 Low-Order Latches
	byte	T1L_H;	// T1 High-Order Latches
	byte	T2C_L;	// T2 Low-Order Latches | T2 Low-Order Counter
	byte	T2C_H;	// T2 High-Order Counter
	byte	SR;	// Shift Register
	byte	ACR;	// Auxiliary Control Register
	byte	PCR;	// Peripheral Control Register
	byte	IFR;	// Interrupt Flag Register
	byte	IER;	// Interrupt Enable Register
	byte	PORTA_NH;	// Same as Register 1 except no handshake.

};

Hardware structure

Approximate VHDL entity only!

entity VIA_6522 is	-- 
port(
	n_rst:	in	std_logic;	-- Reset
	n_wr:	in	std_logic;	-- Read / Not Write
	ph2:	in	std_logic;	-- CPU clock phase 2
	cs1:	in	std_logic;
	n_cs2:	in	std_logic;
	rs:	in	std_logic_vector(3 downto 0);
	d:	inout	std_logic_vector(7 downto 0);
	pa:	inout	std_logic_vector(7 downto 0);	-- Port A
	ca:	inout	std_logic_vector(2 downto 1);	-- Port CA
	pb:	inout	std_logic_vector(7 downto 0);	-- Port B 
	cb:	inout	std_logic_vector(2 downto 1);	-- Port CB
	);
end entity VIA_6522;

Data Sheet

For full details see the R6522 Rockwell Versatile Interface Adapter (VIA) data sheet (Zipped TIF)


Pinout comparison:

Pin 6821
6520
6522 6526
18 CB1 CB1 !PC
19 CB2 CB2 TOD in
21 R/!W !IRQ !IRQ
22 CS0 R/!W R/!W
23 !CS2 !CS2 !CS
24 CS1 CS1 !FLAG
35 A0 RS3 RS3
36 A1 RS2 RS2
37 !IRQB RS1 RS1
38 !IRQA RS0 RS0
39 CA2 CA2 SP
40 CA1 CA1 CNT