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

📄 dac_1446.c

📁 使用picc开发的使用spi总线控制AD和DA芯片的源程序
💻 C
字号:
//   DIGITAL TO ANALOGUE CONVERTER HARDWARE INTERFACE PROGRAM
//   COPYRIGHT PROPERTY OF ALPHADATA DESIGNS LIMITED (c) 1999
//   WRITTEN FOR THE LTC1446 12 BIT 2-CHANNEL MICRO-WIRE D TO A

//   published by permission of Alphadata designs on
//   Hi-Tech C website, http://www.workingtex.com/htpic. Thanks!

//------------------------------------------------------
// Version History
//------------------------------------------------------
// Issue 1.0 : 21/12/1999 : First Officially Released
//------------------------------------------------------

#include <stdio.h>

#include "h8genlib.h"
#include "ioh8314.h"
#include "sci.h"
#include "spi.h"
#include "dac_1446.h"

extern byte p4dr;

/* call this to write one channel of data to the d to a */
void dac_write(word output)
{
byte count;
byte block;
byte ops[3];
//char	s[50];

	/* Select ADC device */
  	spi_dac_select();

  	//Format output data
	if (output<0x1000) {

		ops[0]=0;
		ops[1]=output >> 8;
		ops[2]=output;

	} else {

		ops[0] = output >> 4;
		ops[1] = (output << 4) + 0x0F;
		ops[2] = 0xFF;

	}

//  	ops[0]= ((byte*)&output)[1];
//    	ops[1]= ((byte*)&output)[2];
//    	ops[2]= ((byte*)&output)[3];

//    	sprintf(s,"%02X %02X %02X\r\n",ops[0],ops[1],ops[2]);
//    	sci_put_string(0,s);

	/* output three blocks of eight bits */
	for (block=0;block<3;block++) {
  		for (count=0;count<8;count++) {

	  		if ((ops[block] & 0x80) == 0) spi_lodata(); else spi_hidata();

	  		spi_hiclock();

	  		spi_loclock();

    			ops[block] = ops[block] << 1;
  		}
  	}

  	spi_dac_deselect();

}

/* call this to set up the hardware ports */
void dac_initialise(void)
{

	dac_write(0);

}

// end

⌨️ 快捷键说明

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