dac.c

来自「DC Power 基于Mega8数控电源」· C语言 代码 · 共 31 行

C
31
字号
#include <avr/io.h>#include "avr_compat.h"// dac takes an int instead of unsigned int to avoid conversion// from the datatypes in analog.c but you can only use the positive values. void dac(int value){	PORTD=value & 0xFF; // mask out 8 bits	// 0x300=1100000000	value=(value & 0x300)>>6; // mask out 2 msb bits and shift by 6	// F3=11110011	PORTC=(PORTC & 0xF3)|value; // change PC2 and PC3 only}void init_dac(void) {	// enable PD0-PD7 as output PD0 is LSB in dac	DDRD=0xff;	// zero output	PORTD=0;	// enable PC3 as output (MSB in dac)	sbi(DDRC,PC3);	// zero output	cbi(PORTC,PC3);	// enable PC2 as output (MSB in dac)	sbi(DDRC,PC2);	// zero output	cbi(PORTC,PC2);}

⌨️ 快捷键说明

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