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.5. BUSINSyntax : Variable = BUSIN Control , { Address }orBUSIN Control , { Address }, [ Variable {, Variable…} ]Overview :Operators :Receives a value from the I 2 C bus and places it into variable/s. By firstsending the control and optional address 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 value or a variable expression.The two variations of the BUSIN command may both be used in thesame BASIC program. The first type is useful for simply receiving asingle value from the bus. The second type may be used to receiveseveral values and designate each to a separate variable.The BUSIN command operates as an I 2 C master and may be used tointerface 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 %10100001 or $A1. 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 set to signifythat we wish to read from the eeprom. Note that this bit is automaticallyset by the BUSIN command, regardless of its initial setting.Example :‘ Receive a byte from the I 2 C bus and place it into variable Var.DIM Var as BYTE‘ We’ll only read 8-bitsDIM Address as WORD ‘ 16-bit address requiredSYMBOL Control %10100001 ‘ Target an eepromAddress = 20 ‘ Read the value at address 20Var = BUSIN Control , Address ‘ Read the byte from the eepromorBUSIN Control , Address, [ Var ]‘ Read the byte from the eeprom27Copyright Crownhill 2001

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

Saved successfully!

Ooh no, something went wrong!