Input Programming

1. port + 0
  MSN



                                                   


LSB
7
6
5
4
3
2
1
0
Input A/D low byte data.

2. port + 1
 MSN





                                                 
LSB
0
0
0
0
11
10
 9
 8
Input A/D high byte data.

3. port + 2
MSN






LSB
/hold
R2
R1
R0
C3
C2
C1
 C0 
Read back control signal for data conversion. Please refer next section for more details.

4. port +4
MSN






LSB
1D7
1D6
1D5
1D4
1D3
1D2
1D1
1D0
Digital input channel 1.

5. port + 5

MSN






LSB
2D7
2D6
2D5
2D4
2D3
2D2
2D1
2D0
Digital input channel 2.

6. port + 6

MSN






LSB
3D7
3D6
3D5
3D4
3D3
3D2
3D1
3D0
Digital input channel 3.

7. port + 7
MSN






LSB
4D7
4D6
4D5
4D4
4D3
4D2
4D1
4D0
Digital input channel 4.

8. port + 8

Counter 0 I/O buffer (8254 IC).

9. port + 9
Counter 1 I/O buffer (8254 IC).

10. port + A
Counter 2 I/O buffer (8254 IC).

11. port + B
Counter control register (8254 IC).


Output Programming
1. port + 0
MSN






LSB
x
R2
R1
R0
C3
C2
C1
C0
Select A/D channel number and enable/disable the selected channel. The R0 to R2 are used to select gain control factor, and the C0 to C4 are used to select A/D input channel. If JP5 is short, the Ro to R2 are disable.
R2 R1 R0 Gain Control Factor
0 0 0 *1
0 0 1 *2
0 1 0 *3
0 1 1 *4
1 0 0 *5
1 0 1 *6
1 1 0 *7
1 1 1 *8
The gain control factor is used to scale your input voltage. For example, if you select unipolar and its voltage range from 0 to 20V, and the gain control factor is *8, then your input voltage range is from 0 to 2.5V, because whole the input voltage was scale 8 times.
C3 C2 C1 C0 Input Channel
0 0 0 0 CH0
0 0 0 1 CH1
0 0 1 0 CH2
0 0 1 1 CH3
0 1 0 0 CH4
0 1 0 1 CH5
0 1 1 0 CH6
0 1 1 1 CH7
1 0 0 0 CH8
1 0 0 1 CH9
1 0 1 0 CH10
1 0 1 1 CH11
1 1 0 0 CH12
1 1 0 1 CH13
1 1 1 0 CH14
1 1 1 1 CH15
2. port + 1
MSN






LSB
ENX
X
T1
T0
SL3
SL2
SL1
SL0
Select IRQ and select control method. The T1 and T2 are used to select trig method for A/D converter, and the SL0 to SL3 are used to select interrupt line. When user select external trig(T1=1 and T0=0), he must connect J3 pin 2.
ENX Enable/Disable
0 Gate Disable
1 Gate Enable
T1 T0 Selection
0 0 Software trigger by port address + 2
0 1 Trig by 8254
1 0 External trig from J3-2
1 1 No trigger
When user select trig by 8254 (T1=0 and T0 =1), he must enable the gate by set ENX bit. The clock rate of 8254 is 2M, it is connected to counter 0, then the output of counter 0 is connected to counter 1, so that user need divide the clock by counter 0 then divide it by counter 1. The divided clock rate of counter 1 is used to trig A/D conversion.
SL3 SL2 SL1 SL0 Interrupt Selection
0 x x x No selection
1 0 0 0 IRQ3
1 0 0 1 IRQ4
1 0 1 1 IRQ5
1 0 1 1 IRQ7
1 1 0 0 IRQ10
1 1 0 1 IRQ11
1 1 1 0 IRQ12
1 1 1 1 IRQ15
3. port + 2
Start data conversion. When you select the software trigger (T1=0, T0=0) to start the A/D converter process, you can write any value to this address and start A/D converter process. It needs about 200ns to convert the signal.
4. port + 3
Output signal to reset/retrigger IRQ. When the A/D chip finish the converter process, they generate interrupt request selected by your choice channel. After your program finish the job, you must write any value to this address to clear the interrupt request signal.
5. port + 4
MSN






LSB
1D7
1D6
1D5
1D4
1D3
1D2
1D1
1D0
Digital output channel 1.

6. port + 5
MSN






LSB
2D7
2D6
2D5
2D4
2D3
2D2
2D1
2D0
Digital output channel 2.

7. port + 6
MSN






LSB
3D7
3D6
3D5
3D4
3D3
3D2
3D1
3D0

8. port + 7
MSN






LSB
4D7
4D6
4D5
4D4
4D3
4D2
4D1
4D0

9. port + 8

   counter 0 I/O buffer (8254 IC).

10. port + 9
   counter 1 I/O buffer (8254 IC).

11. port + A
   counter 2 I/O buffer (8254 IC).

12. port + B
   counter control register (8254 IC).

Programming Examples
If you want port+4, port+5, port+6, and port+7 as input channel, you must write FFH value to this port. In the following, we show a C language example.

