- 1、本文档被系统程序自动判定探测到侵权嫌疑,本站暂时做下架处理。
- 2、如果您确认为侵权,可联系本站左侧在线QQ客服请求删除。我们会保证在24小时内做出处理,应急电话:400-050-0827。
- 3、此文档由网友上传,因疑似侵权的原因,本站不提供该文档下载,只提供部分内容试读。如果您是出版社/作者,看到后可认领文档,您也可以联系本站进行批量认领。
查看更多
stm8读sht21(STM8读SHT21)
stm8读sht21(STM8读SHT21)
#包括“stm8s_gpio。”
#包括“user_i2c。”
#包括“内联函数。”
#包括“stdio. h”
#包括“弦。”
无效delay_us(无符号短整数x)
{
无符号短i,j;
对于(i = 0;i x;+ +)
对于(j=0;j<1;j + +);
}
无效delay_ms(无符号短整数x)
{
无符号短i,j;
对于(i = 0;i x;+ +)
对于(j=0;j<1570;j + +);
}
#定义ACK 0
# NACK 1定义
#定义htu21addr 0x80
unsigned char handt [ 2 ];
unsigned char crc_flag = 0;
unsigned char crc_temp = 0;
无符号长整型数wendu_check_shidu = 0;
unsigned char lsbuf1 [ 10 ];
extern char sequen_num [ 20 ];//序列号
无效tmphum();
无符号字符;
/ / I2C启动函数
无效i2c_start()
{
gpio_init(gpioa,gpio_pin_1,gpio_mode_out_od_hiz_slow);// SDA输出高
gpio_writehigh(gpioa,gpio_pin_1);// SDA输出高
gpio_init(gpioa,gpio_pin_2,gpio_mode_out_pp_high_slow);// SCL输出高
gpio_writehigh(gpioa,gpio_pin_2);// SCL输出高
delay_us(4);//延时3.3us
gpio_writelow(gpioa,gpio_pin_1);// SDA输出低
delay_us(10);//延时6.6us
gpio_writelow(gpioa,gpio_pin_2);// SCL输出低
delay_us(4);//延时6.6us
gpio_writehigh(gpioa,gpio_pin_1);// SDA输出高
}
/ / I2C停止函数
无效i2c2_stop()
{
gpio_init(gpioa,gpio_pin_1,gpio_mode_out_pp_low_slow);// SDA输出低
gpio_writelow(gpioa,gpio_pin_1);// SDA输出低
gpio_init(gpioa,gpio_pin_2,gpio_mode_out_pp_low_slow);// SCL输出低
gpio_writelow(gpioa,gpio_pin_2);// SCL输出低
delay_us(4);//延时3.3us
gpio_writehigh(gpioa,gpio_pin_2);// SCL输出高
delay_us(10);//延时3.3us
gpio_writehigh(gpioa,gpio_pin_1);// SDA输出高
delay_us(4);//延时3.3us
gpio_writelow(gpioa,gpio_pin_2);// SCL输出低
}
8 /主发送从接收位数据+检测ACK函数
unsigned char i2c_tx(unsigned char i2c_tx_data)/发送一个字节+检测ACK
{
未签名字符;
gpio_init(gpioa,gpio_pin_2,gpio_mode_out_pp_low_slow);/ /推挽-输出低2M
gpio_writelow(gpioa,gpio_pin_2);// SCL输出低
对于(i = 0;i 8;i +)
{
如果(i2c_tx_data 0x80)
gpio_writehigh(gpioa,gpio_pin_1);// SDA输出高
其他的
{
gpio_writelow(gpioa,gpio_pin_1);// SDA输出低
gpio_init(gpioa,gpio_pin_1,gpio_mode_out_od_low_slow);/ /开漏-输出低2M
}
delay_us(10);//延时3.3us
gpio_writehigh(gpioa,gpio_pin_2);// SCL输出高
delay_us(20);//延时6.6us
gpio_writelow(gpioa,gpio_pin_2);// SCL输出低
delay_us(4);//延时3.3us
i2c_tx_data = 1;//向左移动一位
}
gpio_init(gpioa,gpio_pin_1,gpio_mode_in_fl_no_it);// SDA输入
gpio_writehigh(
您可能关注的文档
- bat 批处理延迟运行脚本(Bat batch running script).doc
- bh1750数字光照(Bh1750 digital light).doc
- beautiful smile and love美丽的微笑和爱心(美丽的微笑与爱心美丽的微笑和爱心).doc
- boys love 名言(男生的爱名言).doc
- bilibili入站测试(bilibili入站测试).doc
- bedzed(BedZED).doc
- bt3破解无线wep_wpa2(BT3 crack wireless wep_wpa2).doc
- bt下载狂热者分析各种破解方法(BT download enthusiasts analyze various crack methods).doc
- build.prop优化(build.prop优化).doc
- bp神经网络c语言实现(BP neural network, C language implementation).doc
文档评论(0)