Вы находитесь на странице: 1из 88

:

AVR RISC-
AVR - RISC
- 120 - 1
- 32 x 8 (32 8- )
-
- 20
20

- 2 -
- - 10 000 /
- 128- EEPROM
EEPROM: 100 000 /
- 128- SRAM
- -
EEPROM-
:
- 8- /

- 16- /

-
-
-

- USI -
- - - USART
:
- debugWIRE- -
- SPI
-
- (Low-power Idle ),
(Power-down ),
(Standby Modes )
-
-
Brown-out Detector (BOD)
-
/ :
- 18 -
- PDIP 20 , SOIC 20 , MLF 32
:
- 1.8 - 5.5V (ATtiny2313V)
- 2.7 - 5.5V (ATtiny2313)
:
- ATtiny2313V: 0 - 4 1.8 - 5.5V, 0 - 10 2.7 - 5.5V
- ATtiny2313: 0 - 10 2.7 - 5.5V, 0 - 20 4.5 - 5.5V
:
- :
1 , 1.8V: 230 A
32 kHz, 1.8V: 20 A ( )
:
<0.1 A 1.8V

iprito@mail.ru

2006

ATtiny2313 ()

1 ATtiny2313


ATtiny2313 CMOS -8- , AVR RISC-. , ATtiny2313
, 1 1
.
, Atmel .
-
SPI-(serial peripheral interface)
. 8- RISC -
ATtiny2313

.
ATtiny2313 , : , , /,
.

iprito@mail.ru

2006

ATtiny2313 ()

2 - ATtiny2313 ( )

iprito@mail.ru

2006

ATtiny2313 ()

AVR 32 . 32
- (ALU),
1 . RISC
CISC-.
ATtiny2313 : 2 - ,
128 EEPROM, 128 SRAM, 18 - , 32
, -, /
, , -USART,
USI ,

.
(Idle mode) , SRAM, /
.
(Power Down mode) ,
, .
(Standby mode) ,
,
.

iprito@mail.ru

2006

ATtiny2313 ()


VCC

GND

Port A (PA2..PA0) 3- /

Port B (PB7..PB0)

Port D (PD6..PD0)

RESET

XTAL1

XTAL2

() ( ).

.
.
( )
, .
ATtiny2313 52.
8- /
() ( ).

.
.
( )
, .
ATtiny2313 52.
7- /
() ( ).
D
. D
.
D ( )
, . D
ATtiny2313 52.
.
, .
15 33.
.
, .. : PA2 dW.

. XTAL1 PA0.
.
XTAL2 - PA1.


, ,
. ,
. , / -
, -
-.
.


, .
.

iprito@mail.ru

2006

ATtiny2313 ()

AVR

AVR-. -
. ,
, .

3 - AVR-
, AVR -
.
.
. .
- .
32 8-
. .
- , ,

iprito@mail.ru

2006

ATtiny2313 ()

, .
32 16-
- .
- . 16 X,Y Z, .

. .
.

. AVR-
16- . 16- 32- .

