⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pc_dac.c

📁 《并行口编程指南》
💻 C
字号:
/*pc_dac.c*/
/*Program to interface the 12-bit AD7548 ADC to the DATA port of the 
parallel adapter*/

#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <process.h>


#define BUF_LEN 1000

/*Global variables that store the addresses of two of three ports of the
standard printer adapter*/
/*for interfacing the DAC to the parallel adapter we need the DATA
port and the CONTROL port*/

unsigned int dport, cport;


main()
{
/*the following array stores data to be transfered to the DAC
connected to the DATA port*/
unsigned int dac_array[BUF_LEN], count, in_temp;
unsigned char temp;



/*Get LPT1 port addresses */
dport = peek(0x40,0x08);
if(dport ==0)
        {
        printf("\n\n\nLPT! not available... aborting\n\n\n");
        exit(1);
        }
printf("\nLPT1 address = %X", dport);
cport = dport +2; 	/* control port address */


/*this statement puts all the CONTROL port signals to logic 1*/
outportb(cport, 0x04);

/*setup a loop to transfer the required data points*/
for(count=0; count<BUF_LEN; count++)
         {
/*The DAC data is stored in the integer variable such that the
least significant 12 bits of the 16 bits contain the DAC data.
The DATA port is 8-bits wide so the 12-bits data is transferred
in two passes. In the first pass, the MSB data is transferred, 
which is 4 bits. In the next pass, the lower 8 bits are transferred
and the LDAC signal is activated*/

in_temp = dac_array[count];
in_temp = in_temp>>8; /*transfer the higher byte in the lower position*/
temp=(unsigned char) in_temp;
/*copy the low byte of the int into a char variable*/

outportb(dport, temp); /*output it to the DATA port*/
temp = inportb(cport);
temp = temp & 0xfb; /*make C2 low, to pulse CSMSB* low*/
outportb(cport, temp);

temp = temp | 0x01; /*pulse C0* low to generate WR* */
outportb(cport, temp);

temp = temp & 0xfe; /*make C0* high again*/
outportb(cport, temp);

temp = temp | 0x04; /*make C2 high again*/
outportb(cport, temp);

in_temp = dac_array[count];
in_temp = in_temp & 0x0f;
temp=(unsigned char) in_temp; /* put the lower byte of the integer 
variable in a char variable*/
outportb(dport, temp); /*load the DATA port with the lower byte for
the DAC*/

temp = inport(cport);
temp = temp | 0x02;
outportb(cport, temp); /*make C1* low so that CSLSB* and LDAC are
low*/

temp = temp | 0x01; /*pulse C0* low to generate WR* */
outportb(cport, temp);

temp = temp & 0xfe; /*make C0* high again*/
outportb(cport, temp);

temp = temp & 0xfd; /*make C1* high again*/
outportb(cport, temp);

         }

return 1;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -