打印
[MCU]

求大神帮忙看下PIC32的代码

[复制链接]
505|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
wc1111|  楼主 | 2018-8-30 15:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
有没有大神用过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
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

0

粉丝