.
. (//)
SP- !
. / /.
AVR .
AVR
.

, .
.
. ,
, .
/ 64
/ . /. /

020 05F.


() AVR 32
. ! .
- 3 : 1-, 2- 3- .
,,
. " " .


- .
.
, ,
.
"" ,
.

- (
),
, , , .

iprito@mail.ru

2006

ATtiny2313 ()

SREG AVR :

7 - I:
() " "
.
. 7 - 0-
. 7
1 RETI- , .
7 SEI CLI ,
.
6 - T: ( )
BLD( ) BST( )
6 . - 6
BST BLD.
5 - H:
H ,
. BCD . .
.
4 - S: , S=N xor V
S- " " N V.
3 - V:
.
2 - N:
.
1 Z:
, .
0 - :
.


RISC- AVR,
. / :
- 8- 8-
- 8- 8-
- 8- 16-
- 16- 16-
4 32 .

iprito@mail.ru

2006

ATtiny2313 ()

4 - 32

.
4, ,
32 . , -,
, , X- Y- Z- .

X- Y- Z-
R26 R31
. 16-
. X,Y Z ,
5:

5 - X,Y Z
: ,
{ 1}, 1.
.

iprito@mail.ru

2006

ATtiny2313 ()

( )
"" () ,
.
(TOP) . ,
() . , PUSH (
) .
, .
( ,
) ,
.
, 060. , PUSH
, .
,
, RET RETI.
AVR 8- /.
( ). ,
() AVR ,
SPL, - SP.
SPH . ATtiny2313:

- ATtiny2313


. AVR -
.
.
6 ,
, , .
1 1
, ,
, :

6 AVR
7 () . -,
, ,
.

iprito@mail.ru

2006

ATtiny2313 ()

10

7 -


AVR . , ,
, .
, , -
. , , - ,
- .

. "" 43.
, .
( ) . (RESET) ,
INT0 - " 0",
. .43.
,
.
. ,
.
, RETI -
.
.
. , ""
(), , ,
.
( ) ,
. ,
( ),
( ) ,
, . ,
, , ,
( ) . ,
, .
,
. . ,
, ,
.
AVR- , (
, ) ,
.
, ,

. .
CLI ,
. CLI, ,
.

iprito@mail.ru

2006

ATtiny2313 ()

11

, ,
EEPROM:

SEI , ,
SEI, - , :


4 . 4
.
4 .
, 3 .

, . , ()
, 4 .
- .
4 . 4
(-) -- ,
2 I SREG.

iprito@mail.ru

2006

ATtiny2313 ()

12

AVR ATtiny2313
ATtiny2313. AVR
, . , ATtiny2313 EEPROM () . .

-
ATtiny2313 - . AVR-
16- 32- - 1 16.
- 10 000 , .
() ATtiny2313 10-, 1 (1 )
. " " 157
() - SPI-.
(
- LPM- Load Programm Memory)
10.

iprito@mail.ru

2006

ATtiny2313 ()

13

SRAM ()
9 SRAM.
224 ,
/, / SRAM. 32 -
( ), 64 - /,
128 - (SRAM).
:
1- ,
2- ,
3- (),
4- (),
5- ().
R26 R31 (
).
.
63 Y Z.
X
Y Z .
32 , 64 / 128
, .
8.


.
2 , 10:

iprito@mail.ru

2006

ATtiny2313 ()

14

10

EEPROM ()
ATtiny2313 128 EEPROM ()-.
, . EEPROM ()
100 000 . EEPROM
EEPROM, EEPROM EEPROM.
EEPROM . 171.

/ EEPROM
EEPROM /. EEPROM
1. ,
. ,
.
Vcc (+) .
, , ,
. " EEPROM" . 19
, . ,
EEPROM, .
EEPROM. EEPROM,
4 , . EEPROM
2 , , .

EEPROM EEAR

7 - Res:
ATtiny2313 .

iprito@mail.ru

2006

ATtiny2313 ()

15

6.. 0 - EEAR6.. 0: EEPROM


- EEAR - 128 EEPROM.
EEPROM 0 127. EEAR
. , , EEPROM
.

EEPROM EEDR

7.. 0 - EEDR7.. 0: EEPROM


EEPROM, EEDR ,
EEPROM, , EEAR. EEPROM,
EEDR EEPROM , EEAR.

EEPROM EER

7.. 6 - Res:
ATtiny2313 .
5, 4 - EEPM1 EEPM0: EEPROM
EEPROM ,
EEPE 1. (
) .
1. EEPE 1,
EEPMn . EEPMn 0b00, EEPROM
.

3 - EERIE: EEPROM " "


EERIE 1, ( EE READY),
1 I SREG. EERIE EEPROM.
EERIE , , EEPROM
.

iprito@mail.ru

2006

ATtiny2313 ()

16

2 - EEMPE: EEPROM
EEMPE EEPE. EEMPE 1 ,
, 4 , 1 EEPE, EEPROM
. EEMPE 1 EEPE . EEMPE 1
, 4 .
1 - EEPE: EEPROM
EEPE EEPROM,
() EEPROM. EEPE 1- EEPROM
EEPMn. EEMPE ,
EEPE, EEPROM . ,
EEPE . EEPE, ,
.
0 - EERE: EEPROM
EERE - () EEPROM. EERE
EEPROM. , - EEAR -
1 EERE EEPROM. EEPROM
. EEPROM ,
4 , .
EEPE , .
EEPROM , EEPROM
EEAR.


.
EEPROM EEAR
EEDR. EEPMn , 1 EEPE ( , 4
1 EEMPE) .
, 1 .16.
EEPE , .
EEPROM, EEPROM - .


, .
(,
). , ,
, , .
, .

, EEAR
. " ", 1 - 0b01 EEPMn, EEPE (
4 , EEMPE) . EEPE 1
. EEPROM, EEPROM
- .

, EEAR
. " ", 1 - 0b10 EEPMn, 1 EEPE (
4 , EEMPE) . EEPE 1
. , ,
. EEPROM,
EEPROM - .

iprito@mail.ru

2006

ATtiny2313 ()

17

, EEPROM. ,
" - OSCCAL"
. 25.
, EEPROM.
, I SREG,
:

iprito@mail.ru

2006

ATtiny2313 ()

18

, EEPROM.
, I SREG,
:

EEPROM
Vcc, EEPROM ,
, EEPROM . ,
- EEPROM .
EEPROM . :
EEPROM . :
, .
EEPROM , :
RESET .
Brown-out Detector (BOD) - .
BOD- ,
().
EEPROM,
, , .

iprito@mail.ru

2006

ATtiny2313 ()

19

/ (/)
/ ATtiny2313 . 209 " ".
/ ATtiny2313
/. / LD/LDS/LDD ST/STS/STD
32 /. /,
000 - 0F1, SBI CBI.
SBIS SBIC.
. /,
IN OUT, 000-03F. /
, LD ST,
0x20.
/ .
() SREG .
, , CBI SBI
.
CBI SBI : 0x00 0x1F.
/ .

/
ATtiny2313 / .

. /
0x00 - 0x1F SBI, CBI, SBIS, SBIC .

/ 2
GPIOR2 (General Purpose I/O Register)

/ 1
GPIOR1 (General Purpose I/O Register)

/ 0
GPIOR0 (General Purpose I/O Register)

iprito@mail.ru

2006

ATtiny2313 ()

20



11 .
, .
, ,
29 " ".
:

11 -


(), AVR.
, , ,
.
.

/
/ /, , /
USART. / ,
, ,
, / . , ,
USI- , / ; USI-
.


.
.

iprito@mail.ru

2006

ATtiny2313 ()

21


, Fuse (-), .
AVR .

. ,

. ,
, .

. 3 (WDT),
.
, . 179 " ATtiny2313"

3

( Vcc=5V)
4,1
65


( Vcc=3V)
4,3
69


( )
4 (4096)
64 (65536)

-
-:
CKSEL = 0010, SUT = 10, CKDIV8.
RC- -
8. - ,
.


XTAL1 XTAL2 , , ,
, 12 . 23.,
.
1 2 , .,
.
. , ,
4 . 23.
.

iprito@mail.ru

2006

ATtiny2313 ()

22

12
,
. fuse- (-) CKSEL3..1, 4:

- CKSEL0, SUT1..0, , 5:

iprito@mail.ru

2006

ATtiny2313 ()

23

:
1. ,
, .
2.
. , , , ,
.

RC-
RC- 8.0 .
Vcc=3V 25*. 8.0
, , -
CKDIV8 , 8. -
CKDIV8. , CKSEL-,
6. , - .
, OSCCAL
RC-. 3 25* ,
10% . ,
html- www.atmel.com/avr,
2% Vcc . RC-
, -
, , .
" " . 159.
6 RC-

iprito@mail.ru

2006

ATtiny2313 ()

24

, SUT-, 7:

OSCCAL

6.. 0 - CAL6.. 0:
, ,
. . OSSCAL , ,
. ,
. 0x7F
. EEPROM FLASH .
EEPROM FLASH, 10%.
. , 8 4
. , 8.

. , 2%
, . OSCCAL
020 .

iprito@mail.ru

2006

ATtiny2313 ()

25


, XTAL1 ,
13. , ,
- CKSEL - "0000".

13.
, SUT- ,
10:

10.
SUT1..0`



PowerSave(idle)
PowerDown


(Vcc=5V)

00

6CK

14CK

01

6CK

14CK+4.1

10

6CK

14CK+65

11

BOD-

Vcc

Vcc


, . 2%
. , ,
, .
, ,
.

iprito@mail.ru

2006

ATtiny2313 ()

26

128
128 ,
128 . Vcc 3V 25*.
CKSEL-- :"0110-0111".
, SUT-, 11:

11. 128

00


PowerSave(idle)
PowerDown
6 ()

01

14+4ms

10

14+4ms

SUT1..0

11


14

/:
-

- CLKPR

7
CLKPCE

6
-

5
-

4
-

3
CLKPS3

2
CLKPS2

1
CLKPS1

0
CLKPS0

CLKPR

7 - CLKPCE: -
CLKPCE CLKPS .
CLKPCE , CLKPR .
CLKPCE- CLKPS.
CLKPS ,
, .
3..0 - CLKPS3..0:

. ,
, .
. 12.
, , ,
CLKPS:
1. CLKPCE , CLKPR .
2. CLKPS,
CLKPCE.
, ,
.
--CKDIV8 CLKPS . CKDIV8
, CLKPS "0000" . CKDIV8
, CLKPS "0011" ,
8 . ,
, .

iprito@mail.ru

2006

ATtiny2313 ()

27

, CLKPS
-CKDIV8. , ,
, .
- CKDIV8.

12.
CLKPS3

CLKPS2

CLKPS1

CLKPS0

0
0
0
0
0
0
0
0
1
-

0
0
0
0
1
1
1
1
0
-

0
0
1
1
0
0
1
1
0
-

0
1
0
1
0
1
0
1
0
-

1
2
4
8
16
32
64
128
256

iprito@mail.ru

2006

ATtiny2313 ()

28



,
. AVR ,
.
SE SMCR
SLEEP. SM0 SM1 MCUCR ,
SLEEP (: Idle-, Power-down-, Standby-).
13. , , ,
- .
, ,
,
, SLEEP, , .
SRAM , .
, .
11 21 , ,, .
.

MCUCR
()

.

7
PUD

6
SM1

5
SE

4
SM0

3
ISC11

2
ISC10

1
ISC01

0
ISC00

MCUCR

6, 4 - SM1..0:
, 13.
13
SM1
SM0

0
0
-Idle
0
1
-PwerDown
1
1
-PowerDown
1
0
-Standby
1: ( Standby)
.

-Idle
SM1..0 "00", SLEEP ,
, , : UART,
, , USI-, /, .
, ,
, /
UART. ,
ACD- - ACSR.
.

iprito@mail.ru

2006

ATtiny2313 ()

29

()
SM1..0 01 11, SLEEP .
, , , ,
USI , (,
). : ,
, BOD-, USI-
, INT0 ,
, . ,
, .
, ,
-PowerDown, -
. "
" . 58 .
,
.
, . -,
, "
" . 22 .5 .24.
-StandBy
SM1..0 "10" /,
SLEEP (StandBy). PowerDown ( - - ) , -StandBy
. .

I/O

INT0,INT1
PCINT0..PCIN
T7


USI

SPM/EEPROM

I/O


Idle
PowerDown

StandBy (1)
:

FLASH

CPU

14

X(2)

X(2)

1. .
2. INT0 - .



AVR -. , ,
, ,
. . ,
.

iprito@mail.ru

2006

ATtiny2313 ()

30

()
-Idle, ,
. . ,
,
. . " " 148
.

BOD- (Brown-out Detector)


(BOD- () )
BOD- . BOD-
-BODLEVEL, , ,
. "BOD-" 34 .


()
, BOD-
. , ,
. ,
, .
.
" " 37 .

()
, .
, , , .
. ""
41 , .

/
, /
. ,
. , , / .
, / , . ,
, /
. " " 49
, . , ,
/ -
Vcc/2 .
, , .
, Vcc/2 /, ,
. ,
DIDR "Digital Input Disable Register - DIDR, 149.

iprito@mail.ru

2006

ATtiny2313 ()

31


/ , ,
ResetVector. , ,
(RJMP) , .
,
. 14
. 15 .

14
/ -, .
. , ,
, .
, .
- SUT CKSEL.
22.
:
ATtiny2313 4
- . , Vcc
VPOT, .
- . , /RESET
, .
- . , ,
, .
- BOD-. , Vcc
VBOT, BOD- .

iprito@mail.ru

2006

ATtiny2313 ()

32

15

VPOT

VRST

tRST

()

()(2)


/RESET

(1)

(1)

(1)

=-40
58*

1,2

=-40
58*

1,1

Vcc=1,8
5,5

0,1 Vcc

Vcc=1,8
5,5

0,9 Vcc

2,5

:
1. /.
TBD.
2. , VPOT
( ).

- "Power-on Reset"
(POR-)
POR-, , . ,
, 15. POR- , Vcc
. POR- ,
Vcc. POR- . ,
POR-, , ,
, Vcc . RESET- ,
, Vcc .

15 , RESET Vcc

iprito@mail.ru

2006

ATtiny2313 ()

33

16

()
RESET.
, ( 15), , ,
. , ,
15. VRST, ,
tTOUT, .

17

BOD- ( )
ATtiny2313 BOD-, , Vcc
, Vcc
. "BODLEVEL". ,
BOD- , .
: VBOT+ = VBOT + VHYST/2 VBOT- = VBOT - VHYST/2.

iprito@mail.ru

2006

ATtiny2313 ()

34

16 BODLEVEL- (1)

VBOT
VBOT
BODLEVEL 2..0
VBOT
111
BOD-
110
1,8
101
2,7
100
4,3
011
010

001
000

:
1. VBOT . , ,
, . , BOD , Vcc ,
.
, - BODLEVEL.

17 BOD-

VHYST

tBOD

BOD-

BOD.

50

BOD- Vcc VBOTIN - 18- ,


BOD- . Vcc VBOT+ -
18- , tTOUT .BOD-
Vcc , Vcc
, tBOD, 15.

18 BOD-

iprito@mail.ru

2006

ATtiny2313 ()

35

WDT
, ,
.
, tTOUT .
43.

19

"MCUSR"
, .

WDRF

BORF

EXTRF

PORF

MCUSR

Bit 3 - WDRF: Watchdog Reset Flag:


1 WDT. 0
.
Bit 2 - BORF: Brown-out Reset Flag: BOD-
1 BOD- . 0
.
Bit 1 - EXTRF: External Reset Flag:
1 . 0
.
Bit 0 - PORF: Power-on Reset Flag:
1 .
.
RESET- , ,
MCUCR- , . MCUCR - /
.

iprito@mail.ru

2006

ATtiny2313 ()

36


()
Ttiny2313 . BOD-
, .


, ,
. 18. ,
.
:
1. BOD- ( BODLEVEL- [2..0])
2. ( ACBG ACSR).
, BOD- , ACBG
, , .
-PowerDown- ,
, , PowerDown-.
18 (1)

(1)

Vcc=2.7
1
VBG

25*


Vcc=2.7
tBG

25*
,
Vcc=2.7
IBG

25*

(1)

(1)

1.1

1.2

40

70

15

:
1. /.
TBD.

iprito@mail.ru

2006

ATtiny2313 ()

37

WDT
ATtiny2313 (WDT).
:
1. .
2. :
2.1
2.2.
2.3
3. 16 8
4 WDT .

20 WDT
-WDT- , ,
128 . ,
. , WDT,
. , . .,
.
WDT , .

. .
, , WDT.
WDT ,
. ,
.
, , ,
- , .
, ,
.
, WDTON, WDT
. WDTON,
, WDE 1 ,
WDIE 0 .
, , WDT
.
WDE WDT:
1. WDCE WDE.
WDE .
2. WDE
- WDP, WDCE .
.

iprito@mail.ru

2006

ATtiny2313 ()

38

- WDT.
, ,
.

: 1. ,
. : WDT , ,
WDT .

iprito@mail.ru

2006

ATtiny2313 ()

39

WDT , WDT
WDT. , WDRF
WDE ( ), , WDT
. ,
WDT.

: 1. , .
: WDT , WDP ,
WDT WDT, .

iprito@mail.ru

2006

ATtiny2313 ()

40


(WDTCSR)
7

WDIF

WDIE

WDP3

WDCE

WDE

WDP2

WDP1

WDP0

WDTCSR

Bit 7 - WDIF: WDT


, WDT, ,
WDT . WDIF ,
. , , .
I SREG , , , WDIE
WDT.
Bit 6 - WDIE: WDT
, , ,
WDT. , ,
WDE , ,
.
WDE 1, WDT ,
. WDT WDIF. ,
, WDIE WDIF
(WDT ). ,
WDT . , WDT
, WDIE . ,
, , .. .
, WDT, WDIE
.
19
WDTON

WDE

WDIE

0
0
0

0
0
1

0
1
0


WDT

Bit 4 - WDCE: WDT


WDE . ,
WDE / , WDCE.
WDCE . , , .
Bit 3 - WDE: WDT
WDE WDRF MCUCR. ,
WDE , WDRF. , WDE,
WDRF. ,
.
Bit 5, 2..0 - WDP3..0: WDT 3, 2, 1 0
WDP3..0 ( ), WDT.
20 42.

iprito@mail.ru

2006

ATtiny2313 ()

41

20 ( ) WDT

WDP3
WDP2
WDP1
WDP0
WDT


Vcc=5.0

2 (2048)

16

4 (4096)

32

8 (8192)

64

16 (16384)

0.125

32 (32768)

0.25

64 (65536)

0.5

128 (131072)

1.0

256 (262144)

2.0

512 (524288)

4.0

1024 (1048576)

8.0

: .

iprito@mail.ru

2006

ATtiny2313 ()

42


, ATtiny2313.
AVR " ", 11.

ATtiny2313
21

0x0000

RESET

0x0001

INT0

0x0002

INT1

0x0003

TIMER1 CAPT

0x0004

TIMER1 COMPA

0x0005

TIMER1 OVF


RESET,
, BOD- ,
WDT.

INT0

INT1
/1
/1
TCNT1 OCR1A
/ 1

0x0006

TIMER0 OVF

/ 0

0x0007

USART0, RX

USART0

0x0008

USART0, UDRE

UART 0

10

0x0009

UART0, TX

11

0x000

ANALOG COMP

12

0x000

PCINT

13

0x000C

TIMER1 COMPB

14

0x000D

TIMER0 COMPA

15

0x000E

TIMER0 COMPB

16

0x00F

USI START

17

0x0010

USI OVERFLOW

18

0x0011

EE READY

19

0x0012

WDT OVERFLOW

USART0

PCINT7..0
/1
TCNT1 OCR1
/ 0
TCNT0 OCR0A
/0
TCNT0 OCR0
()
USI
USI
EEPROM (..
)
WDT

iprito@mail.ru

2006

ATtiny2313 ()

43

ATtiny2313,
:


)
1
0x0000
rjmp
RESET
;
;RESET,
;, BOD- ,
; WDT.
2
0x0001
rjmp
INT0
;
; INT0
3
0x0002
rjmp
INT1
;
; INT1
4
0x0003
rjmp
TIMER1_CAPT
;/1
5

0x0004

rjmp

TIMER1_COMPA

0x0005

rjmp

TIMER1_OVF

;/1
TCNT1 OCR1A
; /1

0x0006

rjmp

TIMER0_OVF

; /0

0x0007

rjmp

USART0_RX

; USART0

0x0008

rjmp

USART0_UDRE

; UART0

10

0x0009

rjmp

UART0_TX

; USART0

11

0x000

rjmp

ANALOG_COMP

12

0x000

rjmp

PCINT

;
;
; PCINT

13

0x000C

rjmp

TIMER1_COMPB

14

0x000D

rjmp

TIMER0_COMPA

15

0x000E

rjmp

TIMER0_COMPB

16

0x00F

rjmp

USI_START

17

0x0010

rjmp

USI_OVERFLOW

18

0x0011

rjmp

EE_READY

19

0x0012

rjmp

WDT_OVERFLOW

; EEPROM (..
;
;)
; WDT

RESET:

ldi r16,low(RAMEND)

0x0014

out SPL,r16

0x0015

sei

;
; SRAM
;
;

;/1
TCNT1 OCR1B
;/0
TCNT0 OCR0A
;/0
B
; ()
;USI
; USI

;
0x0013

0x0016

iprito@mail.ru

2006

ATtiny2313 ()

44

I/O- ( /)

AVR- -- ,
I/O-. , /
, /
, , -
SBI- CBI-. -
( ) /
( ).
.
, .
, , ,
Vcc. I/O- , Vcc GND,
21. " " 176
.

21 I/O-
. ""
( : ,, ..), "n" . ,
, .
, "PORTB3" 3 (PortB); : "PORTxn".
/ " I/O-"
57.
I/O- , :1.
- "PORTx"; 2. - "DDRx"; 3. -"PINx"; -"PINx"
, - "PORTx" "DDRx" . , -"PINx"
"PORTx". ,

PUD MCUCR.
I/O- / "I/O-
/" 46.
, . ,
, " " 50.
, ,
.

iprito@mail.ru

2006

ATtiny2313 ()

45

, ,
/.

I/O- /
. 22
I/O-, Pxn.

Pxn

22 /
: 1. WRx, WPx, WDx, RRx, RPx, RDx
, clkI/O, SLEEP, PUD .


, ; : DDxn, PORTxn,
PINxn . " I/O-" 57, DDxn
DDRx, PORTxn PORTx, PINxn PINx.
DDxn DDRx . DDxn
, Pxn . , DDxn , Pxn
.
PORTxn , ,
. , PORTxn
.
, , .
PORTXn , ,
. , PORTxn ,
, .

iprito@mail.ru

2006

ATtiny2313 ()

46


PINxn PORTxn,
DDRxn. , SBI
.


:
1. "" "Z-", ({DDxn, PORTxn} = 0b00),
;
2. . , ({DDxn,
PORTxn} = 0b11);
3. , ,
: {DDxn, PORTxn} = 0b01) ;
4. , ,
: ({DDxn, PORTxn} = 0b10);
,
, ..
Vcc. , -, ,
PUD- MCUCR.
1 2, 3 4
.
3 4 .
(- ) 1 2 .
22 .
22
PUD-
Pull-up-
DDxn PORTxn

(
I/O
()
MCUCR)

0
0
X

(Z-)
Pxn- ,
0
1
0



0
1
1

(Z-)

1
0
X

( )

1
1
X

( )


DDxn, PINx.
22, PINxn .
, , ,
, , . 23
.
tpd,max tpd,min .

23 -

iprito@mail.ru

2006

ATtiny2313 ()

47

( 23) ,
( ). ,
, , ""
, 23.
.
PINxn , ( ).
, , , ,
0,5 1,5 ,
PINxn, , .
() nop , 24. "out"
. tpd
.

24

iprito@mail.ru

2006

ATtiny2313 ()

48

, :
0 1 ;
2 3 ;
4 5 (Z-);
6 7 Vcc ;

: 1.

0, 1, 6 7, / ; 2 3
, 0 1
.


22, GND
. , SLEEP, SLEEP-
,
, , ,
Vcc/2.
, .
, (SLEEP-)
. SLEEP-, ,
, " " 50.
, ( "
", " " " "),
. , , ,
SLEEP- () , ,
SLEEP- .

iprito@mail.ru

2006

ATtiny2313 ()

49



/ . 25 , ,
22, .
, 25 ,
AVR.

PUOExn:

PUOVxn:

DDOExn:

DDOVxn:

PVOExn:

PVOVxn:

DIEOExn:

DIEOVxn:

SLEEP:

Pxn

Pxn ,

Pxn
/
Pxn ,
/
Pxn

Pxn ,

Pxn ,

Pxn , ,

WDx:

DDRx

RDx:

DDRx

Pxn

DIxn:

PTOExn:

Pxn

AIOxn:

PUD:

RRx:

PORTx

WRx:

PORTx

RPx:

PINx

WPx:

PINx

clkI/O:

/





/

25 (1)
25:
1. Pxn: P ; x ; n ;
2. DATABUS ;
: 1. WRx, WPx, WDx, RRx, RPx, RDx
, clkI/O, SLEEP, PUD .
.
23 . ,
25, 23.
, .

iprito@mail.ru

2006

ATtiny2313 ()

50

23



,
Pull-up Override Enable PUOV. PUOE

,

PUOE

, ,

:
DDxn, PORTxn PUD)
PUOE ,
Pull-up Override Value - ,
/, PUOV
PUOV

/,

DDxn, PORTxn PUD .
,
Data Direction Override Enable - ()

DDOE
DDOV. DDOE ,
/

DDxn.
Data Direction Override Value DDOE ,
,
/, DDOV
DDOV

/
/
DDxn .
,
Port Value Override Enable ,

PVOE
PVOV. PVOE ,
- ,

PORTxn.
Port Value Override Value
PVOE,
,
PVOV
PVOV

PORTxn.

Port Toggle Override Enable
PTOE, PORTxn
PTOE

.

,
Digital Input Enable Override
DIEOV.
Enable
DIEOE ,
DIEOE
,

.
Digital Input Enable Override
DIEOE ,
Value ,
/, DIEOV
DIEOV
,
/
,

.


.
25,
.
DI
Digital Input
,
, ,

.
AIO .

/
AIO
/
,
.

. ,
, .

iprito@mail.ru

2006

ATtiny2313 ()

51

MCUCR
7

PUD

SM1

SE

SM0

ISC11

ISC10

ISC01

ISC00

MCUCR

/
/
/
/
/
/
/
/
/

0
0
0
0
X
0
0
0

Bit 7 PUD:
. , I/O , ,
DDxn PORTxn ({DDxn, PORTxn} = 0b01).
46 .


PORTA
PORTA 24
24 PORTA


2
RESET, dW
1
XTAL2
0
XTAL1


PORT
PORTA 25
25 PORT


7
USCK/SCL/PCINT7
6
DO/PCINT6
5
DI/SDA/PCINT5
4
OC1B/PCINT4
3
OC1A/PCINT3
2
OC0A/PCINT2
1
AIN1/PCINT1
0
AIN0/PCINT0
, :
USCK/SCL/PCINT7 , 7
USCK:
(USI).
SCL:
:
USI.
PCINT7: , .
7 .
DO/PCINT6 , 6
DO: :
USI. PORTB6
, DDB6 1. , PORTB6
, , PORTB6 1.
PCINT6: , .
6 .

iprito@mail.ru

2006

ATtiny2313 ()

52

DI/SDA/PCINT5 , 5
DI: USI. ,
.
SDA:
USI-.
PCINT5: , .
5 .
OC1B/PCINT4 , 4
OC1B:
: 4 / 1,
. , ,
( DDB6 1.
PCINT4: , .
4 .
OC1A/PCINT3 , 3
OC1:
: 3 / 1,
. , ,
( DDB3 1).
, , , / 1 .
PCINT3: , .
3 .
OC0A/PCINT2 , 2
OC0:
: 2 / 0,
. , ,
( DDB2 1).
, , , / 0 .
PCINT2: , .
2 .
AIN1/PCINT1 , 1
AIN1: ,
.
,
.
PCINT1: , .
1 .
AIN0/PCINT0 , 0
AIN0: ,
.
,
.
PCINT0: , .
0 .
26 27 ,
, 25 ( 50). SPI MSTR INPUT SPI
SLAVE OUTPUT MISO- , MOSI SPI MSTR
OUTPUT SPI SLAVE INPUT.

iprito@mail.ru

2006

ATtiny2313 ()

53

26 PB7PB4

PB7/USCK/SCL/
PB6/DO/
PB5/SDA/DI/

PCINT7
PCINT6
PCINT5

PB4/OC1B/
PCINT4

PUOE

PUOV

DDOE

USI_TWO_WIRE

USI_TWO_WIRE

DDOV

(USI_SCL_HOLD+
PORTB7 .DDB7)

( SDA + PORTB5 ).
.
DDRB5)

PVOE

(USI_TWO_WIRE.DDRB7)

USI_TREE_WIRE

(USI_TWO_WIRE.DDRB5)

OC1B_PVOE

PVOV

DO

OC1B_PVOV

PTOE

USI_PTOE

DIEOE

(PCINT7.PCIE+USISIE)

(PCINT6.PCIE)

(PCINT5.PCIE)+USISIE

(PCINT4.PCIE)

DIEOV

DI

PCINT7 INPUT
USCK INPUT
SCL INPUT

AIO

PCINT6 INPUT

PCINT5 INPUT
SDA INPUT
DI INPUT

PCINT4 INPUT

USI_TWO_WIRE USI;
USI_TREE_WIRE USI;
HOLD ;
27 PB3PB0

PB3/OC1A/
PB2/OC0A/
PB1/AIN1/

PCINT3
PCINT2
PCINT1

PB0/AIN0/
PCINT0

PUOE

PUOV

DDOE

DDOV

PVOE

OC1A_PVOE

OC0A_PVOE

PVOV

OC1A_PVOV

OC0A_PVOV

PTOE

DIEOE

(PCINT3 PCIE)

(PCINT2 PCIE)

(PCINT1 PCIE)

(PCINT0 PCIE)

DIEOV

DI

PCINT7 INPUT

PCINT6 INPUT

PCINT5 INPUT

PCINT4 INPUT

AIO

AIN1

AIN0

iprito@mail.ru

2006

ATtiny2313 ()

54

D
D PORTD 28
28 D
D
PD6
PD5
PD4
PD3
PD2
PD1
PD0


ICP
OC0B/T1
T0
INT1
INT0/XCK/CKOUT
TXD
RXD

ICP D, 6
ICP: /1.
OC0B/T1 D, 5
OC0B:
: 2 / 0,
B. , ,
( DDB5 1).
, , , / 0 .
T1: /1 1
CS02 CS01 /1 TCCR1
T0 D, 4
T0: /0 1
CS02 CS01 /0 TCCR0
INT1 D, 3
INT1 1. PD3
.
INT0/XCK/CKOUT D, 2
INT0: 0. PD2
.
XCK: ,
USART, .
CKOUT: .
TXD D, 1
TXD: UART.
RXD D, 0
RXD: UART.

iprito@mail.ru

2006

ATtiny2313 ()

55

29 30 , D
, 25 ( 50).
29 - PD7PD4

PD6/ICP
PD5/OC1B/T1
PD4/T0
PUOE
0
0
0
PUOV
0
0
0
DDOE
0
0
0
DDOV
0
0
0
PVOE
0
OC1B_PVOE
0
PVOV
0
OC1B_PVOV
0
PTOE
0
0
0
DIEOE
ICP
T1
T0
DIEOV
1
1
1
DI
ICP
T1
T0
AIO
AIN1

30 - PD3PD0

PD3/INT1
PD2/INT0B/XCK/CKOUT
PD1/TXD
PUOE
0
0
TXD_OE
0
0
0
PUOV
DDOE
DDOV
PVOE
PVOV
PTOE

0
0

0
0
0
0
0

DIEOE

INT1

DIEOV

1
INT1

-

DI
AIO

XCK_PVOE
XCKO_PVOV
0
INT0 /
XCK
1
INT0 /
XCK
-

TXD_OE
1
TXD_OE
TXD_PVOV
0

PD0/RXD
RXD_OE
PORD0 . PUD
RXD_EN
0
0
0
0

RXD

iprito@mail.ru

2006

ATtiny2313 ()

56

I/O-
PORTA

PORTA2

PORTA1

PORTA0


DDRA

DDA2

DDA1

DDA0

PORTA

DDRA


PINA

PINA2

PINA1

PINA0

PINA

B PORTB

PORTB7

PORTB6

PORTB5

PORTB4

PORTB3

PORTB2

PORTB1

PORTB0

iprito@mail.ru

2006

ATtiny2313 ()

PORTB

57


B DDRB
7

DDB7

DDB6

DDB5

DDB4

DDB3

DDB2

DDB1

DDB0

/
DDRB


B PINB
7

PINB7

PINB6

PINB5

PINB4

PINB3

PINB2

PINB1

PINB0

PINB

D PORTD

---

PORTD6

PORTD5

PORTD4

PORTD3

PORTD2

PORTD1

PORTD0


D DDRD

---

DDD6

DDD5

DDD4

DDD3

DDD2

DDD1

DDD0

PORTD

/
DDRD


D PIND

---

PIND6

PIND5

PIND4

PIND3

PIND2

PIND1

PIND0

iprito@mail.ru

2006

ATtiny2313 ()

PIND

58


INT0 INT1 PCINT7..0. , ,
, , .
. "PCMSK"
, PCINT7..0 . PCINT7..0
, .. ,
, -Idle.
INT0 INT1 ,
. "
" - "EICRA". INT0 INT1 ,
, ,
(. 0). ,
INT0 INT1 " /"
() , 21 "
". INT0 INT1 ,
, Idle. I/O- , -Idle.
, ,
- "Power Down" - ,
, .
, ,
, .
SUT- CKSEL-, " "
21.

MCUCR
()

- "EICRA".

/

7
PUD

6
SM1

5
SE

4
SM0

3
ISC11

2
ISC10

1
ISC01

0
ISC00

MCUCR

3, 2 - ISC11, ISC10: INT1


INT1 INT1, I SREG
.
31. INT1
. / ,
, . .
,
, ,
.
31 INT1
ISC11
ISC10
0
0
INT1 :
0
1
INT1 :
1
0
INT1 :
1
1
INT1 :

1, 0 - ISC01, ISC00: INT0


INT1 INT0, I SREG
.
32.

iprito@mail.ru

2006

ATtiny2313 ()

59

INT0 . /
, , .
. ,
,
, .
32 INT0
ISC11
ISC10

0
0
INT0 :
0
1
INT0 :
1
0
INT0 :
1
1
INT0 :

GIMSK

/

7
INT1

6
INT0

5
PCIE

4
---

3
---

2
---

1
---

0
---

GIMSK

7 - INT1: INT1
INT1 , INT1 I SREG .1.
ISC11 ISC10 MCUCR ,
INT1 ( 31). INT1 , ,
INT1 . ,
.
6 INT0: INT0
INT0 , INT0 I SREG .1.
ISC01 ISC00 MCUCR ,
INT0 ( 32). INT0 , ,
INT0 . ,
.
5 - PCIE:
PCINT7..0 , PCIE ( 1), I-
(SREG) ( 1). PCINT7..0
, .
PCINT7..0 PCMSK.

iprito@mail.ru

2006

ATtiny2313 ()

60

EIFR

/

7
INTF1

6
INTF0

5
PCIF

4
---

3
---

2
---

1
---

0
---

EIFR

7 - INTF1: INT1
INT1, INTF1
1. I SREG INT1 GIMSK 1,
.
. , , .1 .
, INT1 .
6 INTF0: INT0
INT0, INTF0
1. I SREG INT0 GIMSK 1,
.
. , , .1 .
, INT0 .
5 - PCIF: PCINT7..0
PCINT7..0 ,
PCIF. I SREG PCIE
GIMSK 1,
. .
, , .1.

PCINT7..0
PCMSK

/

7
PCINT7

6
PCINT6

5
PCINT5

4
PCINT4

3
PCINT3

2
PCINT2

1
PCINT1

0
PCINT0

PCMSK

7.. 0 - PCINT7..0: PCINT7..0


PCINT7..0 . - PCINT7..0
I/O- , ,
PCIE GIMSK. - PCINT7..0 (), I/O-
.

iprito@mail.ru

2006

ATtiny2313 ()

61

8- / 0
/ 0 - 8- /0 (/ 0) , "
" "". ( )
.
:


( )



(TOV0, OCF0A, OCF0B)

- 8- / 26.
" " 2.
/, 26 /.
/0 " 8- / 0" 72.

26 - - 8- / 0

iprito@mail.ru

2006

ATtiny2313 ()

62

/0
TCNT0 /0 (/0) OCR0A OCR0B 8-.
/ TIFR. ,
/ TIMSK. TIFR TIMSK 26
.
/ ( 26)
0. ( 26)
/0 ( ) (). T/C0
, .
clkTn .
OCR0A OCR0B
/0.
- OC0A OC0B.

iprito@mail.ru

2006

ATtiny2313 ()

63

" " 63.


OCF0A OCF0B,
.

. "n"
"Timer/Counter n" /, / 0.
"x" , , "OCR0x"
OCR0B OCR0. ,
, , "TCNT0", / 0 , ,
.
, 33, .
33 -
BOTTOM

BOTTOM, TCNT0 000.


MAX, TCNT0 0FF (255
..)
TOP, TCNT0 ,
. TOP 0xFF (MAX)
OCR0A.

MAX
TOP

/ 0
/0 , .
( 26-27), , , CS02:0,
TCCR0B.
() " / 0 / 1"
79.


8- / 0
.
27 - .

TOP

BOTTOM

TOVn -

( )

()

/0

-OCn.

27 - -
26-27:
(+1) (-1) TCNT0.
- .
- , TCNT0 ( TCNT0).
clkTn - , /n, clkT0 .
TOP - , , TCNT0 .
BOTTOM - , , TCNT0
().

iprito@mail.ru

2006

ATtiny2313 ()

64

, "" , ""
"" . clkT0 ,
, CS02:0. (
CS02:0 = 0), / . TCNT0 ,
.
"" , "" "".
T/C WGM01- WGM00-
/ (TCCR0A) WGM02-,
/ B (TCCR0B). , , , /0
. ""
" " " " 93.
/ (TOV0) ,
WGM01:0. TOV0 , .


8- TCNT0 OCR0A
OCR0B. , TCNT0, - - OCR0A
OCR0B, () .
( ) OCF0A
OCF0B. ,
.
. , , ,
.
WGM02:0 COM0x1:0. TOP BOTTOM
(
" " 93).
28 - .

28 - -

iprito@mail.ru

2006

ATtiny2313 ()

65

(- )
OCR0x .
.
OCR0x TOP BOTTOM!.

, , , ( , -
).
OCR0x , .
, OCR0x, , ,
OCR0x .


non- ( , -),
, FOC0x.
OCF0x , , /
, OC0x ( COM0x1:0 ,
OC0x, ).


TCNT0
TCNT0
clkT0 , /0 . OCR0x
, TCNT0 , /0 ,
.


TCNT0
/0, TCNT0, TCNT0
, , /0 - . ,
TCNT0 OCR0x,
, .
, TCNT0 , BOTTOM, T/C0 .
OC0x ,
DDR. OC0x -
FOC0x. OC0x
. , COM0x1:0 ,
. COM0x1:0 .


COM0x1:0 . COM0x1:0
OC0x . ,
COM0x1:0 OC0x. 29 . I/O-, I/O- I/O- .
29
I/O- (DDR PORT), ,
COM0x1:0. OC0x, OC0x, OC0x.
, OC0x "0".

iprito@mail.ru

2006

ATtiny2313 ()

66

29 I/O- (DDR PORT), , COM0x1:0


/ ,
COM0x1:0 . , / OC0x
DDR. DDR (DDR_OC0x), OC0x ,
, OC0x .
, .
OC0x , OC0x
. , COM0x1:0 ,
. " 8- /
0" 72 .


(Normal, , PWM()) COM0x1:0
-. COM0x1:0=0 (: COM0x1=0 COM0x0=0)
, OC0x. ,
non- ( ), 28, 63. - (fast-PWM)
26 54, 27 54.
/
/
/


, . / ,
WGM2:0 COMx1:0. COMx1:0
/, WGM2:0. COMx1:0 ,
- - ( ). non COMx1:0 , : 1-; 2-; 3 ( " " 64).
( ), : 33, 34, 35 36
" /" 70.

iprito@mail.ru

2006

ATtiny2313 ()

67

Normal
("Normal") (
:WGM02:0 = 0). ,
. , 8- (TOP=0xFF),
(000. Normal /0 -TOV0-
, TCNT0.
TOV0 , TCNT0 (, ),
, , . , ,
TOV0, () /0
. Normal TCNT0 .
.
, - ,
.

- (
)
"" "Clear Timer on Compare", -
" ". - (
:WGM02:0 = 2) OCR0A , / .
- TCNT0 , TCNT0
, OCR0A. OCR0A
TOP-, , /0.
, .
- 30. TCNT0
, TCNT0 OCR0A,
TCNT0 .

30 - -
, TCNT0 TOP
OCF0A. ,
, TOP-. , , , TOP
BOTTOM, , -
, /0.
OCR0A , TCNT0,
/ 0 . /0
8- TCNT0 (0xFF), , (0x00)
, TCNT0 OCR0A.
-, OC0A
, TCNT0 OCR0A,
: (COM0A1:0 = 1). OC0A ,
. , ,

iprito@mail.ru

2006

ATtiny2313 ()

68

, () : fOC0 = fclk_I/O/2, ,
OCR0A (0x00). - :

f OCnx =

[f clkI / O ]
2 N (1 + OCRnx )

N , , ,
/0, : (N=1, N=8, N=64, N=256
N=1024). (Normal) /0, (-) TOV0
,
TCNT0 (MAX) (0x00).

- (FastPWM
FPWM-)
-, FPWM- (WGM02:0 = 3 7),
. FPWM- _ C. ..
BOTTOM- TOP-, BOTTOM TOP ...
TOP 0xFF, WGM2:0 = 3 TOP ,
OCR0A, WGM2:0 = 7. ,
OC0x ( ) TCNT0 OCR0x,
TCNT0 BOTTOM, OC0x . ,
, OC0x ( )
TCNT0 OCR0x, TCNT0 BOTTOM, OC0x
. PWM FPWM-, ,
, , ,
. FPWM-
, _ - ..
-
(, .), , , .
FPWM- , TCNT0
TOP. TCNT0 TOP, TCNT0
. FPWM- 29.
TCNT0 29 ( ),
( - TCNT0 ). 29,
, . (
29) TCNT0- OCR0x TCNT0.

31 - FPWM-
/ "TOV0" ,
TOP. ,

iprito@mail.ru

2006

ATtiny2313 ()

69

, () . FWPM-
- OC0x. COM0x
: COM0x1:0 = 2, .
COM0x : COM0x1:0 = 3, :
COM0x : COM0A1:0 = 1, AC0A
, , WGM02.
OC0B ( 54). ( ) ,
. ,
OC0x , .. "1" ( "0");
- "0" ( "1") ,
TOP BOTTOM.
, "" OCnx, :

f OCnx PWM =

[f clkI / O ]
N 256

N , , ,
/, : (N=1, N=8, N=64, N=256
N=1024).
OCR0A
-. OCR0A BOTTOM,
MAX:
MAX+1; OCR0A , MAX,
- ( ,
COM0A1:0).
- FPWM- 50% (
) OC0x
(COM0x1:0 = 1). , ,
, () : fOC0 = fclk_I/O/2, , OCR0A
(0x00). -,
OC0A, , FPWM-
, - - .

(PCPWM-)
PCPWM- (WGM02:0 = 1 5)
- . PCPWM- .
BOTTOM TOP, ,
TOP BOTTOM. TOP 0xFF, WGM2:0 = 1, , WGM2:0
= 5, TOP , OCR0A.
, OC0x "0"
TCNT0 OCR0x , , OC0x
"1" TCNT0 OCR0x .
.
, . , -
, .
PCPWM- () , TCNT0
TOP. TOP . ,
TCNT0 TOP . PCPWM-
32. TCNT0 32
(), . 32, ,
OCn .

OCR0x TCNT0.

iprito@mail.ru

2006

ATtiny2313 ()

70

32 - OCn
(PCPWM-)
(TOV0) / ,
BOTTOM. , .
PCPWM- - , ,
OC0x. : COM0x1:0 = 2,
. , : COM0x1:0 = 3, ""
COM0A0 OC0A ,
, , WGM02. OC0B -.
OC0x , . - OC0x
"0" ( "1" ) ,
OCR0x TCNT0 ( OCR0x - , TCNT0 - ,
OCR0x)
; "1" ( "0" ),
OCR0x TCNT0 .
PCPWM- :

f OCnx PCPWM =

[f clkI / O ]
N 510

N , , ,
/, : (N=1, N=8, N=64, N=256
N=1024).
(.., ) OCR0A
- PCPWM-. OCR0A
BOTTOM, , , OCR0A=TOP,
- .
.
2- , 32, OCn
, .
. ,
.
OCR0A MAX, 32.
OCR0A=_TOP(MAX)_, OCn ,
, "1" -
"0"- .

iprito@mail.ru

2006

ATtiny2313 ()

71

- , OCn, TCNTn=MAX,
,
.
, , OCR0A (..
OCR0A+1) , (, TCNT0 OCR0A ) ,
, OCn ( 32
1 ).

/
/n , clkTO, ,
. , , , .
33 , . ,
MAX, -, PCPWM-..

33 - / ( )
34 , 33, (fclkI/O/8)

34 / (fclkI/O/8)
35 OCF0B OCF0A (
) -, - -, OCR0A
TOP-.

35 - / OCF0x
(fclkI/O/8)

iprito@mail.ru

2006

ATtiny2313 ()

72

36 OCF0A TCNT0 - FPWM-,


OCR0A TOP-.

36 - /
(fclkI/O/8)

iprito@mail.ru

2006

ATtiny2313 ()

73

8- / 0
/ 0 TCCR0A

/

7
COM0A1

6
COM0A2

5
COM0B1

4
COM0B0

3
---

2
---

1
WGM01

0
WGM00

TCCR0A

7:6 - COM0A1:0:
OC0A. COM0A1:0 ( ),
OC0A /. , , ,
DDR , ,
.
OC0A , ,
COM0A1:0, WGM02:0. 34 ,
COM0A1:0 WGM02:0 (Normal-)
- ( non-PWM - - /).
34 non-PWM (non-)
COM0A1
COMA0

0
0
/, () OC0A
() OC0A
0
1

( 0) OC0A
1
0

( 1) OC0A
1
1

35 FPWM-
COM0A1
COMA0

0
0
/, () OC0A
WGM02 = 0: OC0A ( PB2
OC0A, PB2, ).
0
1
WGM02 = 1: () OC0A
.
( 0) OC0A
1
0
, TCNT0
TOP.
( 1) OC0A
1
1
, TCNT0
TOP.

:
1. , OCR0A TOP
COM0A1. ( ), OC0A
- ( ,
COM0A1:0). 67 (. ).

iprito@mail.ru

2006

ATtiny2313 ()

74

36 COM0A 1:0, WGM0 2:0


PCPWM.
36
PCPWM.(1).
COM0A1
COMA0

0
0
, OC0A .
WGM02 = 0: , OC0A .
0
1
WGM02 = 1: OC0A
.
OC0A .
1
0
OC0A 1
.
1
1
:
1. , OCR0A TOP COM0A1.
.
(PCPWM-) . 68.

iprito@mail.ru

2006

ATtiny2313 ()

75

USART

(
);
2. ;
3. Master- Slave- ;
4. () ;
5. : 5- , 6- , 7- , 8- 9- 1 2 ;
6. , (-);
7. ;
8. ;
9. , ()
;
10. , ,
;
11. ;
12. ;
1.

- USART 52.
/ - .

52 - - USART (1)
: 1. USART,
1 2, - 29 56, - 26 54.

iprito@mail.ru

2006

ATtiny2313 ()

76

- USART (
): , . .
,
(the baud rate generator). XCK
( ) .
, ,
.
.
USART, .
.
, (UDR)
. , ,
.

AVR USART AVR UART


USART UART :
1. USART;
2. ;
3. ;
4. ;
5. ;
, ,
:
1. . , FIFO. , UDR .
: , (FE - Frame Error DOR);
(RXB8), . , ,
UDR, . ,
.
2. .
( 52),
, . ,
USART (DOR - Data OverRun).
, , -,
, :
CHR9 UCSZ2.
OR
DOR.


. USART 4
. UMSEL UCSRC USART
.
( ) U2X, UCSRA.
(UMSEL=1), DDRx XCK (DDR_XCK)
, , , Master-
Slave-.
53 - .

iprito@mail.ru

2006

ATtiny2313 ()

77

53 - - USART

1.
2.
3.
4.
5.

:
txclk ( );
rxclk ( );
xcki XCK ( ). Slave.
xcko XCK. Mastre.
fosc XTAL- ( ).

Master.
53. UBRR
, .
(fosc), UBRR,
UBRRL.
, .
: (output =fosc/(UBRR+1)). output
2, 8 16 . output
. _ . 48
() , UBRR ,
.

iprito@mail.ru

2006

ATtiny2313 ()

78

48 - UBRR


UBRR

(U2X = 0)

(U2X = 1)
Master-
BAUD - ,
, 1 =8 /;
;
fOSC
UBRR , UBRRH UBRRL,
, UBRR 12- (0-4095).
UBRR 56 ( 133).

(U2X)
U2X UCSRA.
USART. ,
USART.
16 8, ,
USART. , ,
( 16 8 )
, , ,
. _.


Slave- .
53. XCK
. ,
.
, , , ,
XCK, :

: fosc .
, .

iprito@mail.ru

2006

ATtiny2313 ()

79


(UMSEL=1) XCK (Slave-)
(Master-). , (
RxD) ( ) XCK
, TxD:

54
UCPOL UCRSC , XCK
. 54 , , UCPOL = 0,
XCK, XCK.
UCPOL=1, XCK,
.


,
( ) . USART
:
1 - ;
5,6,7,8 9 ;
() ;
1 2 ;
, .
, . ,
() , , .
,
, , ,
. 55 .
( ).

55

St ( . );
(n) ( 0 8);
P ();
FRAME ;

iprito@mail.ru

2006

ATtiny2313 ()

80

Sp ( . );
IDLE (RxD TxD).

USART UCSZ2:0, UPM1:0 USBS UCSRB


UCSRC. . ,
USART , ,
.
SIZe (UCSZ2:0) . UPM1:0
.
USBS. . FE (Frame Error )
, .

()
. (Odd),
. ()
:

Peven ;
Podd ;
dn ;

() ,
.

USART ( )
USART ,
. ,
/ . USART
. , ,
, . TXC
, , . RXC
, , . ,
TXC ( UDR),
, .

iprito@mail.ru

2006

ATtiny2313 ()

81

USART , . USART
( ) .
.
R17 R16.

: 1. , . _.

/ .. , ,
USART
I/O-.

iprito@mail.ru

2006

ATtiny2313 ()

82

USART
USART TXEN UCSRB. ,
, TxD, ,
USART. ,
, . ,
XCK ,
.

5 8
,
.
UDR. ,
. ,
(Idle)
. ,
, () UBRR, U2X
XCK, .

UDRE. , 8 ,
, , . USART
. ,
R16.

: 1. , . _.
, UDRE,
. UDR ,
UDRE () UDR.

iprito@mail.ru

2006

ATtiny2313 ()

83

9
9- (UCSZ = 7), 9 TXB8
UCSRB , UDR.
9- . ,
R17:R16.

1. , UCSRB
. , TXB8
UCSRB.
2. , . _.


, , .

iprito@mail.ru

2006

ATtiny2313 ()

84


USART : UDRE ,
UDRE , TXC , .
.
UDRE , .
, , ,
, .
() UCSRA.
UDRIE UCSRB
UDR, , (
). UDRE UDR.
() UDR , UDRE
,
.
TXC 1, ,
UDR . TXC ,
, , . TXC
( , RS-485),
.
\
UCSRB TXCIE,
TXC (
). ,
TXC, .

()

( ) .
UPM=1,
, .

()
( TXEN ) , ,
. _ . ,
() TxD.

iprito@mail.ru

2006

ATtiny2313 ()

85

USART
USART RXEN ,
UCSRB. () RxD
USART . ,
, .
, XCK
.

5 8
, .
, , () ,
XCK, ,
. .
,
. UDR.
USART,
RXC, , , .
, 8 , UDR .
USART , .

: 1. , . _.
() , ,
RXC. , 1, UDR
.

iprito@mail.ru

2006

ATtiny2313 ()

86

9
9 ( UCSZ 7),
9 RXB8, UCSRB.
, UDR.
-, : FE, DOR UPE. UCSRA. , ,
UDR. UDR FIFO , , - TXB8,
FE, DOR, UPE, FIFO.
USART,
9- .

: 1. , . _.

iprito@mail.ru

2006

ATtiny2313 ()

87


USART , ,
RXC. . RXC .
() ,
, (.. ).
(RXEN = 0) , , RXC .
, .., RXCIE UCSRB,
, RXC (
). ,
() UDR ,
RXC, , ,
, .


USART : FE ,
DOR , UPE ().
UCSRA.
, , , . ,
, UDR, . UDR
. . ,
UCSRA,
USART. .
FE , ,
. FE , ( )
FE , .
,
, . FE USBS ( UCSRC) ,
, .
, UCSRA USBS .

DOR . DOR
( ),
. DOR , ,

. (),
UCSRA. DOR ,
.
UPE (-) , ,
, . , UPE . ,
UPE UCSRA.
() 115 -
123.

iprito@mail.ru

2006

ATtiny2313 ()

88

Оценить