您的位置 首页 应用

MSP430F149单片机驱动DS2762读写操作C言语程序

基于MSP430F149单片机驱动DS2762读写操作C语言程序,能够对按键或着其他信号响应,读出电流以及电压量,并进行相应处理。includemsp4

根据MSP430F149单片机驱动DS2762读写操作C言语程序,可以对按键或着其他信号呼应,读出电流以及电压量,并进行相应处理。

//#include
#define uchar unsigned char
#define uint unsigned int
uint A,B,C,D,E,F,G,H,I,J;//此处对io430x14x中的宏界说C进行了注释,需留意
#define IO_OUT P3DIR |= BIT0;
#define IO_INP P3DIR &= ~BIT0;
uint data;
/******************************************************************************
对读写时刻进行规范化
初始调试选用standard=1的参数
// Pause for exactly tick number of ticks = 0.25us
实践测的A延时14Us
B125US
******************************************************************************/
void SetSpeed(uint standard)
{
// Adjust tick values depending on speed
if (standard)
{
// Standard Speed
A = 6 * 4 / 2;
B = 64 * 4 / 2;
C = 60 * 4 / 2;
D = 10 * 4 / 2;
E = 9 * 4 / 2;
F = 55 * 4 / 2;
G = 0 / 2;
H = 480 * 4 / 2;
I = 70 * 4 / 2;
J = 410 * 4 / 2;
}
else
{
// Overdrive Speed
A = 1.5 * 4;
B = 7.5 * 4;
C = 7.5 * 4;
D = 2.5 * 4;
E = 0.75 * 4;
F = 7 * 4;
G = 2.5 * 4;
H = 70 * 4;
I = 8.5 * 4;
J = 40 * 4;
}
}
/******************************************************************************
延时程序
留意,需求选用8M晶振,时钟周期125ns
******************************************************************************/
void tickDelay(uint tick) // Implementation is platform specific
{
for(;tick>0;tick–);
}
/******************************************************************************
主机复位脉冲
当接纳成果result为0时,标明从机应对
******************************************************************************/
uchar OWTouchReset(void)
{
uchar result;
IO_OUT;
tickDelay(G);
P30 = 0; // Drives DQ low
tickDelay(H);
P30 = 1; // Releases the bus
tickDelay(I);
IO_INP;
result = P3IN & 0X01; // Sample for presence pulse from slave
tickDelay(J); // Complete the reset sequence recovery
return result; // Return sample presence pulse result
}
/******************************************************************************
像写DS2762写入一位
Send a 1-Wire write bit. Provide 10us recovery time.
******************************************************************************/
void OWWriteBit(uchar bit)
{
if (bit)
{
// Write 1 bit
P30 = 0; // Drives DQ low
tickDelay(A);
P30 = 1; // Releases the bus
tickDelay(B); // Complete the time slot and 10us recovery
}
else
{
// Write 0 bit
P30 = 0; // Drives DQ low
tickDelay(C);
P30 = 1; // Releases the bus
tickDelay(D);
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/317298.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部