atmega163l ATMEL Corporation, atmega163l Datasheet - Page 93

no-image

atmega163l

Manufacturer Part Number
atmega163l
Description
Atmega163 8-bit Avr Microcontroller With 16k Bytes Of In-system Programmable Flash
Manufacturer
ATMEL Corporation
Datasheet

Available stocks

Company
Part Number
Manufacturer
Quantity
Price
Part Number:
atmega163l-4AI
Manufacturer:
ATMEL
Quantity:
984
Assembly Code Example –
Master Receiver Mode
1142E–AVR–02/03
;Part specific include file and TWI include file must be included.
; <Initialize registers TWAR and TWBR>
wait5:in
wait6:in
wait7:in
wait8:in
;<Receive more data bytes if needed>
;receive next to last data byte.
ldi
out
sbrs
rjmp
in
cpi
brne
ldi
out
ldi
out
sbrs
rjmp
in
cpi
brne
ldi
out
sbrs
rjmp
in
cpi
brne
in
nop
ldi
out
r16,TWCR
r16, (1<<TWINT) | (1<<TWSTA) | (1<<TWEN)
TWCR, r16
r16,TWCR
r16, TWINT
wait5
r16, TWSR
r16, START
ERROR
r16, 0xc9
TWDR, r16
r16, (1<<TWINT) | (1<<TWEN)
TWCR, r16
r16, TWINT
wait6
r16, TWSR
r16, MR_SLA_ACK; different from MR_SLA_ACK, go to ERROR
ERROR
r16, (1<<TWINT) | (1<<TWEA) | (1<<TWEN)
TWCR, r16
r16,TWCR
r16, TWINT
wait7
r16, TWSR
r16, MR_DATA_ACK ; different from MR_DATA_ACK, go to ERROR
ERROR
r16, TWDR
r16, (1<<TWINT) | (1<<TWEA) | (1<<TWEN)
TWCR, r16
r16,TWCR
;Send START condition
; Wait for TWINT flag set. This indicates that
; the START condition has been transmitted
; Check value of TWI Status Register. If status
; different from START, go to ERROR
; Load SLA+R into TWDR Register
; Clear TWINT bit in TWCR to start transmission of
; SLA+R
; Wait for TWINT flag set. This indicates that
; SLA+R has been transmitted, and ACK/NACK has
; been received
; Check value of TWI Status Register. If status
; Clear TWINT bit in TWCR to start reception of
; data.
; Setting TWEA causes ACK to be returned after
; reception of data byte
; Wait for TWINT flag set. This indicates that
; data has been received and ACK returned
; Check value of TWI Status Register. If status
; Input received data from TWDR.
;<do something with received data>
; Clear TWINT bit in TWCR to start reception of
; data. Setting TWEA causes ACK to be returned
; after reception of data byte
; Wait for TWINT flag set. This indicates that
ATmega163(L)
93

Related parts for atmega163l