
3. CREATING A C PROGRAM
B–61863E–1/06
APPLICATION
PROGRAMMING GUIDE
404
A sample program is shown below.
This program turns keep-relay K10.0 alternately on and off every 80
milliseconds.
/****************************************/
/* ‘printf()’
/****************************************/
#include <stdio.h>
#include <pmclib.h>
#define IO D9
static char dummy;
static const char * const ColorName[] = {
“BLACK”, “RED”, “GREEN”, “YELLOW”, “BLUE”, “MAGENTA”, “CYAN”, “WHITE”
};
void Demo()
{
long 1;
short s;
char c;
printf(“
O033[2JO033[0;0HO033[0m“);
l = *pl meml2(IO D, 0);
s = *pl
mems2(IO D, 0);
c = *pl
memc2(IO D, 0);
printf(“D0(DWORD):DECIMAL = %111dOn”, 1);
printf(“D0(DWORD):HEXADECIMAL = %081x
On”, 1);
printf(“D0(WORD) :DECIMAL = %6d
On”, s);
printf(“D0(WORD) :HEXADECIMAL = %04x
On”, s);
printf(“D0(BYTE) :DECIMAL = %d
On”, c);
printf(“D0(BYTE) :HEXADECIMAL = %x
On”, c);
printf(“D0(BYTE) :CHARACTER = ‘%c’
On”, c);
putchar(‘On’);
for (s = 1; s < 8; s++)
printf(“
O033[%dm%8s On”, s + 40, ColorName[s]);
}
void far main()
{
unsigned short len;
char buf[64];
for (; ;) {
plpcmdi wait();
Demo();
while(pl mdikey(&len, buf) >=0)/* wait system screen */
os
wait tim(1);
}
}