You are on page 1of 10

I/O Ports and bit addressability

•Used to work with bits of I/O register


•32 I/O registers are available with AVR controllers
•Used when only 1 bit is to be accessed
•Ports pins are defined as PX0 to PX7 where X= A,B,C,D
•Address ranges from data memory $20 to $3F and I/O memory
$00 to $1F
Single bit instructions for AVR

SBI ioReg,bit
CBI ioReg,bit
SBIC ioReg,bit ; skip If bit in I/O register is cleared
SBIS ioReg,bit ; skip If bit in I/O register is set
SBI ioReg,bit

Used to set a given bit of an I/O register

Syntax:
SBI ioReg, bit_num ; ioReg is lower 32bit I/O register
; bit_num from 0 to 7

e.g.
SBI PORTB,5 ; It sets bit 5 of port B

CBI ioReg,bit
Write a program to turn ON 8 LED’s connected on Port D in lower to upper manner
And turn them OFF in the upper to lower manner with delay between each ON-OFF.
LDI R20,$0FF
OUT DDRD, R20
OUT PORTD,R20
SBI PORTD,0
CALL Delay
SBI PORTD,1
CALL Delay
.
.
.
.
.
CBI PORTD,7
CALL Delay
CBI PORTD,6
CALL Delay
Write a program to generate square wave of 50 % duty cycle on bit 0 of
Port C and 66% duty cycle on bit 3 of Port C
SBI DDRC,0
Again: SBI PORTC,0
CALL DELAY
CBI PORTC,0
CALL DELAY
JMP again

DELAY: 100ms loop


Checking an input pin

•Used to make a decision based on status of given bit.


•It can be used for any bits of lower 32 I/O registers
•If the condition is satisfied or not, decisions are taken off.
•The immediate instruction is skipped if condition is satisfied.

SBIS (skip if bit in I/O register set)


SBIC (skip if bit in I/O register reset)
Write a program to monitor status of bit 2 of Port D and if it becomes
High send value $45 to PORTC

CBI DDRD,2
LDI R16,$FF
OUT DDRC, R16
again: SBIS PIND, 2
JMP again
LDI R17, $45
OUT PORTC,R17
JMP again

You might also like