Global Variables - Hardware I/O Ports (#7180-7187)

This section is a subtopic of Global Variables manual.

A video on the topic is available here:

The global variables 7180-7183 store the input values in 32 bit increments. Therefore, each register contains 32 bits corresponding to 32 input ports. In this way, Input0 is 31-0, Input1 is 63-32, etc.

Note the way the bits are arranged:

Variable Name Comment
7180 GVAR_HW_INPUTS0 bit 31…bit0 - note that the bits are laid out from 31 to 0 “left to right” rather than the other way around. This is important for the left shift (vs right shift) later in the code examples.
7181 GVAR_HW_INPUTS1 bit 63…bit32
7182 GVAR_HW_INPUTS2 bit 95…bit64
7183 GVAR_HW_INPUTS3 bit 127…bit96

Similarly, global variables 7184-7187 store the information on the state of the output ports, with each variable containing the state of 32 ports:

Variable Name Comment
7184 GVAR_HW_OUTPUTS0 bit 31…bit0 - note that the bits are laid out from 31 to 0 “left to right” rather than the other way around. This is important for the left shift (vs right shift) later in the code examples.
7185 GVAR_HW_OUTPUTS1 bit 63…bit32
7186 GVAR_HW_OUTPUTS2 bit 63…bit32
7187 GVAR_HW_OUTPUTS3 bit 127…bit96

An example of code using the global variable 7184 to access the state of the output:

# define TEST_OUTPUT 12
 
main() 
{
port_state_0=gvarget(7184); 
 
pin_state=port_state_0&(1<<TEST_OUTPUT);
if (pin_state==0) 
{  
   portset(TEST_OUTPUT);
  }else 
  {     
    portclr(TEST_OUTPUT);   
  }; 
 
exit(99);     
}; 

Note: we are using output 12 in this example. Any output can be used.

The code essentially consists of the following:

Another code example utilizing a similar idea is available below:

#define OUTPUT_LASET_SHUTTER 15
 
main()
{
 
a=gvarget(7184);
a=a&(1<<OUTPUT_LASER_SHUTTER);
 
if (a==0)
{
portset(OUTPUT_LASER_SHUTTER);
}else
{
portclr(OUTPUT_LASER_SHUTTER);
};
 
exit(99);
};