beautypg.com

Appendix b, Digital input/output control – Lanner LEC-3000A User Manual

Page 22

background image

20

Digital Input/Output Control

Appendix B

Embedded and Industrial Computing

A DIO sample code:
// LEC3000_Test cpp : Defines the entry point for the

console application
//

#include “Windows h”
#include “stdio h”
#include “F81865 h”

#define PARAMETER_HELP “Test 1 ==> Test DIO \nTest 2

==> Test LED \nTest 3 ==> Enable WatchDog \nTest 4 ==>

Disable WatchDog\n”

#define RETMSG(a,b) {printf (b) ; return a;}

int main(int argc, char* argv[])
{

try

{

int i = 0 ;

if (argc != 2)

RETMSG (-1, PARAMETER_HELP)

;

if (argv[1][0] == ‘1’)

{

for (i = 0 ; i < 4 ; i++)

{

printf

(“Set

DIO#%d=1\n”, i) ;

Write_DIO (i, 1) ;

Sleep (1) ;

printf (“Read DIO=”) ;

for (int j = 0 ; j < 4 ;

j++)

printf (“%d”,

Read_DIO (j) ) ;

printf (“\n”) ;

Sleep (500) ;

}

for (i = 0 ; i < 4 ; i++)

{

printf

(“Set

DIO#%d=0\n”, i) ;

Write_DIO (i, 0) ;

Sleep (1) ;

printf (“Read DIO=”) ;

for (int j = 0 ; j < 4 ;

j++)

printf (“%d”,

Read_DIO (j) ) ;

printf (“\n”) ;

Sleep (500) ;

}

}

else if (argv[1][0] == ‘2’)

{

printf (“LED Red\n”) ;

Run_LED (0, 1) ;

Run_LED (1, 0) ;

Sleep (1000) ;

printf (“LED Green\n”) ;

Run_LED (0, 0) ;

Run_LED (1, 1) ;

Sleep (1000) ;

printf (“LED Amber\n”) ;

for (i = 0 ; i < 33 ; i++)

{

Run_LED (0, 1) ;

Run_LED (1, 0) ;

Sleep (1) ;

Run_LED (0, 0) ;

Run_LED (1, 1) ;