smbus总线单片机c语言程序,C8051F I2C(SMBus)程序

/********************************************************************************************************

*

* File : ws_iic_port.h

* Hardware Environment:

* Build Environment : Silicon LABs 3.42.00 / uVision3 V3.80 20100913

* Version :

* By : Su Wei Feng

*

*                                                          (c) Copyright 2005-2010, WaveShare

*                                                                     https://www.waveshare.net

*                                                                         All Rights Reserved

*

*********************************************************************************************************/

#ifndef _WS_IIC_PORT_H_

#define _WS_IIC_PORT_H_

#define SMB_FREQUENCY 100000 // Target SCL clock rate

// This example supports in 100kHz

void SMBus_Init(void);

void Check_SDA(void);

void SMBus_Write(uint wrDAdr,uchar Data1,uchar Data2,uchar Num);

void SMBus_Read(uint wrDAdr,uchar *Data,uchar Num);

/*Hardware Environment:DVK501 && F320+ EX*/

#if defined(_DVK501_F320_EX_)

void Timer1_Init(void);

void Timer3_Init(void);

void Enb_Interrupt(void);

void SMBus_ISR(void);

void Timer3_ISR(void);

// 16-bit SFR declarations

sfr16 TMR3RL = 0x92; // Timer3 reload registers

sfr16 TMR3 = 0x94; // Timer3 counter registers

sbit SDA = P1^0; // SMBus on P1.0

sbit SCL = P1^1; // and P1.1

void SMBus_Init(void)

{

XBR0 |= 0x07; // Enable SMBus pins

P1MDOUT = 0x00; // All P1 pins open-drain output

P1 = 0xFF;

SMB0CF = 0x5D; // Use Timer1 overflows as SMBus clock source;

// Disable slave mode;

// Enable setup & hold time extensions;

// Enable SMBus Free timeout detect;

// Enable SCL low timeout detect;

SMB0CF |= 0x80; // Enable SMBus

Timer1_Init();

Timer3_Init();

}

void Timer1_Init(void)

{

// Make sure the Timer can produce the appropriate frequency i

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值