u32 Read_CS1237(void) // reading chip, return +/- dat
{
u8 i;
u32 dat=0; // reading dat
u8 count_i=0; // timer cnt
DOUT = 1; // dat io lock 1, 51 must be do
SCLK = 0; // timer pull dowm
while(DOUT == 1) // dat ready for output
{
Delay_ms(5);
count_i++;
if(count_i > 300)
{
SCLK = 1;
DOUT = 1;
return 0; // timer overflow, break
}
}
DOUT = 1; //dat io lock 1,51 must be do
dat=0;
for(i=0;i<24;i++) // getting 24 bit dat
{
SCLK = 1;
Delay_us(48);
dat <<= 1;
if(DOUT == 1)
dat ++;
SCLK = 0;
Delay_us(48);
}
for(i=0;i<3;i++) // 27 clk input in all
{
// One_CLK;
SCLK = 1;Delay_us(48);
SCLK = 0;Delay_us(48);
}
// DAT_1;
i = 24 - ADC_Bit; //i is the to be delete bit
dat >>= i;
return dat;
}
//***********************config the uart 1#
void Config_UART()
{
SCON = 0X50; // uart 1 working in 8 bit model, baud changeable Bin 0101 0000
T2L = 0XE0; // the baud rate is 9600, main fosc @ 11.0592
T2H = 0XFE;
AUXR |= 0X01; // set tmr2 as the uart 1# baud generator Bin 0000 0001
AUXR |= 0X04; // set tmr2 as 1t model Bin 0000 0100
AUXR |= 0X10; // start the T2 Bin 0001 0000
ES = 1; // enable the interrupt
}
//*********************** the uart 1# send bit data