B&B Electronics 485SDD16 manual Software, Programming Techniques, Digital I/O Mask Values

Page 13

Chapter 5 - Software

This chapter will be divided into two sections. The first section covers programming techniques for constructing a command string, receiving data and manipulating data in QuickBASIC. The second section discusses how to install and run the demonstration program on an IBM PC or compatible.

Programming Techniques

This section shows steps and examples of programming the 485SDD16 in QuickBasic. If you are programming in another language, this section can be helpful as a guideline for programming the 485SDD16.

Read I/O Lines Command

The Read I/O Lines command returns two data bytes that represents the states of the module's I/O lines. Refer to this

command in Chapter 3 for more information. Step 1 - Constructing the command string:

Cmnd$ = "!" + CHR$(Maddr) + "RD"

Where Maddr is the address of the module that is to return its I/O states.

Step 2 - Transmitting the command string:

PRINT #1, Cmnd$; Step 3 - Receiving the data:

MSIO$ = INPUT$(1,#1)

LSIO$ = INPUT$(1,#1)

Step 4 - Manipulating the data:

MSIO = ASC(MSIO$)

LSIO = ASC(LSIO$)

Step 5 - Determining an I/O's status:

MSstatus = MSIO AND mask

LSstatus = LSIO AND mask

By "ANDing" the value of MSIO or LSIO with the appropriate mask of an I/O line, the status of the I/O line can be determined. If the status is equal to zero the I/O line is LOW. If the status is not equal to zero the I/O line is HIGH. Table 5.1 shows the mask values for each I/O line.

Step 6 - Repeat Step 5 until the status of each I/O line has been determined.

485SDD16-1005 Manual

21

B&B Electronics --

707 Dayton Road -- Ottawa, IL 61350

PH (815) 433-5100 -- FAX (815) 433-5104

Example 5.1 - Determining the status of I/O lines #2 & #10 of module #5.

Maddr = 5 mask = &H4

Cmnd$ = "!" + CHR$(Maddr) + "RD" PRINT #1, Cmnd$;

MSIO$ = INPUT$(1,#1)

LSIO$ = INPUT$(1,#1)

MSIO = ASC(MSIO$)

LSIO = ASC(LSIO$) MSstatus = MSIO AND mask LSstatus = LSIO AND mask

If LSstatus equals zero then I/O line #2 is LOW. If LSstatus is not equal to zero then I/O line #2 is HIGH. If MSstatus equals zero then I/O line #10 is LOW. If MSstatus is not equal to zero then I/O line #10 is HIGH.

Table 5.1 - Digital I/O Mask Values

I/O Line #

 

Mask Values

 

 

Hexadecimal

 

Decimal

 

 

 

 

0 & 8

 

1H

 

1

1 & 9

 

2H

 

2

2 & 10

 

4H

 

4

3 & 11

 

8H

 

8

4 & 12

 

10H

 

16

5 & 13

 

20H

 

32

6 & 14

 

40H

 

64

7 & 15

 

80H

 

128

Read Configuration Command

The Read Configuration command reads the module's I/O definitions, Power-up states, Address, and Turn-around delay respectively. Refer to this command in Chapter 3 for more information.

Step 1 - Constructing the command string:

Cmnd$ = "!" + CHR$(Maddr) + "RC"

Where Maddr is the address of the module that is to return its configuration.

Step 2 - Transmitting the command string:

PRINT #1, Cmnd$;

22485SDD16-1005 Manual

B&B Electronics -- 707 Dayton Road -- Ottawa, IL 61350

PH (815) 433-5100 -- FAX (815) 433-5104

Image 13
Contents Designed and Manufactured Ottawa, Illinois Electronics Mfg. Co. IncInternet Sales@bb-elec.com Support@bb-elec.comTable of Contents 485SDD16 Specifications 485SDD16 FeaturesIntroduction Communications Power SupplySize Digital I/O Connections Connections485SDD16 I/O Port Pinout Serial Port ConnectionsExample of Multi-Node Network 485SDD16 Commands CommandsEquivalent Values SyntaxSet Output Lines Command Read I/O Lines CommandBit Assignments for I/O Lines Set Turn-around Delay Command Set Module Address CommandDefine I/O Lines Command Command AddrSC ArgumentRead Configuration Command Set Power-up States CommandRead Configuration command returns the modules I/O Command AddrRC Argument None ResponseDigital Inputs InterfacingDigital Outputs Isolated Solid State InputProgramming Techniques SoftwareDigital I/O Mask Values MSdefs = MSdefs and mask LSdefs = LSdefs and mask Set Output States CommandMSpups = MSpups and mask LSpups = LSpups and mask MSstates = MSstates or mask LSstates = LSstates or maskSet Power-up States Command Define I/O Lines CommandCmnd$ = ! + CHR$Maddr + SO + CHR$MSstates + CHR$LSstates Maddr =MSpups = MSpups and NOTmask LSpups = LSpups and NOTmask Set Module Address CommandCmnd$ = ! + CHR$Maddr + SS + CHR$MSpups + CHR$LSpups LSpups = LSpups or &H20Running Demonstration Program Demonstration Program485SDD16-1005 Manual Appendix a Decimal485SDD16-1005 Manual Appendix a 119 120 121 122 123 124 125 126 127485SDD16-1005 Manual Appendix B Appendix B252 Decimal to Hexadecimal Conversion3rd Hex digit 240 4th Hex digit Decimal equals 10FC hexadecimalAppendix C Table C.2 DBM16 I/O Connections Table C.1 DTB25 ConnectionsDBM16 Interfacing 485SDD16-1005 Manual Appendix C Figure C.4 Solid State InputPower Supply Input Voltage DBM16 Specifications LinesTotal Connections SizeFigure C.10 DBM16 Schematic Msb~ I/O msbI/O lsb ~ I/O lsb #addrRD00FF01FE Comp = not x and &HFF485SDD16-1005 Manual Appendix D Table D-1 Extended Commands