ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ R6522 VERSATILE INTERFACE ADAPTER ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ DESCRIPTION The R6522 Versatile Interface Adapter (VIA) is a very flexible I/O control device. In addition, this device contains a pair of very powerful 16-bit interval timers, a serial-to-parallel/parallel-to-serial shift register and input data latching on the peripheral ports. Expanded handshaking capability allows control of bidirectional data transfers between VIA's in multiple processor systems. Control of peripheral devices is handled primarily through two 8-bit bidirectional ports. Each line can be programmed as either an input or an output. Several peripheral I/O lines can be controlled directly from the interval timers for generating programmable frequency square waves or for counting externally generated pulses. To facilitate control of the many powerful features of this chip, an interrupt flag register, an interrupt enable register and a pair of function control registers are provided. FEATURES o Two 8-bit bidirectional I/O ports o Two 16-bit programmable timer/counters o Serial data port o TTL compatible o CMOS compatible peripheral control lines o Expanded "handshake" capability allows positive control data transfers between processor and peripheral devices o Latched output and input registers o 1 MHz and 2 Mhz operation o Single +5V power supply ORDERING INFORMATION ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ Vss ͵ 1 40 ÆÍ CA1 PA0 ͵ 2 39 ÆÍ CA2 Part Number: PA1 ͵ 3 38 ÆÍ RS0 R6522 _ _ _ PA2 ͵ 4 37 ÆÍ RS1 ³ ³ ³ PA3 ͵ 5 36 ÆÍ RS2 ³ ³ ³ PA4 ͵ 6 35 ÆÍ RS3 ³ ³ ³ PA5 ͵ 7 34 ÆÍ RES ³ ³ ³ PA6 ͵ 8 33 ÆÍ D0 ³ ³ ³ PA7 ͵ 9 32 ÆÍ D1 ³ ³ ÀÄÄÄÄÄÄ Temperature Range PB0 ͵ 10 31 ÆÍ D2 ³ ³ Blank = 40øC to +70øC PB1 ͵ 11 30 ÆÍ D3 ³ ³ E = 40øC to +85øC PB2 ͵ 12 29 ÆÍ D4 ³ ³ PB3 ͵ 13 28 ÆÍ D5 ³ ³ PB4 ͵ 14 27 ÆÍ D6 ³ ÀÄÄÄÄÄÄÄÄ Package PB5 ͵ 15 26 ÆÍ D7 ³ C = Ceramic PB6 ͵ 16 25 ÆÍ 02 ³ P = Plastic PB7 ͵ 17 24 ÆÍ CS1 ³ CB1 ͵ 18 23 ÆÍ CS2 ³ CB2 ͵ 19 22 ÆÍ R/W ÀÄÄÄÄÄÄÄÄÄÄ Frequency Vcc ͵ 20 21 ÆÍ IRQ No Letter = 1 MHz ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ A = 2 MHz R6522 Pin Configuration INTERFACE SIGNALS ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ / ³ ³ \ ³ /ÀÄÄÄÄÄÙ\ ³ ³ /ÀÄÄÄÄÄÙ\ ³ M B ³ D0-D7 < 8 >³ ³< (8) > PA0-PA7 ³ I U ³ \ÚÄÄÄÄÄ¿/ ³ ³ \ÚÄÄÄÄÄ¿/ ³ C S ³ ³ ³ ³ P I R ³ 02 ÄÄÄÄÄÄÄÄÄÄ>³ ³<ÄÄÄÄÄÄÄÄÄÄ CA1 ³ E N R O I ³ _ ³ ³ ³ R T 6 P N ³ R/W ÄÄÄÄÄÄÄÄÄÄ>³ R6522 ³<ÄÄÄÄÄÄÄÄÄ> CA2 ³ I E 5 R T < ___ 2 ³ VIA ³ > P R 0 O E ³ CS1,CS2 ÄÄÄÄÄ/ÄÄÄÄ>³ ³<ÄÄÄÄÄÄÄÄÄ> CB1 ³ H F 0 C R ³ 4 ³ ³ ³ E A E F ³ RS0-RS3 ÄÄÄÄÄ/ÄÄÄÄ>³ ³<ÄÄÄÄÄÄÄÄÄ> CB2 ³ R C S A ³ ___ ³ ³ ³ A E S C ³ RES ÄÄÄÄÄÄÄÄÄÄ>³ ³ /ÀÄÄÄÄÄÙ\ ³ L O E ³ ___ ³ ³< (8) > PB0-PB7 ³ R ³ IRQ ÄÄÄÄÄÄÄÄÄÄ>³ ³ \ÚÄÄÄÄÄ¿/ ³ \ ³ ³ / ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Figure 1. R6522 VIA Interface Signals ___ RESET (RES) ___ A low reset (RES) input clears all R6522 internal registers to logic 0 (except T1 and T2 latches and counters and the Shift Register). This places all peripheral interface lines in the input state, disables the timers, shift register, etc. and disables interrupting from the chip. INPUT CLOCK (PHASE 2) The input clock is the system 02 clock and triggers all data transfers between processor bus and the R6522. _ READ/WRITE (R/W) The direction of the data transfers between the R6522 and the system processor is controlled by the R/W line in conjunction with the CS1 and CS2 inputs. When R/W is low (write operation), and the R6522 is selected, data is transferred from the processor bus into the selected R6522 register. When R/W is high (read operation), and the R6522 is selected, data is transferred from the selected R6522 register to the processor bus. DATA BUS (D0-D7) The eight bidirectional data bus lines transfer data between the R6522 and the system processor bus. During read cycles, the contents of the selected R6522 register are placed on the data bus lines. During write cycles, these lines are high-impedance inputs and data is transferred from the processor bus into the selected register. When the R6522 is not selected, the data bus lines are high impedance. ___ CHIP SELECTS (CS1, CS2) The two chip select inputs are normally connected to processor address lines either directly or through decoding. The selected R6522 register is accessed when CS1 is high and CS2 is low. REGISTER SELECTS (RS0-RS3) The coding of the four Register Select inputs select one of the 16 internal registers of the R6522, as shown in Table 1. Table 1. R6522 Register Addressing ÚÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³Reg.³ RS Coding ³Register ³ Register/Description ³ ³ # ÃÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ´ Desig. ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³RS3³RS2³RS1³RS0³ ³ Write (R/W = L) ³ Read (R/W = H) ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 0 ³ 0 ³ 0 ³ 0 ³ 0 ³ ORB/IRB ³ Output Register B ³ Input Register B ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 1 ³ 0 ³ 0 ³ 0 ³ 1 ³ ORA/IRA ³ Output Register A ³ Input Register A ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 2 ³ 0 ³ 0 ³ 1 ³ 0 ³ DDRB ³ Data Direction Register B ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 3 ³ 0 ³ 0 ³ 1 ³ 1 ³ DDRA ³ Data Direction Register A ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 4 ³ 0 ³ 1 ³ 0 ³ 0 ³ T1C-L ³ T1 Low-Order Latches ³ T1 Low-Order Counter ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 5 ³ 0 ³ 1 ³ 0 ³ 1 ³ T1C-H ³ T1 High-Order Counter³ T1 High-Order Counter³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 6 ³ 0 ³ 1 ³ 1 ³ 0 ³ T1L-L ³ T1 Low-Order Latches ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 7 ³ 0 ³ 1 ³ 1 ³ 1 ³ T1L-H ³ T1 High-Order Latches ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 8 ³ 1 ³ 0 ³ 0 ³ 0 ³ T2C-L ³ T2 Low-Order Latches ³ T2 Low-Order Counter ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 9 ³ 1 ³ 0 ³ 0 ³ 1 ³ T2C-H ³ T2 High-Order Counter ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 10 ³ 1 ³ 0 ³ 1 ³ 0 ³ SR ³ Shift Register ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 11 ³ 1 ³ 0 ³ 1 ³ 1 ³ ACR ³ Auxiliary Control Register ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 12 ³ 1 ³ 1 ³ 0 ³ 0 ³ PCR ³ Peripheral Control Register ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 13 ³ 1 ³ 1 ³ 0 ³ 1 ³ IFR ³ Interrupt Flag Register ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 14 ³ 1 ³ 1 ³ 1 ³ 0 ³ IER ³ Interrupt Enable Register ³ ÃÄÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 15 ³ 1 ³ 1 ³ 1 ³ 1 ³ ORA/IRA ³ Output Register Aø ³ Input Register Aø ³ ÃÄÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ NOTE: øSame as Register 1 except no handshake. ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ___ INTERRUPT REQUEST (IRQ) The Interrupt Request output goes low whenever an internal interrupt flag is set and the corresponding interrupt enable bit is a logic 1. This output is open-drain to allow the interrupt request signal to be wire-OR'ed with other equivalent signals in the system. PERIPHERAL PORT A (PA0-PA7) Port A consists of eight lines which can be individually programmed to act as inputs or outputs under control of a Data Direction Register A. The polarity of output pins is controlled by an Output Register and input data may be latched into an internal register under control of the CA1 line. All of these modes of operation are controlled by the system processor through the internal control registers. These lines represents one standard TTL load in the input mode and will drive one standard TTL load in the output mode. Figure 2 illustrates the output circuit. +5V o ³ > < > < ³ *ÄÄÄÄÄ*ÄÄÄ> PA0-PA7, ³ ³ CA2 ÚÄÄÄÄÄ¿ ÚÄÄÙ ³ I/O CONTROL ÄÄÄÄ´ ³ |³ ³ ³ NOR ³oÄÄÄÄ´³ ³ OUTPUT DATA ÄÄÄÄ´ ³ |³ ³ ÀÄÄÄÄÄÙ ÀÄÄ¿ ³ __³__ ³ --- ³ ~ ³ INPUT DATA <ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Figure 2. Port A Output Circuit PORT A CONTROL LINES (CA1,CA2) The two Port A control lines act as interrupt inputs or as handshake outputs. Each line controls an internal interrupt flag with a corresponding interrupt enable bit. In addition, CA1 controls the latching of data on Port A input lines. CA1 is a high-impedance input only while CA2 represents one standard TTL load in the input mode. CA2 will drive one standard TTL load in the output mode. PORT B (PB0-PB7) Peripheral Port B consists of eight bi-directional lines which are controlled by an output register and a data direction register in much the same manner as the Port A. In addition, the polarity of the PB7 output signal can be controlled by one of the interval timers while the second timer can be programmed to count pulses on the PB6 pin. Port B lines represent one standard TTL load in the input mode and will drive one standard TTL load in the output mode. In addition, they are capable of sourcing 1.0 mA at 1.5 Vdc in the output mode to allow the outputs to directly drive Darlington transistor circuits. Figure 3 is the circuit schematic. +5V o ³ *ÄÄÄÄÄÄ¿ ³ ³ INPUT ÚÄÄÄÄÄ¿ ÚÄÄÙ > OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄ*ÄÄÄ´ ³ |³ < CONTROL ³\ ³ ³ NOR ³oÄÄÄÄ´³ > ÚÄÄo³ >ÄÄÄÅÄÄÄ´ ³ |³ < ³ ³/ ³ ÀÄÄÄÄÄÙ ÀÄÄ¿ ³ ³ ³ ³ ³ ³ ³ *ÄÄÄÄÄÄ*ÄÄÄ> PB0-PB7, ³ ³ ³ ³ CB1,CB2 ³ ³ ÚÄÄÄÄÄ¿ ÚÄÄÙ ³ ³ ÀÄÄÄ´ ³ |³ ³ OUTPUT ³ ³ NOR ³oÄÄÄÄ´³ ³ DATA ÄÄÄ*ÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ |³ ³ ÀÄÄÄÄÄÙ ÀÄÄ¿ ³ __³__ ³ --- ³ ~ ³ INPUT DATA <ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Figure 3. Port B Output Circuit PORT B CONTROL LINES (CB1,CB2) The Port B control lines act as interrupt inputs or as handshake outputs. As with CA1 and CA2, each line controls an interrupt flag with a corresponding interrupt enable bit. In addition, these lines act as a serial port under control of the Shift Register. These lines represent one standard TTL load in the input mode and will drive one standard TTL load in the output mode. CB2 can also drive a Darlington transistor circuit; however, CB1 cannot. FUNCTIONAL DESCRIPTION The internal organization of the R6522 VIA is illustrated in Figure 4. INTERRUPT ___ CONTROL ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ> IRQ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ÚÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ ³ FLAGS ³ ³ ³INPUT LATCH³ ³ ³ ³ (IFR) ³ ³ ³ (IRA) ³ ³ ³ P ÚÄÄ\Ã------------´ ³ Ã-----------´ ³ ³ O ³ Ú/³ ENABLE ÃÄÙ ÚÄÄ\³ OUTPUT ³/ÄÄ\³BUFFERS³/ÄÄ\ R ÚÄÄÄÄÄÄÄ¿ ³ ³ ³ (IER) ³ ³ Ú/³ (ORA) ³\ÄÄ/³ (PA) ³\ÄÄ/ T ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ ³ Ã-----------´ ³ ³ DATA /ÄÄ\³ DATA ÃÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ ³ DATA DIR ³ ³ ³ A BUS \ÄÄ/³ BUS ÃÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ³ (DDRA) ³ ³ ³ ³BUFFERS³ ³ ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÙ ³ ³ ³ ³ ³ PERIPHERAL ³ ³ ³PORT A REGISTER ÀÄÄÄÄÄÄÄÙ ³ ³ ³ (PCR) ³ ³ ³ ³ À\Ã------------´ ³ ³ ÚÄÄÄÄÄÄÄÄÄÄÄ¿<ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ CA1 ³ Ú/³ AUXILIARY ³ ³ À\³ PORT A ³<ÄÄÄÄÄÄÄÄÄÄÄÄÄÄ> CA2 ³ ³ ³ (ACR) ³ ³ Ú/Ã-----------´ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ ³ ³ PORT B ³<ÄÄÄÄÄÄÄÄ¿ ³ ³ FUNCTION ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÙ<ÄÄÄÄÄÄ¿ ³ ³ ³ CONTROL ³ ³ HANDSHAKE ³ ³ ³ ³ ÚÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄ¿ ³ ³ CONTROL ³ ³ ___ ÚÄÄÄÄÄÄÄ¿ ³ ³ ³ LATCH | LATCH ³ ³ ³ ÚÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ³ RES ÄÄÄÄ>³ ³ ³ ³ ³(T1L-H)|(T1L-L)³ ³ À\³ SHIFT REG ³<ÄÄÄÄÄÄÅÄ*ÄÄÄÄÄ> CB1 _ ³ ³ ³ À\Ã-------+-------´ ³ Ú/³ (SR) ³<ÄÄÄÄÄÄ*ÄÄÄÄÄÄÄ> CB2 R/W ÄÄÄÄ>³ ³ ³ Ú/³COUNTER|COUNTER³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÙ 02 ÄÄÄÄ>³ ³ ³ ³ ³(T1C-H)|(T1C-L)³ ³ ³ ___ ³ CHIP ³ ³ ³ ÀÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÙ ³ ³PORT B REGISTER CS2 ÄÄÄÄ>³ ACCESS³ ³ ³ TIMER 1 ³ ³ ÚÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄ¿ CS1 ÄÄÄÄ>³CONTROL³ ³ ³ ÚÄÄÄÄÄÄÄ¿ ³ ³ ³INPUT LATCH³ ³ ³ ³ ³ ³ ³ ³ LATCH ³ ³ ³ ³ (IRB) ³ ³ ³ P RS0 ÄÄÄÄ>³ ³ ³ ³ ³(T2L-L)³ ³ ³ Ã-----------´ ³ ³ O RS1 ÄÄÄÄ>³ ³ ³ ³ ÚÄÄÄÄÄÄÄÙ-------´ ³ À\³ OUTPUT ³/ÄÄ\³BUFFERS³/ÄÄ\ R RS2 ÄÄÄÄ>³ ³ ³ À\³COUNTER|COUNTER³ ÀÄÄ/³ (ORB) ³\ÄÄ/³ (PB) ³\ÄÄ/ T RS3 ÄÄÄÄ>³ ³ ÀÄÄ/³(T2C-H)|(T2C-L)³ Ã-----------´ ³ ³ ÀÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÙ ³ DATA DIR ³ ³ ³ B TIMER 2 ³ (DDRB) ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÙ Figure 4. R6522 VIA Block Diagram PORT A AND PORT B OPERATION The R6522 VIA has two 8-bit bidirectional I/O ports (Port A and Port B) and each port has two associated control lines. Each 8-bit peripheral port has a Data Direction Register (DDRA, DDRB) for specifying whether the peripheral pins are to act as inputs or outputs. A 0 in a bit of the Data Direction Register causes the corresponding peripheral pin to act as an input. A 1 causes the pin to act as an output. Each peripheral pin is also controlled by a bit in the Output Register (ORA, ORB) and the Input Register (IRA, IRB). When the pin is programmed as an output, the voltage on the pin is controlled by the corresponding bit of the Output Register. A 1 in the Output Register causes the output to go high, and a 0 causes the output to go low. Data may be written into Output Register bits corresponding to pins which are programmed as inputs. In this case, however, the output signal is unaffected. Reading a peripheral port causes the contents of the Input Register (IRA, IRB) to be transferred onto the Data Bus. With input latching disabled, IRA will always reflect the levels on the PA pins. With input latching enabled, IRA will reflect the levels on the PA pins at time the latching occurred (via CA1). The IRB register operates similar to the IRA register. However, for pins programmed as outputs there is a difference. When reading IRA, the level on the pin determines whether a 0 or a 1 is sensed. When reading IRB, however, the bit stored in the output register, ORB, is the bit sensed. Thus, for outputs which have large loading effects and which pull an output "1" down or which pull an output "0" up, reading IRA may result in reading a "0" when a "1" was actually programmed, and reading a "1" when a "0" was programmed. Reading IRB, on the other hand, will read the "1" or "0" level actually programmed, no matter what the loading on the pin. Figures 5 through 8 illustrate the formats of the port registers. In addition, the input latching modes are selected by the Auxiliary Control Register (Figure 12). REG 0 ÄÄ ORB/IRB ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ ³ 7 ³ 6 ³ 5 ³ 4 ³ 3 ³ 2 ³ 1 ³ 0 ³ ÀÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÙ Ä¿ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ PB0 ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ PB1 ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ PB2 ³ OUTPUT REGISTER ³ ³ ³ ³ ³ ³ "B" (ORB) ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PB3 ³ ³ ³ ³ ³ ÃÄ OR ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PB4 ³ ³ ³ ³ ³ INPUT REGISTER ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PB5 ³ "B" (IRB) ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PB6 ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PB7 ³ ÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ PIN ³ ³ ³ ³ DATA DIRECTION ³ WRITE ³ READ ³ ³ SELECTION ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³DDRB = 1 OUTPUT ³MPU WRITES OUTPUT LEVEL³MPU READS OUTPUT REGISTER ³ ³ ³ORB ³BIT, ORB PIN LEVEL HAS NO ³ ³ ³ ³AFFECT ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³DDRB = 0 INPUT ³MPU WRITES INTO ORB BUT³MPU READS INPUT LEVEL ON PB³ ³INPUT LATCHING DISABLED³NO AFFECT ON PIN LEVEL ³PIN ³ ³ ³UNTIL DDRB CHANGED ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³DDRB = 0 INPUT ³ ³MPU READS IRB BIT WHICH IS ³ ³INPUT LATCHING ENABLED ³ ³THE LEVEL OF THE PB PIN AT ³ ³ ³ ³THE TIME OF THE LAST CB1 ³ ³ ³ ³ACTIVE TRANSITION ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Figure 5. Output Register B (ORB), Input Register B (IRB) REG 1 ÄÄ ORA/IRA ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ ³ 7 ³ 6 ³ 5 ³ 4 ³ 3 ³ 2 ³ 1 ³ 0 ³ ÀÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÙ Ä¿ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ PA0 ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ PA1 ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ PA2 ³ OUTPUT REGISTER ³ ³ ³ ³ ³ ³ "A" (ORA) ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PA3 ³ ³ ³ ³ ³ ÃÄ OR ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PA4 ³ ³ ³ ³ ³ INPUT REGISTER ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PA5 ³ "A" (IRA) ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PA6 ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PA7 ³ ÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ PIN ³ ³ ³ ³ DATA DIRECTION ³ WRITE ³ READ ³ ³ SELECTION ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³DDRA = 1 OUTPUT ³MPU WRITES OUTPUT LEVEL³MPU READS LEVEL ON PA PIN ³ ³INPUT LATCHING DISABLED³ORA ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³DDRA = 1 INPUT ³ ³MPU READS IRA BIT WHICH IS ³ ³INPUT LATCHING ENABLED ³ ³THE LEVEL OF THE PA PIN AT ³ ³ ³ ³THE TIME OF THE LAST CA1 ³ ³ ³ ³ACTIVE TRANSITION ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³DDRA = 0 INPUT ³MPU WRITES INTO ORA BUT³MPU READS LEVEL ON PA PIN ³ ³INPUT LATCHING DISABLED³NO AFFECT ON PIN LEVEL ³ ³ ³ ³UNTIL DDRA CHANGED ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³DDRA = 0 INPUT ³ ³MPU READS IRA BIT WHICH IS ³ ³INPUT LATCHING ENABLED ³ ³THE LEVEL OF THE PA PIN AT ³ ³ ³ ³THE TIME OF THE LAST CA1 ³ ³ ³ ³ACTIVE TRANSITION ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Figure 6. Output Register A (ORA), Input Register A (IRA) REG 2 ÄÄ DDRB REG 3 ÄÄ DDRA ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ³7³6³5³4³3³2³1³0³ ³7³6³5³4³3³2³1³0³ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ PB0 ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ PA0 ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ PB1 ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ PA1 ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ PB2 ³ DATA ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ PA2 ³ DATA ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ PB3 ³_ DIRECTION ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ PA3 ³_ DIRECTION ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄ PB4 ³ REGISTER ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄ PA4 ³ REGISTER ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ PB5 ³ "B" (DDRB) ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ PA5 ³ "A" (DDRA) ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PB6 ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PA6 ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PB7 ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ PA7 ³ ÄÙ ÄÙ "0" ASSOCIATED PB PIN IS AN INPUT "0" ASSOCIATED PA PIN IS AN INPUT (HIGH IMPEDANCE) (HIGH IMPEDANCE) "1" ASSOCIATED PB PIN IS AN OUTPUT "1" ASSOCIATED PA PIN IS AN OUTPUT WHOSE LEVEL IS DETERMINED BY WHOSE LEVEL IS DETERMINED BY ORB REGISTER BIT ORA REGISTER BIT Figure 7. Data Direction Register B Figure 8. Data Direction Register A (DDRB) (DDRA) HANDSHAKE CONTROL OF DATA TRANSFERS The R6522 allows positive control of data transfers between the system processor and peripheral devices through the operation of "handshake" lines. Port A lines (CA1, CA2) handshake data on both a read and a write operation while the Port B lines (CB1, CB2) handshake on a write operation only. READ HANDSHAKE Positive control of data transfers from peripheral devices into the system processor can be accomplished very effectively using Read Handshaking. In this case, the peripheral device must generate the equivalent of a "Data Ready" signal to the processor signifying that valid data is present on the peripheral port. This signal normally interrupts the processor, which then reads the data, causing generation of a "Data Taken" signal. The peripheral device responds by making new data available. This process continues until the data transfer is complete. In the R6522, automatic "Read Handshaking" is possible on the Peripheral A Port only. The CA1 interrupt input pin accepts the "Data Ready" signal and CA2 generates the "Data Taken" signal. The "Data Ready" signal will set an internal flag which may interrupt the processor or which may be polled under program control. The "Data Taken" signal can either be a pulse or a level which is set low by the system processor and is cleared by the "Data Ready" signal. These options are shown in Figure 9 which illustrates the normal Read Handshake sequence. ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ 02 ÄÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀĺÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀĺÄÙ ÀÄÙ ÀÄÙ ÀÄ ³ ³ "DATA READY" ÄÄÄÄÄÄÄÄÄ¿ ÚºÂÂÂÂÂÂÂÂÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄ¿ CA1) ÀÄÄÄÁÁÁÁÁºÁÁÁÁÁÁÁÙ ³ ³ ÀÄÄÄÄÄÄ ___ ³ ³ ³ ³ IRQ OUTPUT ÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄ¿ ÀÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÙ ³ ÀÄÄÄÄÄÄ READ IRA ÚÄÄÄ¿ ³ ³ OPERATION ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ ³ ³ "DATA TAKEN" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ÚÄÄÄÄÄÄ HANDSHAKE MODE ÀÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÙ (CA2) ³ ³ ³ ³ "DATA TAKEN" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄ PULSE MODE ÀÄÄÄÙ (CA2) Figure 9. Read Handshake Timing (Port A, Only) WRITE HANDSHAKE The sequence of operations which allows handshaking data from the system processor to a peripheral device is very similar to that described for Read Handshaking. However, for Write Handshaking, the R6522 generates the "Data Ready" signal and the peripheral device must respond with the "Data Taken" signal. This can be accomplished on both the PA port and the PB port on the R6522. CA2 or CB2 act as a "Data Ready" output in either the handshake mode or pulse mode and CA1 or CB1 accept the "Data Taken" signal from the peripheral device, setting the interrupt flag and cleaning the "Data Ready" output. This sequence is shown in Figure 10. ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ 02 ÄÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀĺÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀĺÄÙ ÀÄÙ ÀÄÙ ÀÄ ³ ³ ³ ³ ÚÄÄÄ¿ ÚÄÄÄ¿ WRITE ORA,ORB ÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÙ ÀÄÄÄÄÄ OPERATION ³ ³ "DATA READY" ÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ HANDSHAKE MODE ÀÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÙ ³ ÀÄÄÄ (CA2,CB2) ³ ³ ³ ³ ³ ³ "DATA READY" ÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄ¿ PULSE MODE ÀÄÄÄÙ ³ ³ ÀÄÄÄ (CA2,CB2) ³ ³ ³ ³ ³ ³ "DATA TAKEN" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚºÂÂÂÂÄÄÄÄÄÄÄÄÄ (CA1,CB1) ÀÄÄÄÁÁÁÁÁÁÁÁÁºÁÁÁÙ ³ ___ ³ ³ IRQ OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄ¿ ÚÄÄÄ ÀÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÙ Figure 10. Write Handshake Timing Selection of operating modes for CA1, CA2, CB1 and CB2 is accomplished by the Peripheral Control Register (Figure 11). REG 12 ÄÄ PERIPHERAL CONTROL REGISTER ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ ³ 7 ³ 6 ³ 5 ³ 4 ³ 3 ³ 2 ³ 1 ³ 0 ³ ÀÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÙ ÀÄÄÄÄÂÄÄÄÄÙ ³ ÀÄÄÄÄÂÄÄÄÄÙ ³ CB2 CONTROL ÄÄÄÄÄÙ ³ ³ ÀÄ CA1 INTERRUPT CONTROL ÚÄÂÄÂÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³7³6³5³ OPERATION ³ ³ ³ ³ 0 = NEGATIVE ACTIVE EDGE ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ 1 = POSITIVE ACTIVE EDGE ³ ³0³0³0³ INPUT NEG. ACTIVE EDGE ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ÀÄÄÄÄ CA2 INTERRUPT CONTROL ³0³0³1³ INDEPENDENT INTERRUPT ³ ³ ÚÄÂÄÂÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ³ ³ ³ INPUT NEGATIVE EDGE ³ ³ ³3³2³1³ OPERATION ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³0³1³0³ INPUT POS. ACTIVE EDGE ³ ³ ³0³0³0³ INPUT NEG. ACTIVE EDGE ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³0³1³1³ INDEPENDENT INTERRUPT ³ ³ ³0³0³1³ INDEPENDENT INTERRUPT ³ ³ ³ ³ ³ INPUT POSITIVE EDGE ³ ³ ³ ³ ³ ³ INPUT NEGATIVE EDGE ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³1³0³0³ HANDSHAKE OUTPUT ³ ³ ³0³1³0³ INPUT POS. ACTIVE EDGE ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³1³0³1³ PULSE OUTPUT ³ ³ ³0³1³1³ INDEPENDENT INTERRUPT ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ ³ ³ INPUT POSITIVE EDGE ³ ³1³1³0³ LOW OUTPUT ³ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³1³0³0³ HANDSHAKE OUTPUT ³ ³1³1³1³ HIGH OUTPUT ³ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÀÄÁÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ ³1³0³1³ PULSE OUTPUT ³ CB1 INTERRUPT CONTROL ÄÄÄÄÄÄÄÄÙ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³1³1³0³ LOW OUTPUT ³ ³ 0 = NEGATIVE ACTIVE EDGE ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 1 = POSITIVE ACTIVE EDGE ³ ³1³1³1³ HIGH OUTPUT ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÁÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Figure 11. Peripheral Control Register (PCR) COUNTERS/TIMERS There are two independent 16-bit-counter/timers (called Timer 1 and Timer 2) in the R6522. Each timer is controlled by writing bits into the Auxiliary Control Register (ACR) to select this mode of operation (Figure 12). REG 11 ÄÄ AUXILIARY CONTROL REGISTER ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿ ³ 7 ³ 6 ³ 5 ³ 4 ³ 3 ³ 2 ³ 1 ³ 0 ³ ÀÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÁÄÂÄÙ ÀÄÄÂÄÄÙ ³ ÀÄÄÄÄÂÄÄÄÄÙ ³ ÀÄÄÄÄÄÄ PA T1 TIMER CONTROL ÄÄÄÙ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄ PB ÚÄÂÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄ¿ ³ ³ ³7³6³OPERATION ³ PB7 ³ ³ ³ LATCHING ENABLE/DISABLE ÃÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄ´ ³ ³ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³0³0³TIMED INTERRUPT ³ ³ ³ ³ ³ 0 = DISABLE LATCHING³ ³ ³ ³EACH TIME T1 IS ³ ³ ³ ³ ³ 1 = ENABLE LATCHING ³ ³ ³ ³LOADED ³DISABLE³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÃÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ ³0³1³CONTINUOUS ³ ³ ³ ³ ³ ³ ³INTERRUPTS ³ ³ ³ ÀÄÄÄÄ SHIFT REGISTER CONTROL ÃÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄ´ ³ ÚÄÂÄÂÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³1³0³TIMED INTERRUPT ³ONE- ³ ³ ³4³3³2³ OPERATION ³ ³ ³ ³EACH TIME T1 IS ³SHOT ³ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³LOADED ³OUTPUT ³ ³ ³0³0³0³ DISABLED ³ ÃÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄ´ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³1³1³CONTINUOUS ³SQUARE ³ ³ ³0³0³1³ SHIFT IN UNDER COMTROL OF T2 ³ ³ ³ ³INTERRUPTS ³WAVE ³ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ ³OUTPUT ³ ³ ³0³1³0³ SHIFT IN UNDER CONTROL OF 02 ³ ÀÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÙ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³0³1³1³ SHIFT IN UNDER CONTROL OF EXT.CLK ³ T2 TIMER CONTROL ÄÄÄÄÄÄÄÄÄÄÄÄÙ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÚÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³1³0³0³ SHIFT OUT FREE-RUNNING AT T2 RATE ³ ³5³ OPERATION ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÃÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³1³0³1³ SHIFT OUT UNDER CONTROL OF T2 ³ ³0³ TIMED INTERRUPT ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÃÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³1³1³0³ SHIFT OUT UNDER CONTROL OF 02 ³ ³1³ COUNT DOWN WITH ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ PULSES ON PB6 ³ ³1³1³1³ SHIFT OUT UNDER CONTROL OF EXT.CLK³ ÀÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÁÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Figure 12. Auxiliary Control Register (ACR) Timer 1 Operation Interval Timer T1 consists of two 8-bit latches (Figure 13) and a 16-bit counter (Figure 14). The latches store data which is to be loaded into the counter. After loading, the counter decrements at 02 clock rate. Upon reaching zero, an interrupt flag is set, and IRQ goes low if the T1 interrupt is enabled. Timer 1 then disables any further interrupts or automatically transfers the contents of the latches into the counter and continues to decrement. In addition, the timer may be programmed to invert the output signal on a peripheral pin (PB7) each time it "times-out". Each of these modes is discussed separately below. Note that the processor does not write directly into the low-order counter (T1C-L). Instead, this half of the counter is loaded automatically from the low order latch (T1L-L) when the processor writes into the high order counter (T1C-H). In fact, it may not be necessary to write to the low order counter in some applications since the timing operation is triggered by writing to the high order latch. REG 6 ÄÄ T1 LOW-ORDER LATCH REG 7 ÄÄ T1 HIGH-ORDER LATCH ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ³7³6³5³4³3³2³1³0³ ³7³6³5³4³3³2³1³0³ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ 1 ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ 256 ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ 2 ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ 512 ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ 4 ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ 1024 ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ 8 ³_ COUNT ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ 2048 ³_ COUNT ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄ 16 ³ VALUE ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄ 4096 ³ VALUE ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ 32 ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ 8192 ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 64 ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 16384 ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 128 ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 32768 ³ ÄÙ ÄÙ WRITE - 8 BITS LOADED INTO T1 WRITE - 8 BITS LOADED INTO T1 HIGH- LOW-ORDER LATCHES. THIS ORDER LATCHES. UNLIKE REG 4 OPERATION IS NO DIFFERENT OPERATION NO LATCH TO THAN A WRITE INTO REG 4 COUNTER TRANSFERS TAKE PLACE READ - 8 BITS FROM T1 LOW ORDER- READ - 8 BITS FROM T1 HIGH-ORDER LATCHES TRANSFERRED TO MPU. LATCHES TRANSFERRED TO MPU UNLIKE REG 4 OPERATION, THIS DOES NOT CAUSE RESET OF T1 INTERRUPT FLAG Figure 13. Timer 1 (T1) Latch Registers REG 4 ÄÄ T1 LOW-ORDER COUNTER REG 5 ÄÄ T1 HIGH-ORDER COUNTER ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ³7³6³5³4³3³2³1³0³ ³7³6³5³4³3³2³1³0³ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ 1 ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ 256 ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ 2 ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ 512 ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ 4 ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ 1024 ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ 8 ³_ COUNT ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ 2048 ³_ COUNT ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄ 16 ³ VALUE ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄ 4096 ³ VALUE ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ 32 ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ 8192 ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 64 ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 16384 ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 128 ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 32768 ³ ÄÙ ÄÙ WRITE - 8 BITS LOADED INTO T1 WRITE - 8 BITS LOADED INTO T1 LOW-ORDER LATCHES. LATCH HIGH-ORDER LATCHES. ALSO CONTENTS ARE TRANSFERRED AT THIS TIME BOTH HIGH- AND INTO LOW-ORDER COUNTER AT LOW-ORDER LATCHES TRANSFERRED THE TIME THE HIGH-ORDER INTO T1 COUNTER. T1 INTERRUPT COUNTER IS LOADED (REG 5) FLAG ALSO IS RESET READ - 8 BITS FROM T1 LOW-ORDER READ - 8 BITS FROM T1 HIGH-ORDER COUNTER TRANSFERRED TO MPU. COUNTER TRANSFERRED TO MPU IN ADDITION T1 INTERRUPT FLAG IS RESET (BIT 6 IN INTERRUPT FLAG REGISTER) Figure 14. Timer 1 (T1) Counter Registers Timer 1 One-Shot Mode The Timer 1 one-shot mode generates a single interrupt for each timer load operation. As with any interval timer, the delay between the "write T1C-H" operation and generation of the processor interrupt is a direct function of the data loaded into the timing counter. In addition to generating a single interrupt, Timer 1 can be programmed to produce a single negative pulse on the PB7 peripheral pin. With the output enabled (ACR7=1) a "write T1C-H" operation will cause PB7 to go low. PB7 will return high when Timer 1 times out. The result is a single programmable width pulse. ___ T1 interrupt flag will be set, the IRQ pin will go low (interrupt enabled), and the signal on PB7 will go high. At this time the counter will continue to decrement at system clock rate. This allows the system processor to read the contents of the counter to determine the time since interrupt. However, the T1 interrupt flag cannot be set again unless it has been cleared as described in this specification. Timing for the R6522 interval timer one-shot mode is shown in Figure 15. ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ 02 ÄÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀĺÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄ ³ ³ ³ ÚÄÄÄ¿ ³ WRITE T1C-H ÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ___ ³ ³ IRQ OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄ¿ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ ³ PB7 OUTPUT ÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÙ ³ N ³N-1³N-2³N-3³ ³ 0 ³N³ ³N-1³N-2³N-3³ ³ ³ ³<ÄÄÄÄ N + 1.5 CYCLES ÄÄÄÄÄ>³ Figure 15. Timer 1 One-Shot Mode Timing In the one-shot mode, writing into the T1L-H has no effect on the operation of Timer 1. However, it will be necessary to assure that the low order latch contains the proper data before initiating the count-down with a "write T1C-H" operation. When the processor writes into the high order counter (T1C-H), the T1 interrupt flag will be cleared, the contents of the low order latch will be transferred into the low order counter, and the timer will begin to decrement at system clock rate. If the PB7 output is enabled, this signal will go low on the 02 following the write operation. When the counter reaches zero, the T1 interrupt flag will be set, the IRQ pin will go low (interrupt enabled), and the signal on PB7 will go high. At this time the counter will continue to decrement at system clock rate. This allows the system processor to read the contents of the counter to determine the time since interrupt. However, the T1 interrupt flag cannot be set again unless it has been cleared as described in this specification. Timer 1 Free-Run Mode The most important advantage associated with the latches in T1 is the ability to produce a continuous series of evenly spaced interrupts and the ability to produce a square wave on PB7 whose frequency is not affected by variations in the processor interrupt response time. This is accomplished in the "free-running" mode. In the free-running mode, the interrupt flag is set and the signal on PB7 is inverted each time the counter reaches zero. However, instead of continuing to decrement from zero after a time-out, the timer automatically transfers the contents of the latch into the counter (16 bits) and continues to decrement from there. The interrupt flag can be cleared by writing T1C-H, by reading T1C-L or by writing directly into the flag as described later. However, it is not necessary to rewrite the timer to enable setting the interrupt flag on the next time-out. All interval timers in the R6522 are "re-triggerable". Rewriting the counter will always re-initialize the time-out period. In fact, the time-out can be prevented completely if the processor continues to rewrite the timer before it reaches zero. Timer 1 will operate in this manner if the processor writes into the high order counter (T1C-H). However, by loading the latches only, the processor can access the timer during each down-counting operation without affecting the time-out in process. Instead, the data loaded into the latches will determine the length of the next time-out period. This capability is particularly valuable in the free-running mode with the output enabled. In this mode, the signal on PB7 is inverted and the interrupt flag is set with each time-out. By responding to the interrupts with new data for the latches, the processor can determine the period of the next half cycle during each half cycle of the output signal on PB7. In this manner, very complex waveforms can be generated. A precaution to take in the use of PB7 as the timer output concerns the Data Direction Register contents for PB7. Both DDRB bit 7 and ACR bit 7 must be 1 for PB7 to function as the timer output. If one is 1 and the other is 0, then PB7 functions as a normal output pin, controlled by ORB bit 7. ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ 02 ÄÄÙ ÀÄÙ ÀÄÙ ÀĺÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀĺÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄ ³ ³ ³ WRITE T1C-H ÚÄÄÄ¿ ³ ³ OPERATION ÄÄÄÄÙ ÀÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ___ ³ ³ ³ IRQ OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄ¿ ºÄÄÄÄÄÄÄÄÄ¿ ³ ÀÄÄÄÄÄÄÄÄÄÄĺ ÀÄÄÄÄÄÄÄ ³ ³ ³ PB7 OUTPUT ÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄ¿ ÀÄÄÄÄĺÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄ ³ ³ ³ ³< N+1.5 CYCLES>³<ÄÄÄÄ N+2 CYCLES ÄÄÄ>³ Figure 16. Timer 1 Free-Run Mode Timing Timer 2 Operation Timer 2 operates as an interval timer (in the "one-shot" mode only), or as a counter for counting negative pulses on the PB6 peripheral pin. A single control bit in the Auxiliary Control Register selects between these two modes. This timer is comprised of a "write-only" low-order latch (T2L-L), a "read-only" low-order counter (T2C-L) and a read/write high order counter (T2C-H). The counter registers act as a 16-bit counter which decrements at 02 rate. Figure 17 illustrates the T2 Latch/Counter Registers. REG 8 Ä T2 LOW-ORDER LATCH/COUNTER REG 9 Ä T2 HIGH-ORDER COUNTER ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ³7³6³5³4³3³2³1³0³ ³7³6³5³4³3³2³1³0³ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ 1 ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ 256 ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ 2 ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ 512 ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ 4 ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ 1024 ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ 8 ³_ COUNT ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ 2048 ³_ COUNT ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄ 16 ³ VALUE ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄ 4096 ³ VALUE ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ 32 ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ 8192 ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 64 ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 16384 ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 128 ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ 32768 ³ ÄÙ ÄÙ WRITE - 8 BITS LOADED INTO T2 WRITE - 8 BITS LOADED INTO T2 LOW-ORDER LATCH HIGH-ORDER COUNTER. ALSO, LOW-ORDER LATCH TRANSFERRED READ - 8 BITS FROM T2 LOW-ORDER TO LOW-ORDER COUNTER. IN COUNTER TRANSFERRED TO MPU. ADDITION T2 INTERRUPT FLAG T2 INTERRUPT FLAG IS RESET IS RESET READ - 8 BITS FROM T2 HIGH-ORDER COUNTER TRANSFERRED TO MPU Figure 17. Timer 2 (T2) Latch/Counter Registers Timer 2 One-Shot Mode As an interval timer, T2 operates in the "one-shot" mode similar to Timer 1. In this mode, T2 provides a single interrupt for each "write T2C-H" operation. After timing out, the counter will continue to decrement. However, setting of the interrupt flag is disabled after initial time-out so that it will not be set by the counter decrementing again through zero. The processor must rewrite T2C-H to enable setting of the interrupt flag. The interrupt flag is cleared by reading T2C-L or by writing T2C-H. Timing for this operation is shown in Figure 18. ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ 02 ÄÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀĺÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄ ³ ³ ³ ÚÄÄÄ¿ ³ WRITE T2C-H ÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ___ ³ ³ IRQ OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄ¿ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ ³ ³ N ³N-1³N-2³N-3³ ³ 0 ³N³ ³N-1³N-2³N-3³ ³<ÄÄÄÄÄÄ N+1.5 CYCLES ÄÄÄÄÄ>³ Figure 18. Timer 2 One-Shot Mode Timing Timer 2 Pulse Counting Mode In the pulse counting mode, T2 counts a predetermined number of negative-going pulses on PB6. This is accomplished by first loading a number into Timer 2. Writing into T2C-H clears the interrupt flag and allows the counter to decrement each time a pulse is applied to PB6. The interrupt flag is set when T2 counts down past zero. The counter will then continue to decrement with each pulse on PB6. However, it is necessary to rewrite T2C-H to allow the interrupt flag to set on a subsequent time-out. Timing for this mode is shown in Figure 19. The pulse must be low on the leading edge of 02. WRITE T2C-H ÚÄÄÄ¿ OPERATION ÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄ¿ ÚÄÄÄÄĺÄÄÄÄÄ¿ ÚÄÄÄÄÄ¿ ÚÄÄÄÄÄÄ PB6 INPUT ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ___ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ IRQ OUTPUT ³ ³ ³ ÀÄÄÄÄÄÄÄÄ N ³ N-1 ³ N-2 1 ³ 0 ³ -1 Figure 19. Timer 2 Pulse Counting Mode SHIFT REGISTER OPERATION The Shift Register (SR) performs serial data transfers into and out of the CB2 pin under control of an internal modulo-8 counter. Shift pulses can be applied to the CB1 pin from an external source or, with the proper mode selection, shift pulses generated internally will appear on the CB1 pin for controlling external devices. The control bits which select the various shift register operating modes are located in the Auxiliary Control Register. Figure 20 illustrates the configuration of the SR data bits and Figure 21 shows the SR control bits of the ACR. REG 10 ÄÄ SHIFT REGISTER REG 11 ÄÄ AUXILIARY CONTROL REGISTER ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ³7³6³5³4³3³2³1³0³ ³7³6³5³4³3³2³1³0³ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ÀÄÁÄÁÄÁÂÁÂÁÂÁÄÁÄÙ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄ ³ ÀÄÄÂÄÄÙ ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄ ³ SHIFT ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄ ³_ REGISTER ³ SHIFT REGISTER ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄ ³ BITS ÀÄ MODE CONTROL ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ ÚÄÂÄÂÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ ³4³3³2³OPERATION ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ ÃÄÅÄÅÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÄÙ ³0³0³0³DISABLED ³ ³0³0³1³SHIFT IN UNDER CONTROL OF T2 ³ NOTES ³0³1³0³SHIFT IN UNDER CONTROL OF 02 ³ 1 WHEN SHIFTING OUT BIT 7 IS THE ³0³1³1³SHIFT IN UNDER CONT. OF EXT.CLK ³ FIRST BIT OUT AND SIMULTANEOUSLY ³1³0³0³SHIFT OUT FREE RUNNING AT T2 RATE³ IS ROTATED BACK INTO BIT 0 ³1³0³1³SHIFT OUT UNDER CONTROL OF T2 ³ 2 WHEN SHIFTING IN BITS INITIALLY ³1³1³0³SHIFT OUT UNDER CONTROL OF 02 ³ ENTER BIT 0 AND ARE SHIFTED ³1³1³1³SHIFT OUT UNDER CONT. OF EXT.CLK ³ TOWARDS BIT 7 ÀÄÁÄÁÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Figure 20. Shift registers Figure 21. Shift Register Modes SR Mode 0 -- Disabled Mode 0 disables the Shift Register. In this mode the microprocessor can write or read the SR and the SR will shift on each CB1 positive edge shifting in the value on CB2. In this mode the SR Interrupt Flag is disabled (held to a logic 0). SR Mode 1 -- Shift in Under Control of T2 In mode 1, the shifting rate is controlled by the low order 8 bits of T2 (Figure 22). Shift pulses are generated on the CB1 pin to control shifting in external devices. The time between transitions of this output clock is a function of the system clock period and the contents of the low order T2 latch (N). 02 Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿ ÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀ WRITE OR READ ÚÄ¿ ³ ³ ³ ³ ³ SHIFT REG ÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄÄ N+2 CYCLES ³<ÄÄÄ>³<ÄÄÄ>³ N+2 CYCLES ³ CB1 OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ 1 ÚÄÄÄÄÄ¿ 2 ÚÄÄÄÄÄ¿ 3 ÚÄÄÄĺÄÄ¿ 8 ÚÄÄÄÄÄ SHIFT CLOCK ÀÄÄÄÄÄÙ ÀÄÄÄÄÄÙ ÀÄÄÄÄÄÙ ÀÄÄÄÄÄÙ ³ ³ CB2 INPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\/Ä1Ä\/ÄÄÄÄÄ\/Ä2Ä\/ÄÄÄÄÄ\/Ä3Ä\/ĺÄÄÄÄÄ\/Ä8Ä\/ÄÄ DATA ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ/\ÄÄÄ/\ÄÄÄÄÄ/\ÄÄÄ/\ÄÄÄÄÄ/\ÄÄÄ/\ĺÄÄÄÄÄ/\ÄÄÄ/\ÄÄ ³ ___ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ IRQ ÄÄÄÄÄÄÄÙ ÀÄÄÄ Figure 22. SR Mode 1 ÄÄ Shift In Under T2 Control The shifting operation is triggered by the read or write of the SR if the SR flag is set in the IFR. Otherwise the first shift will occur at the next time-out of T2 after a read or write of the SR. Data is shifted first into the low order bit of SR and is then shifted into the next higher order bit of the shift register on the negative-going edge of each clock pulse. The input data should change before the positive-going edge of the CB1 clock pulse. This data is shifted into shift register during the 02 clock cycle following the positive-going edge of the CB1 clock pulse. After 8 CB1 clock pulses, the shift register interrupt flag will set and IRQ will go low. SR Mode 2 -- Shift in Under 02 Control In mode 2, the shift rate is a direct function of the system clock frequency (Figure 23). CB1 becomes an output which generates shift pulses for controlling external devices. Timer 2 operates as an independent interval timer and has no effect on SR. The shifting operation is triggered by reading or writing the Shift Register. Data is shifted, first into bit 0 and is then shifted into the next higher order bit of the shift register on the trailing edge of each 02 clock pulse. After 8 clock pulses, the shift register interrupt flag will be set, and the output clock pulses on CB1 will stop. Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú 02 ÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙ ÚÄ¿ ³ ³ ³ ³ READ SR ÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ ³ ³ ³ CB1 OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ SHIFT CLOCK ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ³ ³ CB2 INPUT ÄÄÄÄÄÄÄÄÄÄÄÄ\/Ä1\/Ä2\/Ä3\/Ä4\/Ä5\/Ä6\/Ä7\/Ä8\/ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ DATA ÄÄÄÄÄÄÄÄÄÄÄÄ/\ÄÄ/\ÄÄ/\ÄÄ/\ÄÄ/\ÄÄ/\ÄÄ/\ÄÄ/\ÄÄ/\ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ ___ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ IRQ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ Figure 23. SR Mode 2 ÄÄ Shift In Under 02 Control SR Mode 3 -- Shift in Under CB1 Control In mode 3, external pin CB1 becomes an input (Figure 24). This allows an external device to load the shift register at its own pace. The shift register counter will interrupt the processor each time 8 bits have been shifted in. However, the shift register counter does not stop the shifting operation; it acts simply as a pulse counter. Reading or writing the Shift Register resets the Interrupt Flag and initializes the SR counter to count another 8 pulses. Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿ 02 ÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀ ³ CB1 OUTPUT ÄÄÄÄÄÄ¿ 1 ÚÄÄÄÄ¿ 2 ÚÄÄÄÄ¿ 3 ÚÄÄÄÄ¿ 4 ÚÄÄÄÄĺÄÄ¿ 8 ÚÄÄÄÄÄ SHIFT CLOCK ÀÄÄÄÄÙ ÀÄÄÄÄÙ ÀÄÄÄÄÙ ÀÄÄÄÄÙ ÀÄÄÄÄÙ ³ ³ CB2 INPUT ÄÄÄÄÄÄÄÄ\/Ä1Ä\/ÄÄÄ\/Ä2Ä\/ÄÄÄ\/Ä3Ä\/ÄÄÄ\/Ä4Ä\/ÄĺÄÄÄÄ\/Ä8Ä\/ÄÄ DATA ÄÄÄÄÄÄÄÄ/\ÄÄÄ/\ÄÄÄ/\ÄÄÄ/\ÄÄÄ/\ÄÄÄ/\ÄÄÄ/\ÄÄÄ/\ÄĺÄÄÄÄ/\ÄÄÄ/\ÄÄ ___ ³ IRQ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÀÄÄÄ Figure 24. SR Mode 3 ÄÄ Shift In Under CB1 Control Note that the data is shifted during the first system clock cycle following the positive-going edge of the CB1 shift pulse. For this reason, data must be held stable during the first full cycle following CB1 going high. SR Mode 4 -- Shift Out Under T2 Control (Free-Run) Mode 4 is very similar to mode 5 in which the shifting rate is set by T2. However, in mode 4 the SR Counter does not stop the shifting operation (Figure 25). Since the Shift Register bit 7 (SR7) is recirculated back into bit 0, the 8 bits loaded into the Shift Register will be clocked onto CB2 repetitively. In this mode the Shift Register Counter is disabled. 02 Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿Ú¿ ÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀÙÀ ÚÄ¿ ³ ³ ³ ³ ³ ³ WRITE SR ÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ N+2 CYCLES ³<ÄÄÄ>³<ÄÄÄ>³ N+2 CYCLES³ ³ CB1 OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ 1 ÚÄÄÄÄÄ¿ 2 ÚÄĺÄÄ¿ 8 ÚÄÄÄÄÄ¿ 9 ÚÄÄÄ SHIFT CLOCK ÀÄÄÄÄÄÙ ÀÄÄÄÄÄÙ ÀÄÄÄÄÄÙ ÀÄÄÄÄÄÙ CB2 OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\/ÄÄÄÄÄ1ÄÄÄÄ\/ÄÄ2ÄĺÄÄÄÄ\/ÄÄÄÄÄ8ÄÄÄÄ\/ÄÄÄ1ÄÄ DATA ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ/\ÄÄÄÄÄÄÄÄÄÄ/\ÄÄÄÄĺÄÄÄÄ/\ÄÄÄÄÄÄÄÄÄÄ/\ÄÄÄÄÄÄ Figure 25. SR Mode 4 ÄÄ Shift Out Under T2 Control (Free-Run) SR Mode 5 -- Shift Out Under T2 Control In mode 5, the shift rate is controlled by T2 (as in mode 4). The shifting operation is triggered by the read or write of the SR if the SR flag is set in the IFR (Figure 26). Otherwise the first shift will occur at the next time-out of T2 after a read or write of the SR. However, with each read or write of the shift register the SR Counter is reset and 8 bits are shifted onto CB2. At the same time, 8 shift pulses are generated on CB1 to control shifting in external devices. After the 8 shift pulses, the shifting is disabled, the SR Interrupt Flag is set and CB2 remains at the last data level. ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ 02 Ù ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀĺÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ À ÚÄÄÄ¿ ³ ³ ³ ³ ³ ³ WRITE SR ÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ N+2 CYCLES ³<ÄÄÄÄÄ>³<ÄÄÄÄÄ>³ N+2 CYCLES ³ ³ CB1 OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ 1 ÚÄÄÄÄÄÄÄ¿ 2 ÚÄÄĺÄÄÄÄÄ¿ 8 ÚÄÄÄÄÄÄ SHIFT CLOCK ÀÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÙ ³ CB2 OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\/ÄÄÄÄÄÄ1ÄÄÄÄÄÄ\/ÄÄÄ2ÄÄĺÄÄÄÄÄÄÄÄ\/ÄÄÄÄÄ8ÄÄÄÄ DATA ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ/\ÄÄÄÄÄÄÄÄÄÄÄÄÄ/\ÄÄÄÄÄÄĺÄÄÄÄÄÄÄÄ/\ÄÄÄÄÄÄÄÄÄÄ ___ ³ IRQ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÀÄÄÄÄÄÄ Figure 26. SR Mode 5 ÄÄ Shift Out Under T2 Control SR Mode 6 -- Shift Out Under 02 Control In mode 6, the shift rate is controlled by the 02 system clock (Figure 27). ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚĺĿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ 02 Ù ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ À ÚÄÄÄ¿ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ WRITE SR ÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ ³ CB1 OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄ¿ 1 ÚÄÄÄ¿ 2 ÚÄÄÄ¿ 3 ÚÄÄÄ¿ 4 ÚÄĺÄÄ¿ 7 ÚÄÄÄ¿ 8 ÚÄÄÄÄÄÄ SHIFT CLOCK ÀÄÄÄÙ ÀÄÄÄÙ ÀÄÄÄÙ ÀÄÄÄÙ ÀÄÄÄÙ ÀÄÄÄÙ ³ ³ CB2 OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄ\/ÄÄÄ1ÄÄ\/ÄÄÄ2ÄÄ\/ÄÄÄ3ÄÄ\/ÄÄ4ĺÄÄÄ\/ÄÄÄ7ÄÄ\/ÄÄÄ8ÄÄÄÄ DATA ÄÄÄÄÄÄÄÄÄÄÄÄÄ/\ÄÄÄÄÄÄ/\ÄÄÄÄÄÄ/\ÄÄÄÄÄÄ/\ÄÄÄĺÄÄÄ/\ÄÄÄÄÄÄ/\ÄÄÄÄÄÄÄÄ ___ ³ IRQ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÀÄÄÄÄÄÄ Figure 27. SR Mode 6 ÄÄ Shift Out Under 02 Control SR Mode 7 -- Shift Out Under CB1 Control In mode 7, shifting is controlled by pulses applied to the CB1 pin by an external device (Figure 28). The SR counter sets the SR Interrupt Flag each time it counts 8 pulses but it does not disable the shifting function. Each time the microprocessor, writes or reads the shift register, the SR Interrupt Flag is reset and the SR counter is initialized to begin counting the next 8 shift pulses on pin CB1. After 8 shift pulses, the Interrupt Flag is set. The microprocessor can then load the shift register with the next byte of data. ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚÄ¿ ÚĺĿ ÚÄ¿ ÚÄ¿ ÚÄ¿ 02 Ù ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ ÀÄÙ À ÚÄÄÄ¿ ³ WRITE SR ÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³ CB1 INPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ 1 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ 2 ÚÄÄĺÄÄÄÄ¿ ³ 8 Ú SHIFT CLOCK ÀÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÙ ³ CB2 OUTPUT ÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\/ÄÄÄÄÄÄÄÄÄÄÄ1ÄÄÄÄÄÄÄÄÄÄ\/ÄÄÄÄÄ2ÄÄÄĺÄÄÄÄ\/ÄÄÄ8ÄÄÄÄ DATA ÄÄÄÄÄÄÄÄÄÄÄÄÄÄ/\ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ/\ÄÄÄÄÄÄÄÄÄĺÄÄÄÄ/\ÄÄÄÄÄÄÄÄ ___ ³ IRQ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÀÄÄÄÄÄÄ Figure 28. SR Mode 7 ÄÄ Shift Out Under CB1 Control INTERRUPT OPERATION Controlling interrupts within the R6522 involves three principal operations. These are flagging the interrupts, enabling interrupts and signaling to the processor that an active interrupt exists within the chip. Interrupt flags are set in the Interrupt Flag Register (IFR) by conditions detected within the R6522 or on inputs to the R6522. These flags normally remain set until the interrupt has been serviced. To determine the source of an interrupt, the microprocessor must examine these flags in order, from highest to lowest priority. Associated with each interrupt flag is an interrupt enable bit in the Interrupt Enable Register (IER). This can be set or cleared by the processor to enable interrupting the processor from the corresponding interrupt flag. If an interrupt flag is set to a logic 1 by an interrupting condition, and the corresponding interrupt enable bit is set to a 1, the Interrupt Request (IRQ) output will go low. IRQ is an "open-collector" output which can be "wire-OR'ed" with other devices in the system to interrupt the processor. Interrupt Flag Register (IFR) In the R6522, all the interrupt flags are contained in one register, i.e., the IFR (Figure 29). In addition, bit 7 of this register will be read as a logic 1 when an interrupt exists within the chip. This allows very convenient polling of several devices within a system to locate the source of an interrupt. REG 13 ÄÄ INTERRUPT FLAG REGISTER ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ³7³6³5³4³3³2³1³0³ SET BY CLEARED BY ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ ³ ³ ³ ³ ³ ³ ÀÄÄCA2´ CA2 ACTIVE EDGE ³ READ OR WRITE REG 1 (ORA)ø ³ ³ ³ ³ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ ³ ³ ³ ÀÄÄCA1ÄÄ´ CA1 ACTIVE EDGE ³ READ OR WRITE REG 1 (ORA) ³ ³ ³ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ ³ ³ ÀSHIFT REG´ COMPLETE 8 SHIFTS ³ READ OR WRITE SHIFT REG ³ ³ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ ³ ÀÄCB2ÄÄÄÄÄÄÄ´ CB2 ACTIVE EDGE ³ READ OR WRITE ORBø ³ ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ ÀÄCB1ÄÄÄÄÄÄÄÄÄ´ CB1 ACTIVE EDGE ³ READ OR WRITE ORB ³ ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ÀÄTIMER 2ÄÄÄÄÄÄÄ´ TIME-OUT OF T2 ³ READ T2 LOW OR WRITE T2 HIGH ³ ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ÀÄTIMER 1ÄÄÄÄÄÄÄÄÄ´ TIME-OUT OF T1 ³ READ T1 LOW OR WRITE T1 HIGH ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ÀÄIRQÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ANY ENABLED INTERRUPT ³ CLEAR ALL INTERRUPTS ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ø IF THE CA2/CB2 CONTROL IN THE PCR IS SELECTED AS "INDEPENDENT" INTERRUPT INPUT, THEN READING OR WRITING THE OUTPUT REGISTER ORA/ORB WILL NOT CLEAR THE FLAG BIT. INSTEAD, THE BIT MUST BE CLEARED BY WRITING INTO THE IFR, AS DESCRIBED PREVIOUSLY. Figure 29. Interrupt Flag Register (IFR) The Interrupt Flag Register (IFR) may be read directly by the processor. In addition, individual flag bits may be cleared by writing a "1" into the appropriate bit of the IFR. When the proper chip select and register signals are applied to the chip, the contents of this register are placed on the data bus. Bit 7 indicates the status of the IRQ output. This bit corresponds to the logic function: IRQ = IFR6xIER6 + IFR5xIER5 + IFR4xIER4 + + IFR3xIER3 + IFR2xIER2 + IFR1xIER1 + IFR0xIER0 Note: x = logic AND, + = logic OR The IFR bit 7 is not a flag. Therefore, this bit is not directly cleared by writing a logic 1 into it. It can only be cleared by clearing all the flags in the register or by disabling all the active interrupts as discussed in next section. Interrupt Enable Register (IER) For each interrupt flag in IFR, there is a corresponding bit in the Interrupt Enable Register (IER) (Figure 30). Individual bits in the IER can be set or cleared to facilitate controlling individual interrupts without affecting others. This is accomplished by writing to the IER after bit 7 set or cleared to, in turn, set or clear selected enable bits. If bit 7 of the data placed on the system data bus during this write operation is a 0, each 1 in bits 6 through 0 clears the corresponding bit in the IER. For each zero in bits 6 through 0, the corresponding bit is unaffected. REG 14 ÄÄ INTERRUPT ENABLE REGISTER ÚÄÂÄÂÄÂÄÂÄÂÄÂÄÂÄ¿ ³7³6³5³4³3³2³1³0³ ÀÂÁÂÁÂÁÂÁÂÁÂÁÂÁÂÙ Ä¿ ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄ CA2 ³ ³ ³ ³ ³ ³ ³ ÀÄÄÄÄÄ CA1 ³ 0 = INTERRUPT ³ ³ ³ ³ ³ ÀÄÄÄÄÄÄÄ SHIFT REG ³ DISABLED ³ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄ CB2 ³_ ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄ CB1 ³ ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄ TIMER 2 ³ 1 = INTERRUPT ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ TIMER 1 ³ ENABLED ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ SET/CLEAR ³ ÄÙ NOTES: 1 IF BIT 7 IS A "0", THEN EACH "1" IN BITS 0-6 DISABLES THE CORRESPONDING INTERRUPT. 2 IF BIT 7 IS A "1", THEN EACH "1" IN BITS 0-6 ENABLES THE CORRESPONDING INTERRUPT. 3 IF A READ OF THIS REGISTER IS DONE, BIT 7 WILL BE "1" AND ALL OTHER BITS WILL REFLECT THEIR ENABLE/DISABLE STATE. Figure 30. Interrupt Enable Register (IER) Selected bits in the IER can be set by writing to the IER with bit 7 in the data word set to a logic 1. In this case, each 1 in bits 6 through 0 will set the corresponding bit. For each zero, the corresponding bit will be unaffected. This individual control of the setting and clearing operations allows very convenient control of the interrupts during system operation. In addition to setting and clearing IER bits, the contents of this register can be read at any time. Bit 7 will be read as a logic 1, however.