Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ATtiny104_Datasheet.pdf
Скачиваний:
0
Добавлен:
12.02.2026
Размер:
3.8 Mб
Скачать

Assembly Code Example

...

;Define pull-ups and set outputs high

;Define directions for port pins

ldi r16,(1<<PUEB2) ldi r17,(1<<PB0)

ldi r18,(1<<DDB1)|(1<<DDB0) out PUEB,r16

out PORTB,r17 out DDRB,r18

;Insert nop for synchronization nop

;Read port pins

in r16,PINB

...

14.4.8.Alternate Port Functions

Most port pins have alternate functions in addition to being general digital I/Os. The following figure shows how the port pin control signals from the simplified in the figure of Ports as General Digital I/O can be overridden by alternate functions. The overriding signals may not be present in all port pins, but the figure serves as a generic description applicable to all port pins in the AVR microcontroller family.

Atmel ATtiny102 / ATtiny104 [DATASHEET]

70

Atmel-42505D-ATtiny102-ATtiny104_Datasheet_Complete-10/2016

Figure 14-6. Alternate Port Functions

 

 

PUOExn

 

 

 

REx

 

 

1

PUOVxn

 

 

 

 

 

 

 

 

 

 

 

 

 

0

 

 

 

Q

D

 

 

 

 

 

 

PUExn

 

 

 

DDOExn

 

 

Q CLR

 

 

 

 

 

RESET

WEx

 

 

DDOVxn

 

 

 

1

 

 

 

 

 

 

 

 

 

 

 

 

 

0

 

 

 

Q

D

 

 

 

 

 

 

DDxn

 

 

 

 

 

 

Q CLR

 

 

 

PVOExn

 

 

RESET

WDx

 

 

 

 

 

 

 

PVOVxn

 

 

 

 

RDx

 

 

 

 

 

 

 

Pxn

1

 

 

 

 

1

 

0

 

 

 

Q D

0

 

 

 

 

 

 

 

 

 

 

 

PORTxn

 

PTOExn

 

 

DIEOExn

 

 

Q CLR

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DIEOVxn

 

 

RESET

 

WPx

 

1

 

 

 

WRx

 

 

 

 

 

RRx

 

0

SLEEP

 

 

 

 

 

 

 

 

 

 

 

 

SYNCHRONIZER

 

 

 

RPx

 

 

 

 

 

 

 

 

 

D SET Q

D

 

Q

 

 

 

 

 

PINxn

 

 

 

 

L CLR Q

CLR

Q

 

 

 

 

 

 

 

 

 

clk I/O

 

 

 

 

 

 

 

DIxn

 

 

 

 

 

 

 

AIOxn

PUOExn:

Pxn PULL-UPOVERRIDE ENABLE

 

WEx:

WRITE PUEx

 

 

REx:

 

READ PUEx

 

PUOVxn:

Pxn PULL-UPOVERRIDE VALUE

 

WDx:

WRITE DDRx

 

DDOExn:

Pxn DATA DIRECTION OVERRIDE ENABLE

 

RDx:

 

READ DDRx

 

DDOVxn:

Pxn DATA DIRECTION OVERRIDE VALUE

 

RRx:

 

READ PORTx REGISTER

PVOExn:

Pxn PORTVALUE OVERRIDE ENABLE

 

WRx:

WRITE PORTx

 

PVOVxn:

Pxn PORTVALUE OVERRIDE VALUE

 

RPx:

 

READ PORTx PIN

DIEOExn:

Pxn DIGITAL INPUT-ENABLE OVERRIDE ENABLE

WPx:

WRITE PINx

 

DIEOVxn:

Pxn DIGITAL INPUT-ENABLE OVERRIDE VALUE

clk

 

:

I/O CLOCK

 

SLEEP:

SLEEPCONTROL

 

 

I/O

DIGITAL INPUTPIN n ON PORTx

 

DIxn:

PTOExn:

Pxn, PORTTOGGLE OVERRIDE ENABLE

 

AIOxn:

ANALOGINPUT/OUTPUTPIN n ON PORTx

DATA BUS

Note:  1. WEx, WRx, WPx, WDx, REx, RRx, RPx, and RDx are common to all pins within the same port. clkI/O and SLEEP are common to all ports. All other signals are unique for each pin.

The following table summarizes the function of the overriding signals. The pin and port indexes from previous figure are not shown in the succeeding tables. The overriding signals are generated internally in the modules having the alternate function.

Atmel ATtiny102 / ATtiny104 [DATASHEET]

71

Atmel-42505D-ATtiny102-ATtiny104_Datasheet_Complete-10/2016

Table 14-2. Generic Description of Overriding Signals for Alternate Functions

Signal Name

Full Name

Description

PUOE

Pull-up Override

If this signal is set, the pull-up enable is controlled by the PUOV signal.

 

Enable

If this signal is cleared, the pull-up is enabled when PUExn = 0b1.

 

 

 

PUOV

Pull-up Override Value

