Action
This statement will set the DAC output value on the XTINY platform.
Syntax
WRITEDAC value
Remarks
A DAC is a digital to analog converter.
Value is a constant or numeric variable. Xtinies have an 8 bit DAC. DA/DB series have a 10 bit DAC. The 10 bit model need a specific alignment of the bits. That is the reason this statement exists since on Xtiny it will write to the DAC0_DATA register which is 1 byte.
On the AVR128DB28 the DAC0_DATA register is a word register. The two LS bits of the value are located in bit 6 and 7 of the LSB. This means that the value you write must be shifted 6 places to the left and that is what WRITEDAC will do for the platforms that use a 10 bit DAC.
In order to use the DAC you must use the CONFIG DACx statement that will enable the DAC and will set the output pin to output mode.
And you need to set the voltage reference for the DAC using CONFIG VREF.
See also
Example
See the CONFIG DACx example.