User Tools

Site Tools

한국어

moacon:portinit:index

portInit

void portInit(u8 portBlockNumber, u8 mode)

portBlockNumber: Port Block Number (e.g. 0 for ports 0~7, 1 for ports 10~17, etc…)
mode: 0 or 1 (0=Output, 1=Input)

Intitializes a port block's I/O mode as either Input or Output. In order to use a port for output, its I/O mode must be changed to Output. Likewise, in order to use a port for input, its I/O mode must be changed to Input.

Ports are initialized to Input when the system is first powered on. The MOACON ports' I/O mode can only be set in blocks. The MOACON's ports are organized in blocks of 8.

Number Block 0 (+0) Block 1 (+10) Block 2 (+20) Block 3 (+30) Block 4 (+40) Block 5(+50)
Ports Ports 0 - 7 Ports 10 - 17 Ports 20 - 27 Ports 30 - 37 Ports 40 - 47 Ports 50 - 57

Setting mode to 0 will put the port block in Output mode, and setting mode to 1 will put the port block in Input mode.

In the image above there are 3 output modules and 3 input modules. The following code would be used to set the ports' I/O mode for this configuration.

portInit(0,0); // Block 0 in Output mode
portInit(1,0); // Block 1 in Output mode
portInit(2,0); // Block 2 in Output mode
portInit(3,1); // Block 3 in Input mode
portInit(4,1); // Block 4 in Input mode
portInit(5,1); // Block 5 in Input mode

Because ports are initialized to Input when the system is first powered on, this code can be reduced to the following:

portInit(0,0); // Block 0 in Output mode
portInit(1,0); // Block 1 in Output mode
portInit(2,0); // Block 2 in Output mode

Port blocks 3, 4, and 5 are in Input mode by default.

The following program will copy all the outputs read from an input module in slot 0 (DIO +0) to the output module in slot 1 (DIO + 10).

#include "moacon500.h"
 
void cmain()
{
    portInit(0, 1); // Input module in slot 0
    portInit(1, 0); // Output module in slot 1
 
    while(1)
    {
       u8 state = portBlockIn(0);  // Read all 8 inputs
       portBlockOut(1, state);     // Copy input state to outputs
    }
}

MOACON home

moacon/portinit/index.txt · Last modified: 2017/11/16 10:56 by COMFILE Technology