
/*******************************************************************/
/*      DIO-24    : Source Code                                    */
/*      Function  : DIO-24 Digital Output & Digital Input    */
/*      Date      : 04/29/1997                                     */
/*      Copyright : ICP DAS Co.                                    */
/*******************************************************************/

#include "stdio.h"
#include "conio.h"
#include "dio24.h"

unsigned int IO_BASE;

int _DIO24_Init(unsigned int base_adr)
{
    if(base_adr>=0x400) return(1);
    if(base_adr<0x200) return(1);

    IO_BASE=base_adr;


    return(0);

}





_DIO24_Conf( unsigned char pa_cw , unsigned char pb_cw ,
			 unsigned char pcl_cw, unsigned char pch_cw)
{

  unsigned char  cw;

  pa_cw &= 0x01;
  pb_cw &= 0x01;
  pcl_cw &=0x01;
  pch_cw &=0x01;

  

  cw=((pa_cw << 4) + (pch_cw <<3) + (pb_cw<<1) +(pcl_cw +0x80)) & 0x9b;

  outport(IO_BASE+3, cw);

 }

_DIO24_Output( unsigned char port_o , unsigned char data_o)
{

  data_o &=0xff ;
  if(port_o <=3) outportb( IO_BASE +3 - port_o , data_o );
  if(port_o ==4)
  {
  data_o &=0x0f ;
  outportb( IO_BASE +2 ,data_o);
  }
  if(port_o == 5)
  {
  data_o = (data_o<<4)& 0xf0;
  outportb( IO_BASE + 2 , data_o);
  }
}

_DIO24_Input( unsigned char port_i)
{

 unsigned char inp_data;

 if (port_i<=3) inp_data= inportb( IO_BASE + 3 - port_i ) ;

 if (port_i==4) inp_data= (inportb( IO_BASE + 2 ))&0x0f;
 if (port_i==5) inp_data=((inportb(IO_BASE + 2))&0xf0)>>4;

 return(inp_data);

}


