// **********dab8043.c // Interface between MC68HC812 and DAC8043 12-bit DAC // does not use SPI (for SPI interface see dac8043.c) // Last modified 1/15/02 by Jonathan W. Valvano // Copyright 2002 by Jonathan W. Valvano, valvano@uts.cc.utexas.edu // You may use, edit, run or distribute this file // as long as the above copyright notice remains //******** DAC8043_Init *************** // Initialize 6812-DAC8043 interface // make PS7,PS6,PS5 outputs void DAC8043_Init(void){ // PS7=LD=1 DDRS = 0xE0; // PS6=CLK=0 PORTS = 0x80; // PS5=SRI=0 } //******** DAC8043_Out *************** // Output 12-bit code to DAC8043 // 0<=code<=4095 // uses bit banging technique void DAC8043_Out(unsigned short code){ int n; for(n=0;n<12;n++){ PORTS &= ~0x40; // PS6=CLK=0 if(code&0x0800) // msb in bit 11 PORTS |= 0x20; // PS5=SRI=1 else PORTS &= ~0x20; // PS5=SRI=0 PORTS |= 0x40; // PS6=CLK=1 code = code<<1; } PORTS &= ~0x40; // PS6=CLK=0 PORTS &= ~0x80; // PS7=LD=0 PORTS |= 0x80; // PS7=LD=1 }