|
Инициализация:
ldi temp,50
out TWBR,temp ;set I2C speed
ldi temp,0
out TWSR,temp;Write data to the RTC:
;Input: YL - address, temp - dataWr_RTC: push temp
ldi temp,(1<out TWCR,temp ;start
rcall TWI_Waitldi temp,I2C_Addr ;I2C slave address (write)
out TWDR,temp
ldi temp,(1<out TWCR,temp
rcall TWI_Waitmov temp,YL ;subaddress
out TWDR,temp
ldi temp,(1<out TWCR,temp
rcall TWI_Waitpop temp ;data
out TWDR,temp
ldi temp,(1<out TWCR,temp
rcall TWI_Waitldi temp,(1<
out TWCR,temp ;stop
ret;Read data from the RTC:
;Input: YL - address
;Out: temp - dataRd_RTC: ldi temp,(1<
out TWCR,temp ;start
rcall TWI_Waitldi temp,I2C_Addr ;I2C slave address (write)
out TWDR,temp
ldi temp,(1<out TWCR,temp
rcall TWI_Waitmov temp,YL ;subaddress
out TWDR,temp
ldi temp,(1<out TWCR,temp
rcall TWI_Waitldi temp,(1<
out TWCR,temp ;stop ;read:
ldi temp,(1<
out TWCR,temp ;start
rcall TWI_Waitldi temp,I2C_Addr+1 ;I2C slave address (read)
out TWDR,temp
ldi temp,(1<out TWCR,temp
rcall TWI_Waitldi temp,(1<
out TWCR,temp ;read data and send NACK
rcall TWI_Waitin temp,TWDR ;data
push templdi 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