DAC work incorrectly when P0 is used as analog input.
when i use DAC to output voltage ,(no load), and then read voltage from channel 8 (p0.2),
I found when P0.0~p0.3 are used as analog-channel, the output of dac is wrong.
When P0.X are used as gpio, or SPI, the output voltage is correct.
When I set P0.X as analogue input, the output of DAC will be larger.
I don't know what is wrong ?
code is :
main()
{
DACCON = 0x0010; //ref=1.2V
DACDAT = 0x7000000;
GP0KEY1 = 0x7; //Write to GP0KEY1
GP0CON1 = 0x0; //p0.1: spi(0), i2c(1), p0.0 analog input(1), io(0)
GP0KEY2 = 0x13;
DelayMs(10); //delay in milli-second.
GP0KEY1 = 0x7; //Write to GP0KEY1
GP0CON1 = 0x1; //p0.1: spi(0), i2c(1), p0.0 analog input(1), io(0)
GP0KEY2 = 0x13;
DelayMs(10);
}
void DelayMs(long d)
{
long i, j;
for (j=0; j<d; j++)
{
for (i=0; i<900; i++)
{
T2CLRI = 0x55;
}
}
}