11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PICBASIC</strong> <strong>PLUS</strong> Compiler5.6. BUSOUTSyntax : BUSOUT Control , { Address } , [ Variable {, Variable…} ]Overview :Operators :Transmit a value to the I 2 C bus by first sending the control and optionaladdress out of the clock pin (SCL), and data pin (SDA).Variable is a user defined variable or constant.Control may be a constant value or a BYTE sized variable expression.Address may be a constant, variable, or expression.The BUSOUT command operates as an I 2 C master and may be usedto interface with any device that complies with the 2-wire I 2 C protocol.The most significant 7-bits of control byte contain the control code andthe slave address of the device being interfaced with. Bit-0 is the flagthat indicates whether a read or write command is being implemented.For example, if we were interfacing to an external eeprom such as the24C32, the control code would be %10100000 or $A0. The most significant4-bits (1010) are the eeprom’s unique slave address. Bits 2 to3 reflect the three address pins of the eeprom. And Bit-0 is clear tosignify that we wish to write to the eeprom. Note that this bit is automaticallycleared by the BUSOUT command, regardless of its initialvalue.Example :‘ Send a byte to the I 2 C bus.DIM Var as BYTE‘ We’ll only read 8-bitsDIM Address as WORD ‘ 16-bit address requiredSYMBOL Control %10100000 ‘ Target an eepromAddress = 20 ‘ Write to address 20Var = 200 ‘ The value place into address 20BUSOUT Control , Address , [ Var ] ‘ Send the byte to the eepromDELAYMS 5‘ Allow time for allocation of byteAddress, is an optional parameter that may be an 8-bit or 16-bit value.If a variable is used in this position, the size of address is dictated bythe size of the variable used (BYTE or WORD). In the case of theabove eeprom interfacing, the 24C32 eeprom requires a 16-bit address.While the smaller types require an 8-bit address. Make sureyou assign the right size address for the device interfaced with, or youmay not achieve the results you intended.30Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!