Paso 4: Programar el maestro
Por último, programar el microcontrolador maestro. Preste especial atención a las líneas que la DDELink. Propiedad Ubicación: Si no está establecido correctamente, esto no funciona!
Dim Master As New oDDELinkDim wire As New oWireDim hz1 As New oBitSub Main() 'link the 1 second timer to the a bit we can access 'this bit will now toggle once per second wire.Input.Link(ooPIC.Hz1) wire.Output.Link(hz1) wire.Operate = cvTrue 'this sets the I2C address of our local microcontroller 'the I2C interface is not active until an address is set ooPIC.Node = 1 'now we setup our DDELink object, our input is the bit hz1 'note that the object also has a .Output property that is used 'when we are in recieve mode Master.Input.Link(hz1) 'this is the I2C address of the remote microcontroller, note that 'in the slave code, we tell it to have an address of 2 Master.Node = 2 'ugh...this is the crappy part, this is the "address" of the DDELink 'object in the slave's memory space. In order to figure out this number, 'we need to open and compile the slave code, then goto View->Compiled Code. 'look for something like: 'L*.Construct.Begin ;Dim <name> as new oDDELink 'where * is any number, and <name> is the name of your DDELink object 'in your slave code. The line immediately below it should read something like: 'C0020:041 ;This.<name>.Address 'the number to the right of the ':' is the address of the slave DDELink object Master.Location = 41 'this tells the object that we will be sending data (ie, copy data from our .Input property 'to the slaves .output property (note, if you set this to recieve, it is the opposite) Master.Direction = cvSend 'turn it on, but nothing is happening yet... Master.Operate = cvTrue Do 'check to see if we are currently transmitting data If Master.Transmitting = cvFalse Then 'setting this value to 1 will cause the master to send the value to the slave 'note, this is automatically reset to 0 upon completion of transmission Master.Sync = 1 End If LoopEnd Sub