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

chop ④ : AVR I/o port programming

called
tv

Inputs / outputs pins are


ports Do -
-
co

Cl
Bl
-
-

i
i
have PORTB PORTC Po RTD
.

at
we
PORTA on
-
-

, .

, ,
-

Do

Some AVR models does not have olltte ports i


-
D 7

BG B 4
PORT B : B7 BS BS BL BI Bo

other ports
some
for the
, every port is 8 biforate )

To write to the
pins we use Porta ( .bg
? )
§
F.
To read
from 11 it
'
I 4 PINK

To define o -
pin as I or O we use DD Rsc

In DDR x
to
-
bit bribe
I
:

,Yp
con ending
Yin
÷ input
output
: ,

E L DI RIG ,
ox e3

OUT DD RC ,
R " Outputs
76 s 4 32 to

DDRC XC 3 I I 00 00 I I
⇒ = o =

CG and Ct
⇒ Fo ,
c
, ,
are

and L2 ,C3 ,
CG and CS are
inputs
ee : Define Port D as output then toggle ②

it
forever .

Sod LDI RIG ,


OX FF DDRD -

-
1111 1111

ly ⇒ old
pins of
OUT DDRD RIG
,
port bone outputs

loop RIG

}
0
i
LDI ,
PORT D= oooo oooo

OUT Po RTD ,
Rig

)
L DI RIG ,
OXFF
port D= 1111 1111

out PORT D ,
Rtb

amp loop

E Define Bo
, Bg ,
Be , and Bt as
input
and the other pins of PORTB as outputs
3 2 I
7 6 S 4 o

Sold L d d L d L d L

DDRB :
o I I O 0 I I °

=
OX 66

⇒ The Solution is :

L DI RIG ,
O X 66

OUT DDRB ,
R 16
I/o Bit Manipulation ③

SBI : Set Bit in I/o Register

SBI K
iorey ,

bit nb.hr in I onol


Reg
io

=

don't change the other bit

C BI :
Cleon Bit in I/o Register

C BI io
Reg ,
K

bit nb.hr in and


io
Rey
= o

don't change the other bit

the
ED Trace
following assembly program

AT
LD I R 16 ,
OX FF Solt ① RIG -

- OXFF

DUT DDRC ,
RIG ② DDRC -

- OXFF ⇒ all
pins of core output
LD I RIG OX At
, ③ Rib = ox

Po R 16 Porte XA 't
RTC ④
o
OUT
-

,
1010 0 111
Po
=

S BI RTC 4
,

Porte

=

C B I Porte ,
7
I O I I O I I I

C BE Po RTC ,
5 ⑥ o o I I 0111

RTC
S BE Po , 3
⑦ ooo I 0 111

⑧ 00 O I I I I I

⇒ Po RTC = ox IF
Crete
ED o -

square
wove on CL .

Suppose ④
we
have a subroutine called oblong
-

.
all it

between
every toggle

soy
in bit 2=1
C 2 : output ⇒
DDRC

wave ⇒ Cz 51-17-17 - . .

square
: ,

S B I DD Re ,
2 ← cos : output
B I Po RTC 2 L2 o
again : C , ←
=

CALL
delay
S BI Po RTC 2 cod = I
, ←

CALL delay
ymp again
checking on
input pin ( Rooting ) ⑤
S BI S .
.

Skip meet instruction if


B it in I/o is Set

SB IS
Ioneg ,
hi

⇒ Skip meet instructor if bit

mb.hr in Io is I
neg
=

S BIC :
Skip meet instructor if
B it in I/o is Clear

SB Ic Io h
-
neg ,


skip
nut instruction if the

bit nb.hr in Io 5=0


rag

E CBI DDR B ,
3 → B. 3 is
input
LD I Rib O R 16=0
, →

SB IS PINB , 3 → if B 3=1 Skip


-

LD I RIG , I -

Mov RIO ,
Rib

RIO
if
o
⇒ B 3=1 ⇒ =

RIO =L
if B3=o ⇒
until
Ee keep monitoring B2 it bacon

when high write


High .
B 2 is ⇒

42 in
ox
PORT C

bit
Soy BE input ⇒ 2 in DPRB o
-

we will write in Porte ⇒ Porte output ⇒

1111 = OX FF
DDR c =
1111

CBI DDRB ,
2 → B2 input

,ox42jII
OXFF
}
LDI R 16 ,
Porte output
OUT DDRC ,
rig

again : SB IS PEN B
,
2

executed if B2=o
Jmp again →

< be Rib : her

OUT Porte RIG B 2=1


,
connectedswitch

Ey A is to BS

if switch
'
send to Po
'
o ⇒ N RTD
(
=

switch I
'
to Po
'

it
y RTD
-

-

soy we need to red the Wlne of BS

⇒ BS input bits in DDRB o


-

⇒ -

'
we need Ee write '
N
'
or
'

y to Po RTD

⇒ D is output ⇒ DDRD =oxFF


'

go
Sdsu
④ CBI DDRB
,
5 CBI DDRB
RIB
,

OXFF
5

LDI
< DI Rib ,
OXFF ,

OUT DDRD RIG


OUT DDRD , R 16 ,

-8in : SBIC PIND 5


again PINA
,
SBIS ,

No
grip yes
jmp I
'

I
' LDI RIG ,
W
LDI Rib , y
OUT PORTD , Rif
OUT PORTD Rtb
,

Jmp again zmp again


' '
' '
Yes : LDI RIG ,
Y
No :
LDI Rib ,
N

OUT PORTA RIG


,
OUT PORTD ,
RI 6

jmp again Jmp again