网站大量收购独家精品文档,联系QQ:2885784924

stm8读sht21(STM8读SHT21).doc

  1. 1、本文档被系统程序自动判定探测到侵权嫌疑,本站暂时做下架处理。
  2. 2、如果您确认为侵权,可联系本站左侧在线QQ客服请求删除。我们会保证在24小时内做出处理,应急电话:400-050-0827。
  3. 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(

文档评论(0)

f8r9t5c + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8000054077000003

1亿VIP精品文档

相关文档