
60
ATmega8515(L)
2512A–AVR–04/02
The following codeexample shows how to set port Bpins 0and 1 high, 2and3low, and
define the port pinsfrom 4 to 7 as input withpull-ups assigned to port pins6and7.The
resulting pin values are readback again,but aspreviously discussed, a
nop
instruction
is included to beabletoreadback thevalue recently assigned to some of the pins.
Note: 1. For theassembly program, twotemporary registers areused to minimizethetime
from pull-ups are set on pins 0, 1,6,and7,until the direction bits are correctly set,
defining bit 2 and3aslow andredefining bits 0and 1asstrong highdrivers.
Digital Input Enable and Sleep
Modes
AsshowninFigure29, the digital input signalcan be clamped to ground at theinput of
the schmitt-trigger.The signaldenotedSLEEPinthe figure, isset by the MCU Sleep
Controller in Power-downmodeandStandby modetoavoidhighpowerconsumption if
some input signals are left floating, orhave an analog signallevelclosetoV
CC
/2.
SLEEPis overridden forport pins enabled asExternalInterrupt pins. If the External
InterruptRequestis not enabled, SLEEPis active also for these pins. SLEEPis also
overridden by various other alternate functions asdescribed in “Alternate Port Func-
tions”onpage 61.
If a logichighlevel(“one”) ispresent on an AsynchronousExternalInterrupt pin config-
ured as “InterruptonAnyLogicChange on Pin” whiletheexternal interruptis
not
enabled, the corresponding ExternalInterrupt Flag will be set when resuming from the
above mentionedsleep modes, as the clamping in these sleep modesproduces the
requestedlogicchange.
Assembly Code Example
(1)
...
;
Define pull-ups and set outputs high
;
Define directions for port pins
ldi r16,(1<<PB7)|(1<<PB6)|(1<<PB1)|(1<<PB0)
ldi r17,(1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0)
out PORTB,r16
out DDRB,r17
;
Insert nop for synchronization
nop
;
Read port pins
in r16,PINB
...
CCode Example
unsigned char i;
...
/*
Define pull-ups and set outputs high
*/
/*
Define directions for port pins
*/
PORTB = (1<<PB7)|(1<<PB6)|(1<<PB1)|(1<<PB0);
DDRB = (1<<DDB3)|(1<<DDB2)|(1<<DDB1)|(1<<DDB0);
/*
Insert nop for synchronization
*/
_NOP();
/*
Read port pins
*/
i = PINB;
...
Komentáře k této Příručce