This program uses the minimum resources of the 12 bit data acq uisition.  It only uses IRQ5 and an analog channel and checks digital channels in the card, but before you can use the option for digital I/O you must have a 2 x 26 pin cable connector placed in J1 and J2.
#include <stdio.h>#include <conio.h>#include <dos.h>#include <ctype.h>#include <process.h>#include <stdlib.h>
#ifdef __cplusplus    #define __CPPARGS ...#else    #define __CPPARGS#endif
int channel = 0, address = 0x200;
unsigned int hibyte, lobyte;
float ad;
lon
g int countint;

void main();

void interrupt (*old_interrupt)(__CPPARGS);    //interrupt handler

void interrupt dataacq_interrupt(__CPPARGS)  //interrupt service routine
{
countint++;  //interrupt counter
outportb(address, channel);  //selects the channel that will send a signal
outportb(address + 3, 0x00);  //resets the IRQ
hibyte = inportb(address + 1); //captures hibyte data
lobyte = inportb(address);  //captures lobyte data
outportb(0x20, 0x20); //end of interrupt
}


void one_channel()
{
int looping, OldMask1, NewMask1;
char select_irq, get_ch;

countint = 0;
clrscr();
old_interrupt = getvect(0x0d);       //save old interrupt service routine
disable();                         //disable interrupts
setvect(0x0d, dataacq_interrupt);  //use new ISR
enable();                    //enable interrupts
OldMask1 = inportb(0x21);              //save old interrupt mask
NewMask1 = OldMask1 & 0xDF;       //0xDF masks the interrupt to be used
outportb(0x21, NewMask1);         //output new interrupt mask

//controls output of counter to 100hz
outportb(address + 11, 0x36);
outportb(address + 8, 0xff);
outportb(address + 8, 0x03);
outportb(address + 11, 0x76);
outportb(address + 9, 0x14);
outportb(address + 9, 0x00);

clrscr();
gotoxy(21,3);printf("Channel             Received Value");
gotoxy(20,22);printf("Press 'Space' To Pause and Any Key To Quit");
outportb(address + 1, 0x9A); // output to selected irq
outportb(address + 3, 0x00);  //reset IRQ

do
    {
    gotoxy(1,1);printf("Interrupt Count: %ld", countint); //loop counter

    while(kbhit())//if key is pressed
        {
        get_ch = toupper(getch());
        if(get_ch == 0x20)  //if space bar
            {
            getch();
            }
        else
            {
            disable(); //disable interrupt
            setvect(0x0d, old_interrupt);  //restore old ISR
            enable(); //enable interrupt
            outportb(0x21, OldMask1);   //restore old mask
            main();
            }
        }
ad = ((hibyte & 0x0f) << 8) + (lobyte & 0xff);  //convert  hex   value to decimal
    ad = (ad * 10) / 0xfff;

    for(int z=0;z<=50;z++)     //loop counter
    for(int y=0;y<=100;y++)

    gotoxy(24,5);printf("%d", channel);  //display channel
    gotoxy(45, 5);printf("%.3f ", ad);  //display data
       
}
while(!kbhit());
disable();
setvect(0x0d, old_interrupt);
enable();
outportb(0x21, OldMask1);
main();
}


void digital_io()
{
int four_digital_io, all_hi, digital_addr, count_by_5, digital_send;
int data_read;
long int loop_count = 0;
char esc_key;

do
    {
    clrscr();
    gotoxy(28,20);printf("Press Any Key To Quit");
    gotoxy(1,1);printf("Loops: %ld    ", loop_count);

    for(count_by_5 = 0; count_by_5 <= 255; count_by_5 +=5)
        {
        delay(5);
        while(kbhit())
            {
            main();
            }
        gotoxy(1,4);printf("Transfer Data J3-1D to J2-3D");
        outportb(address + 4, count_by_5);
        outportb(address + 6, 0xff);
        data_read = inportb(address + 6);
        gotoxy(1,5);printf("Digital Input = %d   ",data_read);
        if(count_by_5 == data_read)
            {
            gotoxy(25,5);printf("...Pass  ");
            }
        else
            {
            gotoxy(25,5);printf("...Error");
            gotoxy(25,20);printf("Press Any Key To Continue");
            esc_key = getch();
            if(esc_key == 0x1b)
                {
                main();
                }
            }
        }
    loop_count++;
    }
while(!kbhit());
}

void main()
{
char main_select;

clrscr();

//main menu
gotoxy(25,7);printf("12 BIT DATA ACQUISITION CARD");
gotoxy(28,9);printf("[1] Test Analog Input");
gotoxy(28,10);printf("[2] Digital I/O");
gotoxy(28,11);printf("[3] Exit");
gotoxy(30,13);printf("Choose Option: ");

do
    {
    gotoxy(45,13);main_select = toupper(getch());
    switch(main_select)
        {
        case '1':
            //menu select for analog input function
            one_channel();
            break;
        case '2':
            digital_io();
            break;
        case '3':
//Terminates the program whenever the user chooses 5 from the main menu
            exit(0);

            break;
        }
    }
while(1);
}