有没有大神用过PIC32的,麻烦帮我看下这段代码是什么意思,非常感谢,本人没接触过PIC32.
#define TRIS_DOCI2 TRISDbits.TRISD13 //Direction control of µC port DOCI2
#define DOCIL2 _LATD13 // latch Register for µC-output „DOCI2“
#define DOCI2HIGH _LATD12 //output to control external P-channel FET
DOCI2HIGH = 1; // disconnecting the pullup
unsigned int ReadDoci2(unsigned int *Temperature)
{
unsigned int i, ADC, k = 0;
DOCIL = 0; // Latch of port -> Low on DOCI2
TRIS_DOCI = 1; // DOCI2 port -> enabling as input
delay();
while (!DOCI2) ; // waiting for DOCI high from sensor device
delay_us(60); // delay t S (min 2*1/Fclk)
k=0;
for (i=0; i < 31; i++)
{
k = k<<1;
DOCIL2 = 0; // latch of port -> Low on DOCI2
TRIS_DOCI2 = 0; // DOCI2 port -> enabling as output
delay_us(1); // delay time t L min 200ns
TRIS_DOCI2 = 1; // DOCI2 port -> enabling as input
DOCI2HIGH = 0; // connecting the pullup -> High on DOCI
delay(); // delay time t H min 200ns to get high level on DOCI
DOCI2HIGH = 1; // disconnecting the pullup
Delay_us(2); // delay time min 1us
k |= DOCI2?1:0; // merge DOCI-Input to existing data
}
DOCIL2 = 0; // latch of port -> Low on DOCI2
TRIS_DOCI2 = 0; // DOCI2 port -> enabling as output , force low on DOCI
delay(); // delay time min 200ns
TRIS_DOCI2 = 1; // DOCI2 port -> enabling as input , release DOCI
*Temperature = (unsigned short) (k & 0x3FFF);
// writes temperature part into “Temperature” variable
return k; // gives whole value back
} |