Rainbow-electronics ATmega163L Uživatelský manuál Strana 80

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 156
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 79
ATmega163(L)
80
wait6: in r16,TWCR ; Wait for TWINT flag set. This indicates that
sbrs r16, TWINT ; SLA+R has been transmitted, and ACK/NACK has
rjmp wait6 ; been received
in r16, TWSR ; Check value of TWI Status Register. If status
cpi r16, MR_SLA_ACK ; different from MR_SLA_ACK, go to ERROR
brne ERROR
ldi r16, (1<<TWINT) | (1<<TWEA) | (1<<TWEN)
out TWCR, r16 ; Clear TWINT bit in TWCR to start reception of data.
; Setting TWEA causes ACK to be
; returned after reception of data byte
wait7: in r16,TWCR ; Wait for TWINT flag set. This indicates that
sbrs r16, TWINT ; data has been received and ACK returned
rjmp wait7
in r16, TWSR ; Check value of TWI Status Register. If status
cpi r16, MR_DATA_ACK ; different from MR_DATA_ACK, go to ERROR
brne ERROR
in r16, TWDR ; Input received data from TWDR.
nop ;<do something with received data>
ldi r16, (1<<TWINT) | (1<<TWEA) | (1<<TWEN)
out TWCR, r16 ; Clear TWINT bit in TWCR to start reception
; of data. Setting TWEA causes ACK to be
; returned after reception of data byte
;<Receive more data bytes if needed>
;receive next to last data byte.
wait8: in r16,TWCR ; Wait for TWINT flag set. This indicates that
sbrs r16, TWINT ; data has been received and ACK returned
rjmp wait8
in r16, TWSR ; Check value of TWI Status Register. If status
cpi r16, MR_DATA_ACK ; different from MR_DATA_ACK, go to ERROR
brne ERROR
in r16, TWDR ; Input received data from TWDR.
nop ;<do something with received data>
ldi r16, (1<<TWINT) | (1<<TWEN)
out TWCR, r16 ; Clear TWINT bit in TWCR to start reception of data.
; Not setting TWEA causes NACK to be
; returned after reception of next data byte
; receive last data byte. Signal this to slave by returning NACK
wait9: in r16,TWCR ; Wait for TWINT flag set. This indicates that
sbrs r16, TWINT ; data has been received and NACK returned
rjmp wait9
in r16, TWSR ; Check value of TWI Status Register. If status
cpi r16, MR_DATA_NACK ; different from MR_DATA_NACK, go to ERROR
Zobrazit stránku 79
1 2 ... 75 76 77 78 79 80 81 82 83 84 85 ... 155 156

Komentáře k této Příručce

Žádné komentáře