'PCF8574 stepper example 'http://aquaticus.info 'uncomment for atmega16 $regfile = "m16def.dat" 'uncomment for atmega32 '$regfile = "m32def.dat" $crystal = 14745600 'hardware TWI library $lib "I2C_TWI.LBX" 'TWI clock (100kHz) Config Twi = 100000 Dim B As Byte Dim I As Integer Dim Pcf8574 As Byte Dim Steptab(8) As Byte Dim Steps As Byte Dim Step_mode As Byte 'Address of PCF8574 'JP1: SHORT 1-2 Pcf8574 = &H40 'JP1: SHORT 2-3 'Pcf8574 = &H42 'set 1 for half-step, 0 for full-step mode Step_mode = 0 'Diagnostic messages on DB1 Open "comc.5:2400,8,n,1" For Output As #1 Print #1 , "PCF8574 TEST. I2C ADDRESS: " ; Hex(pcf8574) ; " hex" Print #1 , "STEPPER ON X3 "; If Step_mode <> 0 Then 'half step Print #1 , "HALF STEP MODE" Steps = 8 Restore Half_step Else 'full step Print #1 , "FULL STEP MODE" Steps = 4 Restore Full_step End If 'initialize step table For I = 1 To Steps Read B Steptab(i) = B Next I 'Infinite loop Do For I = 1 To Steps 'flash optional LED on SL9 Toggle Porta.2 'send data to pcf8574 I2csend Pcf8574 , Steptab(i) 'this value affects the speed of rotation. Waitms 50 Next I Loop Full_step: Data &B10000000 , &B01000000 , &B00100000 , &B00010000 Half_step: Data &B10000000 , &B11000000 , &B01000000 , &B01100000 , &B00100000 , &B00110000 , &B00010000 , &B10010000