0% found this document useful (0 votes)
71 views10 pages

I/O Ports and Bit Addressability

- I/O ports allow access and control of individual bits using instructions like SBI, CBI, SBIS, and SBIC. The AVR has 32 8-bit I/O registers labeled PORTA-PORTD that each control 8 pins. - SBI sets a specific bit in an I/O register. CBI clears a bit. SBIS and SBIC skip the next instruction if a bit is set or cleared respectively. - Example programs are provided to blink LEDs on PORTD, generate square waves of different duty cycles on PORTC bits, and monitor a bit on PORTD and output a value to PORTC if the bit goes high.

Uploaded by

Priyancy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views10 pages

I/O Ports and Bit Addressability

- I/O ports allow access and control of individual bits using instructions like SBI, CBI, SBIS, and SBIC. The AVR has 32 8-bit I/O registers labeled PORTA-PORTD that each control 8 pins. - SBI sets a specific bit in an I/O register. CBI clears a bit. SBIS and SBIC skip the next instruction if a bit is set or cleared respectively. - Example programs are provided to blink LEDs on PORTD, generate square waves of different duty cycles on PORTC bits, and monitor a bit on PORTD and output a value to PORTC if the bit goes high.

Uploaded by

Priyancy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy