芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

飞芯科技-芯片解密|单片机解密|IC解密|芯片破解|芯片复制| PCB抄板|软件开发

单片机解密STM32单片机的IIC读取AHT20 AHT21温湿度

  1. 单片机解密#include "stm32f10x.h"
  2. 单片机解密#include "AHT20-21_DEMO_V1_3.h"




  3. void Delay_N10us(uint32_t t)//延时函数
  4. {
  5.   uint32_t k;

  6.    while(t--)
  7.   {
  8.     for (k = 0; k < 2; k++);//110
  9.   }
  10. }

  11. void SensorDelay_us(uint32_t t)//延时函数
  12. {
  13.                
  14.         for(t = t-2; t>0; t--)
  15.         {
  16.                 Delay_N10us(1);
  17.         }
  18. }

  19. void Delay_4us(void)                //延时函数
  20. {        
  21.         Delay_N10us(1);
  22.         Delay_N10us(1);
  23.         Delay_N10us(1);
  24.         Delay_N10us(1);
  25. }
  26. void Delay_5us(void)                //延时函数
  27. {        
  28.         Delay_N10us(1);
  29.         Delay_N10us(1);
  30.         Delay_N10us(1);
  31.         Delay_N10us(1);
  32.         Delay_N10us(1);

  33. }

  34. void Delay_1ms(uint32_t t)                //延时函数
  35. {
  36.    while(t--)
  37.   {
  38.     SensorDelay_us(1000);//////延时1ms
  39.   }
  40. }


  41. void AHT20_Clock_Init(void)                //延时函数
  42. {
  43.         RCC_APB2PeriphClockCmd(CC_APB2Periph_GPIOB,ENABLE);
  44. }

  45. void SDA_Pin_Output_High(void)   //将PB15配置为输出 , 并设置为高电平, PB15作为I2C的SDA
  46. {
  47.         GPIO_InitTypeDef  GPIO_InitStruct;
  48.         GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
  49.         GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
  50.         GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  51.         GPIO_Init(GPIOB,& GPIO_InitStruct);
  52.         GPIO_SetBits(GPIOB,GPIO_Pin_15);
  53. }

  54. void SDA_Pin_Output_Low(void)  //将P15配置为输出  并设置为低电平//SDA配置为浮空输出
  55. {

  56.         GPIO_InitTypeDef  GPIO_InitStruct;
  57.         GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
  58.         GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
  59.         GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  60.         GPIO_Init(GPIOB,& GPIO_InitStruct);
  61.         GPIO_ResetBits(GPIOB,GPIO_Pin_15);
  62. }

  63. void SDA_Pin_IN_FLOATING(void)  //SDA配置为浮空输入
  64. {

  65.         GPIO_InitTypeDef  GPIO_InitStruct;
  66.         GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;//
  67.         GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
  68.         GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
  69.         GPIO_Init( GPIOB,&GPIO_InitStruct);
  70. }

  71. void SCL_Pin_Output_High(void) //SCL输出高电平,P14作为I2C的SCL
  72. {
  73.         GPIO_SetBits(GPIOB,GPIO_Pin_14);
  74. }



联系方式

地址:石家庄市新华区民族路77号华强广场D座2009
电话:0311-88816616/87087811
手机:13315190088
传真:0311-67901001
联系人:张工
网址:www.feixindz.com
邮箱:feixindz@163.com
微信:xinpianjiemi
QQ:527263666/568069805

在线客服
热线电话

企业微信