#include #include #include #include "dm5406.h" #define BaseAddress 0x380 unsigned short DM_DoConversion( void ) { unsigned short value; /* Start the conversion */ outp( BaseAddress + START_CONVERSION, 0 ); /* Wait for conversion to complete */ while ( ( inp( BaseAddress + STATUS_BYTE ) & 1 ) == 0 ) ; /* Read the Data, MSB first */ value = ( inp( BaseAddress + READ_DATA ) & 0x0F ) * 256; value += inp( BaseAddress + READ_DATA ) & 0xFF; return value; } /* The channel here includes the gain: To read channel 3 with A gain of 8: Read_AtoD( 3 | GAIN_8 ) */ unsigned short DM_Read_AtoD( unsigned char Channel ) { unsigned char B; /* Set the conversion channel: */ Channel &= AD_MASK; B = inp( BaseAddress + CHANNEL_SLCT ); if ( ( B & AD_MASK ) != Channel ) { B = ( B & ~AD_MASK ) | Channel; outp( BaseAddress + CHANNEL_SLCT, B ); DM_DoConversion(); /* Once for settling time */ } return DM_DoConversion(); } /******************* DM_Reset The ResetBoard procedure is used to reset the DM5406. The 8255 PPI is configured so that ports A and C are input and port B is output, a dummy A-D conversion is performed and then the clear board command is sent. *******************/ void DM_Reset(void) { outp(BaseAddress + PPI_CTRL, 0x99); /* Set PPI Port B for output */ outp(BaseAddress + PPI_B, 0); /* Channel 0, Gain 1, Ext Trig = Disabled, IRQ = Disabled */ outp(BaseAddress + SCAN_BURST_SLCT, 0); outp(BaseAddress + CLEAR_BOARD, 0); DM_DoConversion(); /* Dummy Conversion */ outp(BaseAddress + CLEAR_BOARD, 0); /* Any value will do */ }