ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 12.06.2025

Просмотров: 8290

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

© MCS Electronics, 1995-2007

X The hexadecimal string that must be converted.

In VB you can use the VAL() function to convert hexadecimal strings.

But since that would require an extra test for the leading &H signs that are required in VB, a separate function was designed.

See also

HEX , VAL , STR , BIN , BINVAL

Example

$regfile = "m48def.dat"

' specify the used

micro

' used crystal

$crystal = 8000000

frequency

' use baud rate

$baud = 19200

$hwstack = 32

' default use 32

for the hardware stack

' default use 10

$swstack = 10

for the SW stack

' default use 40

$framesize = 40

for the frame space

Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

Dim L As Long

Dim S As String * 8

Do

Input "Hex value " , S

L = Hexval(s)

Print L ; Spc(3) ; Hex(l)

Loop

HIGH

Action

Retrieves the most significant byte of a variable.

Syntax

var = HIGH( s )

Remarks

Var

The variable that is assigned with the MSB of var S.

S

The source variable to get the MSB from.

See also

LOW , HIGHW

page -521-


© MCS Electronics, 1995-2007

Example

Dim I As Integer , Z As Byte

I = &H1001

Z = High(i) ' is 10 hex or 16 dec

End

HIGHW

Action

Retrieves the most significant word of a long variable.

Syntax

var = HIGHW( s )

Remarks

Var

The variable that is assigned with the MS word of var S.

S

The source variable to get the MSB from.

There is no LowW() function. This because when you assign a Long to a word or nteger,i only the lower part is assigned. For this reason you do not need a Loww() function. W=L will do the same.

See also

LOW , HIGH

Example

Dim X As Word , L As Long

L = &H12345678

X = Highw(l)

Print Hex(x)

HOME

Action

Place the cursor at the specified line at location 1.

Syntax

HOME UPPER | LOWER | THIRD | FOURTH

Remarks

If only HOME is used than the cursor will be set to the upper line.

You may also specify the first letter of the line like: HOME U

page -522-

© MCS Electronics, 1995-2007

See also

CLS , LOCATE

For a complete example see LCD

Partial Example

'set cursor

Locate 2 , 1

position

'display this

Lcd "*"

Home Upper

'select line 1 and

return home

I2CINIT

Action

Initializes the SCL and SDA pins.

Syntax

I2CINIT

Remarks

By default the SCL and SDA pins are in the right state when you reset the chip. Both the PORT and the DDR bits are set to 0 in that case.

When you need to change the DDR and/or PORT bits you can use I2CINIT to bring the pins in the proper state again.

ASM

The I2C routines are located in i2c.lib. _i2c_init is called.

See also

I2CSEND , I2CSTART , I2CSTOP , I2CRBYTE , I2CWBYTE , I2C_TWI Library for using TWI

Example

Config Sda = Portb.5

Config Scl = Portb.7

I2cinit

Dim X As Byte , Slave As Byte

'reset variable

X = 0

Slave = &H40

'slave address of

a PCF 8574 I/O IC

'get the value

I2creceive Slave , X

Print X

'print it

page -523-


© MCS Electronics, 1995-2007

I2CRECEIVE

Action

Receives data from an I2C serial slave device.

Syntax

I2CRECEIVE slave, var

I2CRECEIVE slave, var , b2W, b2R

Remarks

Slave

A byte, Word/Integer variable or constant with the slave address

from the I2C-device.

Var

A byte or integer/word variable that will receive the information

from the I2C-device.

b2W

The number of bytes to write.

Be cautious not to specify too many bytes!

b2R

The number of bytes to receive.

Be cautious not to specify too many bytes!

You must specify the base address of the slave chip because the read/write bit is set/reset by the software.

When an error occurs, the internal ERR variable will return 1. Otherwise it wil be set to 0.

ASM

The I2C routines are located in the i2c.lib/i2c.lbx files.

See also

I2CSEND, I2CSTART , I2CSTOP, I2CRBYTE , I2CWBYTE

Example

Config Sda = Portb.5

Config Scl = Portb.7

Dim X As Byte , Slave As Byte

'reset variable

X = 0

Slave = &H40

'slave address of

a PCF 8574 I/O IC

'get the value

I2creceive Slave , X

Print X

'print it

Dim Buf(10)as Byte

Buf(1) = 1 : Buf(2) = 2

'send two bytes

I2creceive Slave , Buf(1) , 2 , 1

and receive one byte

'print the

Print Buf(1)

received byte

End

page -524-


© MCS Electronics, 1995-2007

I2CSEND

Action

Send data to an I2C-device.

Syntax

I2CSEND slave, var

I2CSEND slave, var , bytes

Remarks

Slave

The slave address off the I2C-device.

Var

A byte, integer/word or numbers that holds the value, which will be,

send to the I2C-device.

Bytes

The number of bytes to send.

When an error occurs, the internal ERR variable will return 1. Otherwise it wil be set to 0.

ASM

The I2C routines are located in the i2c.lib/i2c.lbx files.

See also

I2CRECEIVE , I2CSTART, I2CSTOP , I2CRBYTE , I2CWBYTE

Example

Config Sda = Portb.5

Config Scl = Portb.7

Dim X As Byte , A As Byte , Bytes As Byte

'assign variable

X = 5

to 5

Dim Ax(10)as Byte

'slave address of

Const Slave = &H40

a PCF 8574 I/O IC

'send the value or

I2csend Slave , X

For A = 1 To 10

'Fill dataspace

Ax(a) = A

Next

Bytes = 10

I2csend Slave , Ax(1) , Bytes

End

I2START,I2CSTOP, I2CRBYTE, I2CWBYTE

Action

page -525-