Hallo,
anbei noch eine 8-Kanalversion für Prozessoren wie den ATTINY45. Der Aufruf eines der möglichen Kanäle erfolgt BCD-codiert über die Eingänge PB2-PB4. ( alle Eingänge offen: Kanal 7 ; alle Eingänge an Masse: Kanal 0.
Die am Ende des Programmlistings aufgeführten Frequenzen sind entsprechend der jeweils gewünschten eigenen Frequenzen abzuändern.
Klaus
'------------------------------------------------------------------
' NS73M_BWN_TY45_2.BAS 49% belegt Achtkanalversion
'
' Original written by: Dave Brown; erweitert auf 8 Kanalauswahl und Frequenz-Direkteingabe by KHH
'
' Sets up NS73M module to transmit in stereo
' 50 us pre-emphasis
' 0.5 milliwatts transmit power
' 200 millivolts audio input for 100% modulation.
'
' Compiler: BASCOM-AVR IDE
' Processor: ATTINY45
'
$regfile = "attiny45.dat" 'ATTINY45 processor
$crystal = 1000000 'Internal RC osc. fuse set to 1 megahertz
'
'NS73M read and write address
Const Fmtxwr = &B11001100 'Address and Write to FM Tx Module
Const Fmtxrd = &B11001101 'Address and Read from FM Tx Module
Dim N As Word
Dim H As Byte
Dim L As Byte
Dim Cex As Byte
Dim Frq As Single
Dim Outfrq As Single
'Configure I2C pins
Config Scl = Portb.0 'Is serial clock SCL pin 5
Config Sda = Portb.1 'Is serial data SDA pin 6
I2cinit
'hole Schalterstellung S1-S3
Config Portb.2 = Input
Config Portb.3 = Input
Config Portb.4 = Input
Portb = &B00011100 'Pullups s1...,s3
Declare Sub Read_switch()
'hole Frequenz gem. Schalterstellung S1-S3 aus Subroutine
'--------------------------------------------------------
Gosub Read_switch
Frq = Outfrq + 0.304
Frq = Frq / 0.008192
N = Int(frq)
H = High(n)
L = Low(n)
' 87.50 - 91.72 : CEX= &H1B
' 88.74 - 98.28 : CEX= &H1A
' 93.10 - 104.0 : CEX= &H19
' 99.50 - 107.9 : CEX= &H18
' Set up Bands based on the following ranges:
If Outfrq < 90 Then Cex = &H1B
If Outfrq => 90 And Outfrq < 95 Then Cex = &H1A
If Outfrq => 95 And Outfrq < 101 Then Cex = &H19
If Outfrq => 101 Then Cex = &H18
Waitms 100 'Wait for NS73M power up
I2cstart 'I2C Start
I2cwbyte Fmtxwr 'I2C FMTx Slave Addr Write
I2cwbyte &H0E 'Register E
I2cwbyte &H05 'Software reset
I2cstop 'I2C Stop
Waitms 1 'Wait for it to process
'
I2cstart 'I2C Start
I2cwbyte Fmtxwr 'I2C FMTx Slave Addr Write
I2cwbyte &H01 'Register 1
I2cwbyte &HB4 'Pilot on, forced subcarrier
I2cstop 'I2C Stop
Waitms 1 'Wait for it to process
'
I2cstart 'I2C Start
I2cwbyte Fmtxwr 'I2C FMTx Slave Addr Write
I2cwbyte &H02 'Register 2
'I2cwbyte &H07 '2 mW power, Unlock detect on
I2cwbyte &H05 '0.5 mW power, Unlock detect on
I2cstop 'I2C Stop
Waitms 1 'Wait for it to process
I2cstart 'I2C Start
I2cwbyte Fmtxwr 'I2C FMTx Slave Addr Write
I2cwbyte &H03 'Register 3
I2cwbyte L 'Lower byte frequency
I2cstop 'I2C Stop
Waitms 1 'Wait for it to process
'
I2cstart 'I2C Start
I2cwbyte Fmtxwr 'I2C FMTx Slave Addr Write
I2cwbyte &H04 'Register 4
I2cwbyte H 'Upper byte frequency
I2cstop 'I2C Stop
Waitms 1 'Wait for it to process
I2cstart 'I2C Start
I2cwbyte Fmtxwr 'I2C FMTx Slave Addr Write
I2cwbyte &H08 'Register 8
I2cwbyte Cex 'CEX = Band 0-3
I2cstop 'I2C Stop
Waitms 1 'Wait for it to process
'
I2cstart 'I2C Start
I2cwbyte Fmtxwr 'I2C FMTx Slave Addr Write
I2cwbyte &H00 'Register 0
'I2cwbyte &HA1 'Pwr on, 200 mV audio for 100% modulation; 75uS Deemph.
I2cwbyte &H81 'Pwr on, 200 mV audio for 100% modulation; 50uS Deemph.
I2cstop 'I2C Stop
Waitms 1 'Wait for it to process
'
I2cstart 'I2C Start
I2cwbyte Fmtxwr 'I2C FMTx Slave Addr Write
I2cwbyte &H0E 'Register E
I2cwbyte &H05 'Software reset
I2cstop 'I2C Stop
Waitms 1 'Wait for it to process
'
I2cstart 'I2C Start
I2cwbyte Fmtxwr 'I2C FMTx Slave Addr Write
I2cwbyte &H06 'Register 6
I2cwbyte &H1E 'Set internal charge pumps
I2cstop 'I2C Stop
Waitms 1 'Wait for it to process
'
Mcucr = &H38 'Prepare to sleep MCU
sleep 'Sleeps processor
Do : Loop 'Just in case it wakes up
End
Sub Read_switch
'Abfrage von bis zu 8 Kanaelen via Schalter S1-S3
Local Aa As Byte
Local Bb As Byte
Local Cc As Byte
Local Ges As Byte
If Pinb.2 = 1 Then Aa = 0 Else Aa = 1
If Pinb.3 = 1 Then Bb = 0 Else Bb = 2
If Pinb.4 = 1 Then Cc = 0 Else Cc = 4
Ges = Aa + Bb
Ges = Cc + Ges
'Eingabe gewuenschter Kanaele in MHz
If Ges = 0 Then Outfrq = 87.90 'Ch.1
If Ges = 1 Then Outfrq = 88.60 'Ch.2
If Ges = 2 Then Outfrq = 89.00 'Ch.3
If Ges = 3 Then Outfrq = 89.50 'Ch.4
If Ges = 4 Then Outfrq = 90.80 'Ch.5
If Ges = 5 Then Outfrq = 91.10 'Ch.6
If Ges = 6 Then Outfrq = 94.10 'Ch.7
If Ges = 7 Then Outfrq = 107.60 'Ch.8
End Sub