资源简介
C51和STC15用I2C操作MPL3115A2串口显示,测量高度和温度.ct1668显示.
#include
#include
#include "ct1668.h"
#define uchar unsigned char
sbit SCL=P1^0;
sbit SDA=P1^1;
#include
#include
#include "ct1668.h"
#define uchar unsigned char
sbit SCL=P1^0;
sbit SDA=P1^1;

代码片段和文件信息
#include
#include
#include “ct1668.h“
#define uchar unsigned char
sbit SCL=P1^0;
sbit SDA=P1^1;
void Delay5us()
{
unsigned char i; //若使用12T芯片,直接写一个空函数,实现5us延时
_nop_();
i = 15;
while (--i);
}
void Start()
{
SDA=1;
Delay5us();
SCL=1;
Delay5us();
SDA=0;
Delay5us();
}
void Stop()
{
SDA=0;
Delay5us();
SCL=1;
Delay5us();
SDA=1;
Delay5us();
}
void Respons() //应答
{
uchar i;
SCL=1;
Delay5us();
while((SDA==1)&&(i<250))i++;
SCL=0;
Delay5us();
}
void Init_mpl3115()
{
SDA=1;
Delay5us();
SCL=1;
Delay5us();
}
void Write_Byte(uchar date)
{
uchar itemp;
temp=date;
for(i=0;i<8;i++)
{
temp=temp<<1;
SCL=0;
Delay5us();
SDA=CY;
Delay5us();
SCL=1;
Delay5us();
}
SCL=0;
Delay5us();
SDA=1;
Delay5us();
}
uchar Read_Byte()
{
uchar ik;
SCL=0;
Delay5us();
SDA=1;
Delay5us();
for(i=0;i<8;i++)
{
SCL=1;
Delay5us();
k=(k<<1)|SDA;
SCL=0;
Delay5us();
}
return k;
}
void Write_mpl3115(uchar addressuchar shuju)
{
Start();
Write_Byte(0xC0); //最低位为0写,1读
Respons();
Write_Byte(address);
Respons();
Write_Byte(shuju);
Respons();
Stop();
}
uchar Read_mpl3115(uchar address)
{
uchar date;
Start();
Write_Byte(0xC0);
Respons();
Write_Byte(address);
Respons();
Start();
Write_Byte(0xC1);
Respons();
date=Read_Byte();
Stop();
return date;
}
void Delay1000ms() //@11.0592MHz
{
unsigned char i j k;
_nop_();
_nop_();
i = 43;
j = 6;
k = 203;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
void SendData(unsigned char dat)
{ SBUF = dat;
while (!TI);
TI = 0;
}
/*void SendString(char *s)
{
while (*s)
{
SendData(*s++);
}
}*/
void UartInit(void) //9600bps@11.0592MHz
{
SCON = 0x50; //8位数据可变波特率
AUXR |= 0x01; //串口1选择定时器2为波特率发生器
AUXR |= 0x04; //定时器2时钟为Fosc即1T
T2L = 0xE0; //设定定时初值
T2H = 0xFE; //设定定时初值
AUXR |= 0x10; //启动定时器2
}
void main(void)
{ uchar high1high2high3temp1temp2;
UartInit();
P1M0 = 0x00;
P1M1 = 0x00;
Init_mpl3115();
Write_mpl3115(0x260xb8);
Write_mpl3115(0x130x07);
Write_mpl3115(0x260xB9);
while(1)
{
high1=Read_mpl3115(0x01);
high2=Read_mpl3115(0x02);
high3=Read_mpl3115(0x03);
temp1=Read_mpl3115(0x04);
temp2=Read_mpl3115(0x05);
SendData(high2);
SendData(temp1);
display(high2temp1);
Delay1000ms();
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-03-08 21:19 mpl3115a2\
文件 6376 2012-06-15 10:41 mpl3115a2\STARTUP.A51
文件 14049 2020-03-08 16:38 mpl3115a2\STARTUP.LST
文件 749 2020-03-08 16:38 mpl3115a2\STARTUP.OBJ
文件 2276 2020-03-08 21:17 mpl3115a2\ct1668.h
文件 15974 2020-03-08 21:17 mpl3115a2\mpl
文件 18893 2020-03-08 21:17 mpl3115a2\mpl.M51
文件 2013 2020-03-08 21:17 mpl3115a2\mpl.hex
文件 58 2020-03-08 21:17 mpl3115a2\mpl.lnp
文件 2011 2020-03-08 21:19 mpl3115a2\mpl.plg
文件 68529 2020-03-08 21:19 mpl3115a2\mpl.uvgui.Administrator
文件 68526 2020-03-08 21:11 mpl3115a2\mpl.uvgui_Administrator.bak
文件 5318 2020-03-08 21:19 mpl3115a2\mpl.uvopt
文件 13529 2020-03-08 21:11 mpl3115a2\mpl.uvproj
文件 6668 2020-03-08 21:17 mpl3115a2\mpl3115.LST
文件 17273 2020-03-08 21:17 mpl3115a2\mpl3115.OBJ
文件 46 2020-03-08 21:17 mpl3115a2\mpl3115.__i
文件 2977 2020-03-08 21:17 mpl3115a2\mpl3115.c
文件 5319 2020-03-08 21:11 mpl3115a2\mpl_uvopt.bak
文件 13361 2020-03-08 18:26 mpl3115a2\mpl_uvproj.bak
- 上一篇:maven pom最全配置
- 下一篇:USR-TCP232-Test.zip
相关资源
- 用DIO 做的I2C程式
- I2C总线接口设计
- 8051F040SMBUS多机通信
- DHT10_I2C驱动.zip
- I2C串行EEPROM应用系统的健壮性设计
- 电子-GravityI2C3.7V锂电池电量计stm32L1
- arduino主机,stm8从机。I2C测试 。每次
- 10位ADC转换器AD5612(stm32_IO口模拟I2C)
- (带有源代码)基于FPGA的模拟I2C接口
- I2C-verilog-(非常详细的i2c学习心得)
- stm32f103iic读取AT24XX全系eeprom
- 分享一个0.96的oled显示驱动,软件模拟
- DAC8571_I2C模式_STM32
- STM32F4 I2C从机中断
- ADS1110stm32驱动自带I2C驱动
- STM32F103C8 例程
- stm32 I2C主从机模式控制代码
- 基于STM32F103硬件I2C读写24Cxx驱动代码的
- Ginkgo_USB-I2C_Classic_Setup_v2.9.2.zip
- I2C从设备接收数据verilog代码实现
- CH341-I2C-labview-应用说明+VI-所有版本都
- Delphi2CPP 和注册机
- STM32_MPU6050DMP硬件I2C读取欧拉角
- 基于FPGA的EEPROM读写系统
- 用stm32硬件I2C和模拟I2C读写EEPROM
- 利用STM32硬件I2C使用加速度传感器AD
- STM32与HTU21的I2C通讯源码
- stm32f103硬件I2C主从通信
- sht20 程序
- 黑苹果i2c触摸驱动教程
评论
共有 条评论