If PUOE is set, the pull-up is enabled/disabled when PUOV is set/

 

 

cleared, regardless of the setting of the PUExn Register bit.

 

 

 

DDOE

Data Direction

If this signal is set, the Output Driver Enable is controlled by the DDOV

 

Override Enable

signal. If this signal is cleared, the Output driver is enabled by the DDxn

 

 

Register bit.

 

 

 

DDOV

Data Direction

If DDOE is set, the Output Driver is enabled/disabled when DDOV is

 

Override Value

set/cleared, regardless of the setting of the DDxn Register bit.

 

 

 

PVOE

Port Value Override

If this signal is set and the Output Driver is enabled, the port value is

 

Enable

controlled by the PVOV signal. If PVOE is cleared, and the Output

 

 

Driver is enabled, the port Value is controlled by the PORTxn Register

 

 

bit.

 

 

 

PVOV

Port Value Override

If PVOE is set, the port value is set to PVOV, regardless of the setting of

 

Value

the PORTxn Register bit.

 

 

 

PTOE

Port Toggle Override

If PTOE is set, the PORTxn Register bit is inverted.

 

Enable

 

 

 

 

DIEOE

Digital Input Enable

If this bit is set, the Digital Input Enable is controlled by the DIEOV

 

Override Enable

signal. If this signal is cleared, the Digital Input Enable is determined by

 

 

MCU state (Normal mode, sleep mode).

 

 

 

DIEOV

Digital Input Enable

If DIEOE is set, the Digital Input is enabled/disabled when DIEOV is set/

 

Override Value

cleared, regardless of the MCU state (Normal mode, sleep mode).

 

 

 

DI

Digital Input

This is the Digital Input to alternate functions. In the figure, the signal is

 

 

connected to the output of the Schmitt Trigger but before the

 

 

synchronizer. Unless the Digital Input is used as a clock source, the

 

 

module with the alternate function will use its own synchronizer.

 

 

 

AIO

Analog Input/Output

This is the Analog Input/output to/from alternate functions. The signal is

 

 

connected directly to the pad, and can be used bi-directionally.

 

 

 

The following subsections shortly describe the alternate functions for each port, and relate the overriding signals to the alternate function. Refer to the alternate function description for further details.

14.4.8.1.Alternate Functions of Port A

The Port A pins with alternate functions are shown in the table below:

Atmel ATtiny102 / ATtiny104 [DATASHEET]

72

Atmel-42505D-ATtiny102-ATtiny104_Datasheet_Complete-10/2016

Table 14-3. Port A Pins Alternate Functions

Port Pin

 

Alternate Functions

 

PA[0]

 

ADC0: ADC Input Channel 0

 

 

 

 

AIN0: Analog Comparator, Positive Input

 

 

T0: Timer/Counter0 Clock Source (default location)

 

 

PCINT0: Pin Change Interrupt source 0

 

 

CLKI: External Clock

 

 

TPICLK: Serial Programming Clock

 

 

 

 

PA[1]

 

ADC1: ADC Input Channel 1

 

 

 

 

AIN1: Analog Comparator, Negative Input

 

 

OC0B: Timer/Counter0 Compare Match B Output (default

 

 

location)

 

 

PCINT1: Pin Change Interrupt source 1

 

 

TPIDATA: Serial Programming Data

 

 

 

 

PA[2]

 

PCINT2: Pin Change Interrupt source 2

 

 

 

 

 

Reset Pin

 

 

RESET:

 

 

 

 

PA[3]

 

OC0A: Timer/Counter0 Compare Match A Output (alternative

 

 

 

 

location)

 

 

PCINT3: Pin Change Interrupt source 3

 

 

 

 

PA[4]

 

ICP0: Timer/Counter0 Input Capture Input (alternative

 

 

 

 

location)

 

 

PCINT4: Pin Change Interrupt source 4

 

 

 

 

PA[5]

 

ADC2: ADC Input Channel 2

 

 

 

 

OC0B: Timer/Counter0 Compare Match B Output (alternative

 

 

location)

 

 

PCINT5: Pin Change Interrupt source 5

 

 

 

 

PA[6]

 

ADC3: ADC Input Channel 3

 

 

 

 

PCINT6: Pin Change Interrupt source 6

 

 

 

 

PA[7]

 

PCINT7: Pin Change Interrupt source 7

 

 

 

 

 

 

The alternate pin configuration is as follows:

Atmel ATtiny102 / ATtiny104 [DATASHEET]

73

Atmel-42505D-ATtiny102-ATtiny104_Datasheet_Complete-10/2016

PA[0] – ADC0/AIN0/T0/PCINT0/CLKI/TPICLK

ADC0: Analog to Digital Converter, Channel 0.

AIN0: Analog Comparator Positive Input. Configure the port pin as input with the internal pullup switched off to avoid the digital port function from interfering with the function of the Analog Comparator.

T0: Timer/Counter0 counter source.

