'The ATmega8 is used. $regfile = "m8def.dat" $crystal = 4000000 Config Sda = Portc.4 Config Scl = Portc.5 Config I2cdelay = 10 Config Lcd = 16 * 2 Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portb.1 , Db6 = Portb.2 , Db7 = Portb.3 , E = Portb.4 , Rs = Portb.5 Config Pind.7 = Output Led Alias Portd.7 'Jcl1562b write and read i2c address Const Jcl1562bwrite = &H70 Const Jcl1562bread = &H71 'Lt6904 write i2c address Const Lt6904write = &H2E 'Lt6904 clk/clk-not configuration 'clk=on, clk-not=off Const Lt6904config = &B10 Dim Frequency As Single Dim Freqincrement As Single Dim Tmp As Single Dim Pwr As Single Dim Oct As Byte Dim Dac As Word Dim Dactmp As Word Dim Lt6904byte1 As Byte Dim Lt6904byte2 As Byte Dim Lttmp As Byte Dim Hexstr As String * 4 Pwr = 2.0 Frequency = 1000000.0 Freqincrement = 100000.0 Cls Do Set Led Waitms 50 Reset Led Waitms 50 'I2cstart 'I2cwbyte Jcl1562bwrite 'I2cwbyte 255 'I2cstop 'Waitms 250 'I2cstart 'I2cwbyte Jcl1562bwrite 'I2cwbyte 0 'I2cstop 'Waitms 250 'calculate oct and dac for this frequency, see 'lt6904 datasheet Tmp = Frequency / 1039 Tmp = Log10(tmp) Tmp = 3.322 * Tmp Oct = Int(tmp) Tmp = Oct + 10 Tmp = Power(pwr , Tmp) Tmp = Tmp / Frequency Tmp = Tmp * 2078 Dac = Int(tmp) Dac = 2048 - Dac Upperline Lcd "Frequency (kHz) " ; Frequency ; " " 'calculate lt6904 two frequency and configuration setting bytes 'Lcd Oct ; " " ; Dac ; " " 'first lt6904 byte is oct shifted left four bits Lt6904byte1 = Oct Shift Lt6904byte1 , Left , 4 'plus the lower two bits of the high byte of dac shifted 2 bits to the left Lttmp = High(dac) Lttmp = Lttmp And &B00000011 Shift Lttmp , Left , 2 Lt6904byte1 = Lt6904byte1 + Lttmp 'plus the upper two bits of the low byte of dac shifted 6 bits to the right Lttmp = Low(dac) Lttmp = Lttmp And &B11000000 Shift Lttmp , Right , 6 Lt6904byte1 = Lt6904byte1 + Lttmp 'second lt6904 byte is the left six bits of the low byte of dac 'plus the lt6904 config bits Lt6904byte2 = Low(dac) Shift Lt6904byte2 , Left , 2 Lt6904byte2 = Lt6904byte2 + Lt6904config Hexstr = Hex(lt6904byte1) Lowerline Lcd "Fbyte1: " ; Hexstr ; " " Hexstr = Hex(lt6904byte2) Lcd "Fbyte2: " ; Hexstr ; " " I2cstart I2cwbyte Lt6904write Lcd "I2C-status: " ; Err ; " " 'Waitms 50 I2cwbyte Lt6904byte1 Lcd Err ; " " 'Waitms 50 I2cwbyte Lt6904byte2 Lcd Err ; " " 'Waitms 50 I2cstop If Frequency > 1000000.0 Then Freqincrement = -10000.0 If Frequency < 500000.0 Then Freqincrement = 10000.0 Frequency = Frequency + Freqincrement Loop End