main.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "sys.h"
  4. #include "stm32f10x.h"
  5. #include "stdio.h"
  6. #include "usart.h"
  7. #include "adc.h"
  8. #include "oled.h"
  9. #include "ds18b20.h"
  10. #include "HX711.h"
  11. #define HwInput PBin(7) //红外传感器输入
  12. #define KEY1 PAin(0) // 手动控制加热
  13. #define JR_OUT_PIN PBout(12) //控制加热输出
  14. #define CS_OUT_PIN PBout(13) //控制出水 电磁阀
  15. void Hw_Init(void)
  16. {
  17. GPIO_InitTypeDef GPIO_InitStructure;
  18. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能端口时钟
  19. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; // 端口配置
  20. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //上拉输入
  21. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
  22. GPIO_Init(GPIOB, &GPIO_InitStructure); //根据设定参数初始化GPIOC13
  23. }
  24. //void TIM2_IRQHandler()
  25. //{
  26. // static u8 st;
  27. // st=TIM_GetFlagStatus(TIM2, TIM_IT_Update);
  28. // if(st!=0)
  29. // {
  30. // TIM_ClearFlag(TIM2, TIM_IT_Update);
  31. // }
  32. //}
  33. //测距
  34. int temp_val=0;
  35. u16 get_cnt=0;
  36. char showbuff[16]={0};
  37. int main(void)
  38. {
  39. NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
  40. delay_init(); //延时函数初始化
  41. LED_Init(); //初始化与LED连接的硬件接口
  42. uart_init(9600);
  43. // ADC1_Init();
  44. delay_ms(500);
  45. OLED_Init();
  46. OLED_Clear();
  47. OLED_ShowString(0,2,(u8*)"2322352",16); //显示
  48. DS18B20_Init();
  49. OLED_ShowText(0,0,"和你在一起好快乐",0);
  50. // sprintf(showbuff,"temp:%2d.%1d",temp_val/10,temp_val%10); //打印成字符串
  51. // OLED_ShowString(0,2,(u8*)showbuff,16); //显示
  52. buzz=1;
  53. while(1)
  54. {
  55. if(++get_cnt>100) //采集时间计数器
  56. {
  57. get_cnt=0;
  58. temp_val = DS18B20_Get_Temp();//采集温度值
  59. sprintf(showbuff,"temp:%2d.%1d",temp_val/10,temp_val%10); //打印成字符串
  60. OLED_ShowString(0,4,(u8*)showbuff,16); //显示
  61. }
  62. delay_ms(5);//延时
  63. }
  64. }