PCINT0: Pin Change Interrupt source 0. The PA[0] pin can serve as an external interrupt source for pin change interrupt 0.

CLKI: External Clock.

TPICLK: Serial Programming Clock.

PA[1] – ADC1/AIN1/OC0B/PCINT1/TPIDATA

ADC1: Analog to Digital Converter, Channel 1.

AIN1: Analog Comparator Negative Input. Configure the port pin as input with the internal pull-up switched off to avoid the digital port function from interfering with the function of the Analog Comparator.

OC0B: Output Compare Match B Output. The PA[1] pin can serve as an external output for the Timer/Counter0 Compare Match B. The PA[1] pin has to be configured as an output (DDB1 set (one)) to serve this function. The OC0B pin is also the output pin for the PWM mode timer function.

PCINT1: Pin Change Interrupt source 1. The PA[1] pin can serve as an external interrupt source for pin change interrupt 0.

TPIDATA: Serial Programming Data.

PA[2] – PCINT2/RESET

PCINT2: Pin Change Interrupt source 2. The PA[2] pin can serve as an external interrupt source for pin change interrupt 0.

RESET: Reset Pin.

PA[3] – OC0A/PCINT3

OC0A: Output Compare Match A Output. The PA[3] pin can serve as an external output for the Timer/Counter0 Compare Match A. The pin has to be configured as an output (DDB0 set (one)) to serve this function. This is also the output pin for the PWM mode timer function.

PCINT3: Pin Change Interrupt source 3. The PA[3] pin can serve as an external interrupt source for pin change interrupt 0.

PA[4] - ICP0/PCINT4

ICP0: Input Capture Pin. The PA[4] pin can act as an Input Capture pin for Timer/Counter0.

PCINT4: Pin Change Interrupt source 4. The PA4 pin can serve as an external interrupt source for pin change interrupt 0.

PA[5] - ADC2/OC0B/PCINT5

ADC2: Analog to Digital Converter, Channel 2.

OC0B: Output Compare Match B Output: The PA1 pin can serve as an external output for the Timer/Counter0 Compare Match B. The PA[5] pin has to be configured as an output (DDB1 set (one)) to serve this function. The OC0B pin is also the output pin for the PWM mode timer function.

PCINT5: Pin Change Interrupt source 5. The PA5 pin can serve as an external interrupt source for pin change interrupt 0.

PA[6] - ADC3/PCINT6

ADC3: Analog to Digital Converter, Channel 3.

Atmel ATtiny102 / ATtiny104 [DATASHEET]

74

Atmel-42505D-ATtiny102-ATtiny104_Datasheet_Complete-10/2016

PCINT6: Pin Change Interrupt source 6. The PA6 pin can serve as an external interrupt source for pin change interrupt 0.

PA[7] - PCINT7

PCINT7: Pin Change Interrupt source 7. The PA7 pin can serve as an external interrupt source for pin change interrupt 0.

The following tables relate the alternate functions of Port B to the overriding signals shown in the figure of Alternate Port Functions.

Table 14-4. Overriding Signals for Alternate Functions in PA[7:6]

Signal

PA7/PCINT7

PA6/ADC3/PCINT6

Name

 

 

 

PUOE

0

0

 

 

 

 

 

PUOV

0

0

 

 

 

 

 

DDOE

0

0

 

 

 

 

 

DDOV

0

0

 

 

 

 

 

PVOE

0

0

 

 

 

 

 

PVOV

0

0

 

 

 

 

 

PTOE

0

0

 

 

 

 

 

DIEOE

(PCINT7 • PCIE0)

(PCINT6 • PCIE0) + ADC3D

 

 

 

 

DIEOV

PCINT7 • PCIE0

PCINT6 • PCIE0

 

 

 

 

DI

PCINT7 Input

PCINT6 input

 

 

 

 

AIO

-

ADC3

 

 

 

 

Table 14-5. Overriding Signals for Alternate Functions in PA[5:4]

 

 

 

 

Signal

PA5/ADC2/OC0B/PCINT5

 

PA4/ICP0/PCINT4

Name

 

 

 

PUOE

0

 

0

 

 

 

 

PUOV

0

 

0

 

 

 

 

DDOE

0

 

0

 

 

 

 

DDOV

0

 

0

 

 

 

 

PVOE

(OC0B Enable • REMAP)

 

0

 

 

 

 

PVOV

(OC0B • REMAP)

 

0

 

 

 

 

PTOE

0

 

0

 

 

 

 

DIEOE

(PCINT5 • PCIE0) + ADC2D

 

(PCINT4 • PCIE0)

 

 

 

 

DIEOV

PCINT5 • PCIE0

 

(PCINT4 • PCIE0)

 

 

 

 

DI

PCINT5 Input

 

ICP0/PCINT4 Input

 

 

 

 

AIO

ADC2

 

-

 

 

 

 

Atmel ATtiny102 / ATtiny104 [DATASHEET]

75

Atmel-42505D-ATtiny102-ATtiny104_Datasheet_Complete-10/2016