void analog_output() //d1 input from do_next_ao //d1 contains data and d2 contains channel number { uint8_t byte; unsigned short int d1 = 0x7FF; //value changed on 19/3 on 4.18pm//changed by seeing the datasheet previous value 7ff printInt(ReadByte(a6,ao_data)); byte = 0xCF & ReadByte(a6,ao_data); WriteByte(a6,ao_data,byte); //make ENEXP and ENLOC to 0 printInt(byte); printInt(ReadByte(a6,ao_data)); delay_us(3); //d1 = _rotlhw(d1,4);//hi nibble //ns/ls/0/ms WriteByte(a6,ao_data,(d1 >> 8) & 0x0f); //output Ms printInt(d1 >> 8 & 0xf); printInt(ReadByte(a6,ao_data)); //added on 15/3/2018 delay_us(3); WriteByte(a6,ao_cntl,0x3 | 0x08); //added this code on 19/3/2018 to set muxen bit high delay_us(1); printInt(ReadByte(a6,ao_cntl)); WriteByte(a6,ao_cntl,2 | 0x08); //strobe msb delay_us(1); printInt(ReadByte(a6,ao_cntl)); delay_us(1); printInt(ReadByte(a6,ao_cntl)); //added on 15/3/2018 // d1 = d1 >> 8; //0/00/ns/ls WriteByte(a6,ao_data, (d1 >> 4 & 0x0f) | 0x40); //middle nibble printInt((d1 >> 4 & 0x0f)); printInt(ReadByte(a6,ao_data)); //added on 15/3/2018 delay_us(3); WriteByte(a6,ao_cntl,3 | 0x08); //strobe msb delay_us(1); printInt(ReadByte(a6,ao_cntl)); //added on 15/3/2018 WriteByte(a6,ao_cntl,2 | 0x08); delay_us(1); printInt(ReadByte(a6,ao_cntl)); //added on 15/3/2018 WriteByte(a6,ao_data,(d1 & 0x0f) | 0x80 ); //output lsb //alt_putstr("\nDAC nibble3:"); printInt(d1 & 0x0f); printInt(ReadByte(a6,ao_data)); //added on 15/3/2018 delay_us(3); WriteByte(a6,ao_cntl,3 | 0x08 ); //strobe msb delay_us(1); printInt(ReadByte(a6,ao_cntl)); //added on 15/3/2018 WriteByte(a6,ao_cntl,2 | 0x08); delay_us(1); printInt(ReadByte(a6,ao_cntl)); //added on 15/3/2018 WriteByte(a6,ao_data,0); //Changed the channel number on 8.15pm //output mux delay_us(3); WriteByte(a6,ao_data,0xd0); //changed the channel number on 8.15pm //output ena printInt(ReadByte(a6,ao_data)); //added on 15/3/2018 }