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

📄 dac832.c

📁 Example codes for ADuC8xx CPU family
💻 C
字号:
//********************************************************************
//
// Author        : ADI 
//
// Date          : December 2002
//
// File          : dac832.c
//
// Hardware      : ADuC832
//
// Description   : This program demonstrates the DAC functions DacCfg(),dacout()
//		
//********************************************************************
 

#include<ADuC832.h>	        		// SFR definition file.
#include"../../lib832.h"			// Function and variable declaration file.
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>

void PrintHelp(void);

void main(void)
	{
	char 	c1;		//Temporary variable.
	char	cXRef;		//External ref flag ('R' pressed).
	char	cChan;		//Selected channel.
	int	iVal;
	int	i1;

	UrtCfg(0x03,0x8508);	//UrtCfg configures UART.
	PllWcd(0);		//PllWcd writes CD bits.
	PrintHelp();
	DacCfg(0x1f);
	while(1)
		{
 		if(UrtBsy()&1)		//If key pressed.
  			{	// Act on command.
  			while((c1 = _getkey())=='w');	//Wait if 'w'.
    			if(c1=='r' || c1=='R')
      				{	//Ramp.
       			        putchar(c1);
	    			if(c1=='r')	cChan = 0;      				
       				else	cChan = 1;
       		      		for(i1=0; i1<0x1000; i1++)
       	                                DacOut(cChan,i1);
        		      	}
        	        else if(c1=='f' || c1=='F')
                 		{	//Full scale.
       			        putchar(c1);
                 		if(c1=='f')	cXRef = 0;
 	       			else	cXRef = 1;
	       		        DacCfg(0x1f+0x60*cXRef);
				}
			else if(c1=='h')	PrintHelp();
  			else if(c1=='0' || c1=='1')
    				{
       			        putchar(c1);
       			        putchar(':');
       				cChan = c1-'0';
       		                iVal = (getchar()-'0')*1000;
       	                 	iVal += (getchar()-'0')*100;
       	                 	iVal += (getchar()-'0')*10;
       	                 	iVal += (getchar()-'0');
                                DacOut(cChan,iVal);
      			}	}
 		}	
	}
void PrintHelp(void)
	{
	printf("To change settings during conversions press one of:\n");
	printf("\t f for Vref full scale.\n");
	printf("\t F for AVdd full scale.\n");
	printf("\t r to ramp DAC0 full scale.\n");
	printf("\t R to ramp DAC1 full scale.\n");
	printf("\t 0 plus 4 digits for that output on DAC0.\n");
	printf("\t 1 plus 4 digits for that output on DAC1.\n");
	printf("\t h for this help screen.\n");
	printf("\t w to wait.\n");
	printf("Press a key to end help.\n\n");
	_getkey();
	}

⌨️ 快捷键说明

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