'********************************************************************************** ' Adjust whitelevel of LDU '********************************************************************************** ' ' SCL (To Atmega 8 / Portd.4 + 10K pullup to +5V) ' SDA (To Atmega 8 / Portd.5 + 10K pullup to +5V) ' ' - Paste code, generated by the blacklevel program into this program ' - Put LDR on a white surface ' - Run Terminal program ' - Wait until error value gets as low as possible (this can take up to 1 min.) ' - Copy code out of terminal window and paste it into main program ' '********************************************************************************** $regfile = "m8def.dat" 'Atmega8-declarations $crystal = 3686400 $baud = 9600 Ddrb = &B00000001 Config Sda = Portd.5 Config Scl = Portd.4 Config I2cdelay = 10 Const Contrast = 35 'adjust contrast between surface and line (ca.20...50 20=no contrast 50=high contrast -- this contrastlevel is needed to find out, whether there's a line or not -- if there's no line, an alert will occur) Dim I As Byte 'i...k = general purpose variables Dim J As Byte Dim K As Byte Dim L As Byte Dim Error As Byte Dim Ldr(16) As Integer 'ldr contains the value of the light dependant resistors Dim Ler(16) As Integer Dim Lfr(16) As Integer Do '********************************************************************************** ' read the values of the 16 sensors via i²c '********************************************************************************** I2cstart 'i2c start condition I2cwbyte &B10010000 'send pcf address (write) I2cwbyte &B01000101 'send control byte (auto-increment on, internal oscillator on) I2cstart 'repeated start condition I2cwbyte &B10010001 'send pcf addressieren (read) I2crbyte Ldr(1) , Ack 'read value of adc0 & acknowledge I2crbyte Ldr(2) , Ack '... I2crbyte Ldr(3) , Ack '... I2crbyte Ldr(4) , Nack 'read value of adc3 / don't acknowledge I2cstop I2cstart 'i2c start condition I2cwbyte &B10010010 'send pcf address (write) I2cwbyte &B01000101 'send control byte (auto-increment on, internal oscillator on) I2cstart 'repeated start condition I2cwbyte &B10010011 'send pcf addressieren (read) I2crbyte Ldr(5) , Ack 'read value of adc0 & acknowledge I2crbyte Ldr(6) , Ack '... I2crbyte Ldr(7) , Ack '... I2crbyte Ldr(8) , Nack 'read value of adc3 / don't acknowledge I2cstop I2cstart 'i2c start condition I2cwbyte &B10010100 'send pcf address (write) I2cwbyte &B01000101 'send control byte (auto-increment on, internal oscillator on) I2cstart 'repeated start condition I2cwbyte &B10010101 'send pcf addressieren (read) I2crbyte Ldr(9) , Ack 'read value of adc0 & acknowledge I2crbyte Ldr(10) , Ack '... I2crbyte Ldr(11) , Ack '... I2crbyte Ldr(12) , Nack 'read value of adc3 / don't acknowledge I2cstop I2cstart 'i2c start condition I2cwbyte &B10010110 'send pcf address (write) I2cwbyte &B01000101 'send control byte (auto-increment on, internal oscillator on) I2cstart 'repeated start condition I2cwbyte &B10010111 'send pcf addressieren (read) I2crbyte Ldr(13) , Ack 'read value of adc0 & acknowledge I2crbyte Ldr(14) , Ack '... I2crbyte Ldr(15) , Ack '... I2crbyte Ldr(16) , Nack 'read value of adc3 / don't acknowledge I2cstop 'i2c stop condition '********************************************************************************** ' paste code out of LDU_adjust_black here: '********************************************************************************** Ldr( 1) = Ldr( 1) -38 Ldr( 2) = Ldr( 2) -37 Ldr( 3) = Ldr( 3) -37 Ldr( 4) = Ldr( 4) -43 Ldr( 5) = Ldr( 5) -40 Ldr( 6) = Ldr( 6) -40 Ldr( 7) = Ldr( 7) -48 Ldr( 8) = Ldr( 8) -36 Ldr( 9) = Ldr( 9) -42 Ldr(10) = Ldr(10) -40 Ldr(11) = Ldr(11) -39 Ldr(12) = Ldr(12) -41 Ldr(13) = Ldr(13) -33 Ldr(14) = Ldr(14) -33 Ldr(15) = Ldr(15) -28 Ldr(16) = Ldr(16) -22 '********************************************************************************** ' end pasted code out of LDU_adjust_black '********************************************************************************** Waitms 1000 Print Chr(12) Error = 0 For I = 1 To 16 'clear screen If Lfr(i) <> Ler(i) Then Error = Error + 1 Lfr(i) = Ler(i) Ler(i) = Ldr(i) + Ler(i) Ler(i) = Ler(i) / 2 If I > 9 Then Print "Ldr(" ; I ; ") = Ldr(" ; I ; ") / " ; Ler(i) Else Print "Ldr( " ; I ; ") = Ldr( " ; I ; ") / " ; Ler(i) End If J = I Mod 4 If J = 0 Then Print "" Next I Print "' *** error = " ; Error Loop End