electronicfox
16.10.2005, 12:05
Frage zu einem Code:
.NOLIST
.INCLUDE "tn26def.inc"
.INCLUDE "i2c.inc"
.LIST
; Verwendete Register
.def LAUTSTL=r16
.def LAUTSTR=r17
.def BAESSE=r18
.def HOEHEN=r19
.def EINGANG=r20
; Anschluesse
.equ TDA8421 = 0b10000000 ; Adresse
.equ i2c_delay = 50 ; wait 4.75 us at 4 MHz 25
.equ i2c_port = PORTB ; port supporting i2c
.equ i2c_pins = PINB ; port pins supporting i2c
.equ i2c_ddr = DDRB ; data direction register for port
.equ sda = 0 ; bit within port for serial data in
.equ scl = 1 ; bit within port for serial data out
; Starteinstellungen
Start:
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00000000 ; Lautstärke-L
rcall i2c_write ; Write Word address
mov i2c_buffer,LAUTSTL ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00000001 ; Lautstärke-R
rcall i2c_write ; Write Word address
mov i2c_buffer,LAUTSTL ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00000010 ; Bässe
rcall i2c_write ; Write Word address
mov i2c_buffer,BAESSE ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00000011 ; Lautstärke-L
rcall i2c_write ; Write Word address
mov i2c_buffer,HOEHEN ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00001100 ; Schalteingang
rcall i2c_write ; Write Word address
mov i2c_buffer,EINGANG ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
[...]
Jetzt möchte ich gerne die Analogwerte zu den jeweiligen Register schieben. Nur wie macht man das am einfachsten beim AVR
.NOLIST
.INCLUDE "tn26def.inc"
.INCLUDE "i2c.inc"
.LIST
; Verwendete Register
.def LAUTSTL=r16
.def LAUTSTR=r17
.def BAESSE=r18
.def HOEHEN=r19
.def EINGANG=r20
; Anschluesse
.equ TDA8421 = 0b10000000 ; Adresse
.equ i2c_delay = 50 ; wait 4.75 us at 4 MHz 25
.equ i2c_port = PORTB ; port supporting i2c
.equ i2c_pins = PINB ; port pins supporting i2c
.equ i2c_ddr = DDRB ; data direction register for port
.equ sda = 0 ; bit within port for serial data in
.equ scl = 1 ; bit within port for serial data out
; Starteinstellungen
Start:
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00000000 ; Lautstärke-L
rcall i2c_write ; Write Word address
mov i2c_buffer,LAUTSTL ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00000001 ; Lautstärke-R
rcall i2c_write ; Write Word address
mov i2c_buffer,LAUTSTL ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00000010 ; Bässe
rcall i2c_write ; Write Word address
mov i2c_buffer,BAESSE ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00000011 ; Lautstärke-L
rcall i2c_write ; Write Word address
mov i2c_buffer,HOEHEN ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
rcall i2c_setup
rcall i2c_start ; I2C Start Condition
ldi i2c_buffer,TDA8421 ; 1. Modul Adresse
rcall i2c_write ; Write Slave address
ldi i2c_buffer,0b00001100 ; Schalteingang
rcall i2c_write ; Write Word address
mov i2c_buffer,EINGANG ; Stand
rcall i2c_write ; Write Word address
rcall i2c_stop
;-----------------------------------------------------------------------------------
[...]
Jetzt möchte ich gerne die Analogwerte zu den jeweiligen Register schieben. Nur wie macht man das am einfachsten beim AVR