\prog;Xi2cT0.asm|Simple write test ;JDN 280301 .Proc 16F84 RB0 = 5 ; bit on Status register that control Bank1 .Macro Bank0to1 Set Status:#RB0 .Endmacro .Macro Bank1to0 Clr Status:#RB0 .Endmacro \b;PortA bSCK = 0 ; I2C bits bSDA = 1 DirA = 2'00011 ; Bits 0 and 1 as inputs PortI2C = 5 TrisI2C = Porti2c SlaveAddress = 16'70 ; 8574 I/O expander .Ins Xi2cM.asi ; Inserts I2C macros \b;PortB bLed = 0 ; Led bright if output=0 DirB =2'00000000 ; Bit 0 as output .Macro LedOn Clr PortB:#bLed .Endmacro .Macro LedOff Set PortB:#bLed .Endmacro \b;Variables .Loc 16'0C ; begin of variables ADi2c: .Blk.16 1 CBit: .Blk.16 1 \b;Programme .Loc 0 ; program start Deb: Move #DirA,W Move W,TrisA Move #DirB,W Move W,TrisB Clr PortI2C ; important for SCK SDA Loop: Move #SlaveAddress,W Move W,ADi2c Call WriteI2C Skip,CS LedOn ; Ack Skip,CC LedOff ; NAck Call Wait ; space on the scope ; to ease synchronization Jump Loop \rout;WrI2C|Send address or data ; Duration about 100 \mu;s \in;ADi2c byte to be transmitted \out;Carry = 0 si ack \mod:ADi2c WriteI2C: Start Move #8,W Move W,CBit L$: RLC ADi2c Skip,CC SetSDA Skip,CS ClrSDA FullSCk DecSkip,EQ CBit Jump L$ SetSDA ; On attend un Ack ClrC Bank1to0 ; Acknowledge TestSkip,BC PortI2C:#bSDA ; CK doit être à 0 SetC Bank0to1 FullSCK Nop3 ClrSDA Stop Ret \rout:Wait|1ms wait Wait: Clr W W$: Add #-1,W ; 4 us loop Skip,EQ ; repeated 256 times Jump W$ Ret .End