PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 05, 2006 3:03 pm |
|
|
One way to do it, is to create two separate driver files.
Each file has the same functions in it, but with "ch_0"
and "ch_1" added onto the end of each function name,
to designate that one driver is for the "channel 1"
TDA7318 chip, and the other driver is for the 2nd TDA7318
chip, which is on "channel 2".
In the program below, all of the code in the TDA7318_0.C file
will be compiled for i2c on pins B0 and B1. After that, a new
#use i2c statement is placed, which uses pins B2 and B3.
So all of the code in the 2nd driver file will be compiled to
use those pins.
Then notice in the main() program, each TDA7318 chip
has its own functions, which have either "ch_0" or "ch_1"
at the end of the function name. These functions are
in the TDA7318_0.C and TDA7318_1.C files. You have
to write these functions.
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use i2c(Master, SDA=PIN_B0, SCL=PIN_B1)
#include "TDA7318_0.C"
#use i2c(Master, SDA=PIN_B2, SCL=PIN_B3)
#include "TDA7318_1.C"
//============================
void main()
{
init_TDA7318_ch_0(); // init channel 0
init_TDA7318_ch_1(); // init channel 1
set_TDA7318_volume_ch_0(0, 0); // Set A, B volume on Ch. 0
set_TDA7318_volume_ch_1(0, 0); // Set A, B Volume on Ch. 1
while(1)
} |
|
|