'Realsisierung mit i2cslave.lib 'kostenpflichtig von MCS erworben 'i2c-Eingang '*********** 'SCL is PORTD.4 (T0) 'SDA is PORTD.2 (INT0) 'Use 10K pull up resistors for both SCL and SDA Config Timer1 = Timer , Prescale = 1 On Timer1 Timer1_isr Enable Interrupts Enable Timer1 Dim Daten As Byte Dim I2cadresse As Byte Config I2cslave = &B11001010 '202 (konstant) $crystal = 4000000 $regfile = "2313def.dat" Config Portb = Output Portb = 255 Portb.1 = 0 'kontrolle, ob programm startet 'warten auf i2c-Daten '********************* Do Loop '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ' The following labels are called from the slave library '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 'When the master wants to read a byte, the following label is allways called 'You must put the data you want to send to the master in variable _a1 'which is register R16 I2c_master_needs_data: '********************* 'when your code is short, you need to put in a waitms statement 'Take in mind that during this routine, a wait state is active 'and the master will wait 'After the return, the waitstate is ended 'Config Portb = Input '_a1 = Pinb Return 'When the master writes a byte, the following label is always called 'It is your task to retrieve variable _A1 and do something with it '_A1 is register R16 that could be destroyed/altered by BASIC statements 'For that reason it is important that you first save this variable I2c_master_has_data: '******************* Daten = _a1 'this is not needed but it shows how you can store _A1 in a byte 'after you have stored the received data, you can alter R16 'when your code is short, you need to put in a waitms statement 'Take in mind that during this routine, a wait state is active 'and the master will wait 'After the return, the waitstate is ended Waitms 10 Gosub Blinken 'kontrolle, ob daten angekommen Enable Timer1 Timer1 = 0 Start Timer1 Return Timer1_isr: 'soll nach dem Empfang von Daten aktiviert werden Portb.7 = 0 Waitms 100 Portb.7 = 1 Waitms 100 If Timer1 > 60000 Then Stop Timer1 End If Timer1_isr_ende: Return Blinken: Portb.0 = 0 Waitms 100 Portb.0 = 1 Waitms 100 Blinken_ende: Return