mega8, TWI, ASM:
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено Леонид Иванович 20 октября 2004 г. 19:42
В ответ на: Кстати. Посмотрел. У меня почти те же самые функции, только на асме. Меня больше интересовала инициализация TWI. отправлено Grapaf 20 октября 2004 г. 14:30

Инициализация:

	
ldi temp,50
out TWBR,temp ;set I2C speed
ldi temp,0
out TWSR,temp

;Write data to the RTC:
;Input: YL - address, temp - data

Wr_RTC: push temp
ldi temp,(1< out TWCR,temp ;start
rcall TWI_Wait

ldi temp,I2C_Addr ;I2C slave address (write)
out TWDR,temp
ldi temp,(1< out TWCR,temp
rcall TWI_Wait

mov temp,YL ;subaddress
out TWDR,temp
ldi temp,(1< out TWCR,temp
rcall TWI_Wait

pop temp ;data
out TWDR,temp
ldi temp,(1< out TWCR,temp
rcall TWI_Wait

ldi temp,(1< out TWCR,temp ;stop
ret

;Read data from the RTC:
;Input: YL - address
;Out: temp - data

Rd_RTC: ldi temp,(1< out TWCR,temp ;start
rcall TWI_Wait

ldi temp,I2C_Addr ;I2C slave address (write)
out TWDR,temp
ldi temp,(1< out TWCR,temp
rcall TWI_Wait

mov temp,YL ;subaddress
out TWDR,temp
ldi temp,(1< out TWCR,temp
rcall TWI_Wait

ldi temp,(1< out TWCR,temp ;stop

;read:

ldi temp,(1< out TWCR,temp ;start
rcall TWI_Wait

ldi temp,I2C_Addr+1 ;I2C slave address (read)
out TWDR,temp
ldi temp,(1< out TWCR,temp
rcall TWI_Wait

ldi temp,(1< out TWCR,temp ;read data and send NACK
rcall TWI_Wait

in temp,TWDR ;data
push temp

ldi temp,(1< out TWCR,temp ;stop

pop temp
ret

;Wait for I2C operation complete:

TWI_Wait:
in temp,TWCR
bbrc temp,TWINT,TWI_Wait
ret



Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru