C language is the one of good complier for interface program via
Programming Microsoft Visual C++ 6 communicating Parallel Port
|
Outp(port,bytedata) |
Send value out port as byte |
|
|
Outpw(port,worddata) |
Send value out port as word |
Such as Outp(0×378,0xF1) |
|
Outpd(port,worddata) |
Send value out port as byte double words. |
|
|
inp(port) |
Read value as byte from port |
|
|
inpw(port) |
Read value as word from port. |
Such as inpw(0×378) |
|
inpd(port) |
Read value as double words from port. |
|
You can notice that the structure of function is like programming by VB because Dll File that is used in VB that is written from C. I will not mention the fundamental of communicating port.
Programming to communicate port Card I/O 8255
Step 1. Set file library
#include<stdio.h>
#include<stdib.h>
#include<dos.h> /* for using function Outp and inp */
#include<conio.h> /* for using function about showing and getting alphabet */
void main(void){
Step 2. Set variable and value of port
int Signal;
int Base;
int portA,portB,port,C; /* variable of Address port */
int ctrlport;
clrscr(); /* clear display */
window(5,5,75,30); /* set alphabet’s frame */
gotoxy(1,1);
cprintf(”Input base address(decimal) Ex.608\n”); /* get started value of port in 8255 */
gotoxy(1,2);scanf(”%d”,&Base);
portA=Base; /* value of port A, start at 300H */
portB=Base+1; /* value of port B’s position, adding 1 value at 301H */
portC=Base+2; /* value of port’s position C by adding 2, having value at 302H */
ctrlport=Base+3; /* value of controlled port’s position adding 3, having value at 303H */
outp(ctrlport,0×80) /* value that we set port as Out put */
Step 3. set working’s condition from user
while(1) {
gotoxy(1,4);cprintf(”Port A.1 has open relay\n”);
gotoxy(1,5);cprintf(”Enter (1) off relay\n”);
gotoxy(1,6);cprintf(”Enter (2) on relay\n”);
gotoxy(1,7);cprintf(”Enter (3)Exit to Dos\n”);
gotoxy(1,8);cprintf(”<—-Select Pls.—->”);
swich(signal){
case1:outp(portA,0); /*not Relay normally open */
gotoxy(1,10);cprintf(Load Motor to on\n”);
case2:outp(portA,1); /* Relay normally Colse */
gotoxy(1,10);cprintf(Load Motor to off\n”);
case3: gotoxy(1,20);cprintf(Exiting\n”);
exit(0);
break;
} /* end Select condition */
if(signal<1 || signal>3){
gotoxy91,15);;cprintf(”Keypress 1,2 or 3\n”);
}; /* end if */
}; /*end while condition*/
}; /* end of main */
Programming to communicate
This method is programming, using to control circuit for LCD display or send alphabet through parallel port that has programming like this.
Step 1 : set library file
#include<dos.h>
#include<stdio.h>
#include<conio.h>
Step 2: set variable and the value of port
#define Com1 0×3F8
/* set com port if Com1= 0×3F8*/
/* set com port if Com2= 0×2F8*/
/* set com port if Com3= 0×3E8*/
/* set com port if Com4= 0×2E8*/
void main(void)
{
int ch;
int count;
char init[]={0×0F,0×01,0×38}; /* 0×0F = Init Display */
/* 0×01 = Clear Dispaly */
/* 0×38 = Dual Line/8 Bits */
outp(Com1+1,0×0); /* set interrupt - Port1 */
outp(Com1+3,0×80); /* set Dual to On*/
outp(Com1+0,0×0C); /* set Baud rate Low Byte*/
/*instead of 0×06 = 19,200 BPS */
/* instead of 0×0C = 9,600 BPS */
/* instead of 0×18 = 4,800 BPS */
/* instead of 0×30 = 2400 BPS */
outp(Com1+1,0×00); /* set Baud rate High Byte */
outp(Com1+3,0×03); /* 8 bit,No Parity,1 Stop Bit */
outp(Com1+2,0xC7); /* FIFO control register*/
outp(Com1+4,0×0B); /* open DTR,RTS,and Out2*/
outp(Com1+4,(inp(Com1+4) | 0×01)) /*select register(DTR) ,0= intersection register /*
for (count=0 ;count <3;count++)
{
outp(Com1,init[count]); /* send value in variable of init */
delay(20) ; /* delay time 20 */
}
outp(Com1+4,(inp(Com1+4) & 0xFE)) /*select register (DTR) ,1=data register /*
printf(”\nSample serial LCD display program,Press ESC to Exit\n”);
do{
if(kbhit()){
ch=getch();
outp(com1),ch);
printf(”%c”,c);
}
}while(c!=27);
}
LCD circuit that will be interfaced with Computer through RS-232 Click here