📄 da2534.c
字号:
//-----------------------------------------
word TLC2543_Access(byte write_to_2543)
//AD cnd write and read the result of last conversion
//Input : write_to_2543 -- command write to AD.
//Output: read_from_2543 -- AD conversion result
// of last time
{
unsigned int read_from_2543=0;
SPCR=0x50;
io_ad_cs=1;
io_ad_cs=0;
read_from_2543 = SPI_MasterTransmit(write_to_2543);
read_from_2543 <<= 8;
read_from_2543 |=SPI_MasterTransmit(0);
//last clock down to EOC need typical 1.5us max 2.2us
#asm("nop\nop\nop\nop\nop")
#asm("nop\nop\nop\nop\nop")
#asm("nop\nop\nop\nop\nop")
#asm("nop\nop\nop\nop\nop")
io_ad_cs=1;
return(read_from_2543);
}
//-----------------------------------------
//-----------------------------------------
byte SPI_MasterTransmit(byte bData)
//CPU master SPI access
//Input : bData -- SPI write data
//Output: SPI read result
{
SPDR = bData;
while(!(SPSR & 0x80));
return SPDR;
}
//-----------------------------------------
//-----------------------------------------
word ADReadV(void)
// Read Pin-V, AD channel 9
// 读取精度为1mV,有效精度为2.5mV,范围0~10V
{
word i,j;
TLC2543_Access(ad_cnt_channel9);
while(io_ad_eoc==LOW); //Conversion typical time 10us LOW
i=TLC2543_Access(ad_cnt_channel9);
i=i>>3;
j=i>>2;
i=i+j;
return(i);
}
//-----------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -