当前位置:网站首页>[IO Development Notes] smart cloud intelligent watering device practice (1) - Basic demo implementation
[IO Development Notes] smart cloud intelligent watering device practice (1) - Basic demo implementation
2022-07-26 22:31:00 【gizwits_ csdn】





- #include "led.h"
- #include "systick.h"
- void LED_Init(void)
- {
- RCC_APB2PeriphClockCmd(LED1_CLK, ENABLE);
- RCC_APB2PeriphClockCmd(LED2_CLK, ENABLE);
- RCC_APB2PeriphClockCmd(LED3_CLK, ENABLE);
- GPIO_InitTypeDef LED_InitStruct = {0};
- LED_InitStruct.GPIO_Pin = LED1_PIN;
- LED_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
- LED_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(LED1_PORT, &LED_InitStruct);
- LED_InitStruct.GPIO_Pin = LED2_PIN;
- GPIO_Init(LED2_PORT, &LED_InitStruct);
- LED_InitStruct.GPIO_Pin = LED3_PIN;
- GPIO_Init(LED3_PORT, &LED_InitStruct);
- LED1(0);
- LED2(0);
- LED3(0);
- }
- void LED_Task(void)
- {
- static uint32_t Timer = 0;
- static uint8_t Sta = 0;
- if(SoftTimer(Timer,500))
- {
- Timer=GetSoftTimer();
- Sta?(Sta=0):(Sta=1);
- LED1(Sta);
- LED2(Sta);
- LED3(Sta);
- }
- }
- void GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
- {
- uint32_t ODR;
- ODR = GPIOx->ODR;
- GPIOx->BSRR = ((ODR & GPIO_Pin) << 16U) | (~ODR & GPIO_Pin);
- }
- #ifndef __LED_H_
- #define __LED_H_
- #include "STM32f10x.h"
- //PB9 --- LED1 --- Low efficiency
- //PB8 --- LED2 --- Low efficiency
- //PA3 --- LED3 --- Low efficiency
- // be based on STM32 Standard library The chip is STM32F103C8T6
- #define LED1_CLK RCC_APB2Periph_GPIOB
- #define LED1_PORT GPIOB
- #define LED1_PIN GPIO_Pin_9
- #define LED2_CLK RCC_APB2Periph_GPIOB
- #define LED2_PORT GPIOB
- #define LED2_PIN GPIO_Pin_8
- #define LED3_CLK RCC_APB2Periph_GPIOA
- #define LED3_PORT GPIOA
- #define LED3_PIN GPIO_Pin_3
- // A switch defined by a macro
- #define LED1(X) X?(GPIO_ResetBits(LED1_PORT,LED1_PIN)):(GPIO_SetBits(LED1_PORT,LED1_PIN))
- #define LED2(X) X?(GPIO_ResetBits(LED2_PORT,LED2_PIN)):(GPIO_SetBits(LED2_PORT,LED2_PIN))
- #define LED3(X) X?(GPIO_ResetBits(LED3_PORT,LED3_PIN)):(GPIO_SetBits(LED3_PORT,LED3_PIN))
- void LED_Init(void);
- void GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
- void LED_Task(void);
- #endif

- #include "key.h"
- #include "systick.h"
- void KEY_Init(void)
- {
- RCC_APB2PeriphClockCmd(KEY0_CLK,ENABLE);
- RCC_APB2PeriphClockCmd(KEY1_CLK,ENABLE);
- RCC_APB2PeriphClockCmd(KEY2_CLK,ENABLE);
- GPIO_InitTypeDef KEY_InitStruct;
- KEY_InitStruct.GPIO_Pin = KEY0_PIN|KEY1_PIN|KEY2_PIN;
- KEY_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
- KEY_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(KEY0_PORT ,&KEY_InitStruct);
- GPIO_Init(KEY1_PORT ,&KEY_InitStruct);
- GPIO_Init(KEY2_PORT ,&KEY_InitStruct);
- }
- static uint8_t Key0Value=0;
- static uint8_t Key1Value=0;
- static uint8_t Key2Value=0;
- void KeyScan(void)
- {
- static uint16_t Key0Timer=0;
- static uint16_t Key1Timer=0;
- static uint16_t Key2Timer=0;
- if(KEY0==0)
- {
- if(Key0Timer<10)
- {
- Key0Timer++;
- if(Key0Timer>=10)
- Key0Value=1;
- }
- }
- else
- {
- Key0Timer = 0;
- }
- if(KEY1==0)
- {
- if(Key1Timer<10)
- {
- Key1Timer++;
- if(Key1Timer>=10)
- Key1Value=1;
- }
- }
- else
- {
- Key1Timer = 0;
- }
- if(KEY2==0)
- {
- if(Key2Timer<10)
- {
- Key2Timer++;
- if(Key2Timer>=10)
- Key2Value=1;
- }
- }
- else
- {
- Key2Timer = 0;
- }
- }
- uint8_t GetKey0(void)
- {
- uint8_t Key=Key0Value;
- Key0Value=0;
- return Key;
- }
- uint8_t GetKey1(void)
- {
- uint8_t Key=Key1Value;
- Key1Value=0;
- return Key;
- }
- uint8_t GetKey2(void)
- {
- uint8_t Key=Key2Value;
- Key2Value=0;
- return Key;
- }
- #ifndef __KEY_H_
- #define __KEY_H_
- #include "stm32f10x.h"
- #define KEY0_CLK RCC_APB2Periph_GPIOA
- #define KEY0_PORT GPIOA
- #define KEY0_PIN GPIO_Pin_0
- #define KEY1_CLK RCC_APB2Periph_GPIOA
- #define KEY1_PORT GPIOA
- #define KEY1_PIN GPIO_Pin_1
- #define KEY2_CLK RCC_APB2Periph_GPIOA
- #define KEY2_PORT GPIOA
- #define KEY2_PIN GPIO_Pin_2
- #define KEY0 GPIO_ReadInputDataBit(KEY0_PORT,KEY0_PIN)
- #define KEY1 GPIO_ReadInputDataBit(KEY1_PORT,KEY1_PIN)
- #define KEY2 GPIO_ReadInputDataBit(KEY2_PORT,KEY2_PIN)
- void KEY_Init(void);
- void KeyScan(void);
- uint8_t GetKey0(void);
- uint8_t GetKey1(void);
- uint8_t GetKey2(void);
- #endif
- <b>
- </b>
- #include "main.h"
- int main(void)
- {
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- USART1_Init(9600);
- //printf(" Print serial port initialization OK !\r\n");
- SysTick_Init();
- //printf(" The system clicks to initialize OK !\r\n");
- LED_Init();
- //printf(" Status indication initialization OK !\r\n");
- KEY_Init();
- //printf(" Key configuration initialization OK !\r\n");
- while(1)
- {
- LED_Task();
- if(GetKey0())
- {
- GPIO_TogglePin(LED1_PORT,LED1_PIN);
- //JiaoHua(1-currentDataPoint.valueRelay_1);
- }
- if(GetKey1())
- {
- GPIO_TogglePin(LED2_PORT,LED2_PIN);
- //gizwitsSetMode(WIFI_AIRLINK_MODE);
- // Press the key to enter the distribution network mode
- }
- if(GetKey2())
- {
- GPIO_TogglePin(LED3_PORT,LED3_PIN);
- }
- }
- }
- #include "usart1.h"
- #include <stdio.h>
- void USART1_NVIC_Config(void)
- {
- // Receive interrupt enable
- NVIC_InitTypeDef NVIC_InitStruct;
- /*NVIC Controller configuration */
- NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn;// Specific interrupt source name
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;//NVIC Response channel enable
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;// Preemption priority value
- NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;// Response priority value
- NVIC_Init(&NVIC_InitStruct);
- }
- /* Print debug serial port */
- void USART1_Init(uint32_t BaudRate)
- {
- USART_DeInit(USART1);
- //1. open GPIO The clock of
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
- //2. Configure related structures
- GPIO_InitTypeDef GPIO_InitStruct;
- // Configuration of serial port sending pin PA9-> Multiplexing push pull output
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA,&GPIO_InitStruct);
- // Configuration of serial port receiving pin PA10-> Floating input mode
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;// Floating input mode
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA,&GPIO_InitStruct);
- //1. Turn on the clock of the serial port
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);// Be careful APB2
- USART_InitTypeDef USART1_InitStruct;
- // Serial port parameter configuration The baud rate can be changed
- // No hardware flow control Transceiver mode
- //1 Start bit 8 Data bits No parity 1 Bit stop bit
- USART1_InitStruct.USART_BaudRate = BaudRate;
- USART1_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
- USART1_InitStruct.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
- USART1_InitStruct.USART_Parity = USART_Parity_No;
- USART1_InitStruct.USART_StopBits = USART_StopBits_1;
- USART1_InitStruct.USART_WordLength = USART_WordLength_8b;
- // A serial port 1 initialization
- USART_Init(USART1,&USART1_InitStruct);
- /*******************/
- // Open serial port interrupt
- USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);// Receive interrupt
- //USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);// Idle interrupt
- // Interrupt priority configuration
- USART1_NVIC_Config();
- USART_Cmd(USART1,ENABLE);
- }
- /* Serial port redirection function The goal is to make STM32 Support printf("%d %x %c ")*/
- int fputc(int ch , FILE *stream)
- {
- while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
- USART_SendData(USART1,(uint16_t) ch); // Data is sent through serial port
- while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
- return ch;
- }
- #ifndef __USART1_H_
- #define __USART1_H_
- #include "stm32f10x.h"
- void USART1_Init(uint32_t BaudRate);
- #endif
- #include "systick.h"
- #include "key.h"
- uint32_t mySysTick_Config(uint32_t ticks)
- {
- if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */
- SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */
- NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Cortex-M0 System Interrupts */
- SysTick->VAL = 0; /* Load the SysTick Counter Value */
- SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
- SysTick_CTRL_TICKINT_Msk |
- SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
- return (0); /* Function successful */
- }
- void SysTick_Init(void)
- {
- //SystemInit();
- SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
- mySysTick_Config(SystemCoreClock/1000);
- }
- void SysTick_Handler(void)
- {
- SystemTick();
- KeyScan();
- }
- static uint32_t Ticks=0;
- void SystemTick(void)
- {
- Ticks++;
- }
- uint32_t GetSoftTimer(void)
- {
- return Ticks;
- }
- uint8_t SoftTimer(uint32_t BaseTimer,uint32_t Timeout)
- {
- if(Ticks>=BaseTimer)
- return (Ticks)>=Timeout+BaseTimer;
- return (Ticks+0xFFFFFF)>=Timeout+BaseTimer;
- }
Smart cloud intelligent watering device actual combat (2)- Basics Demo Realization -
Relay implementation / A functional test /DHT11 Driver code implementation /OLED The screen displays sensor data / Chinese font making and so on
边栏推荐
- 调试stc8a8k64d4单片机485通信总结
- 『MongoDB』你想要的MongoDB基本操作这里都有
- 【Io开发笔记】机智云智能浇花器实战(3)-自动生成代码移植
- 30000 hair loss people, supporting an IPO
- 09.01 深度优先搜索
- systemctl命令
- Blog Garden beautification skills summary
- MySQL recommendation
- Y78. Chapter IV Prometheus' monitoring system and practice -- Prometheus' service discovery mechanism (IX)
- 浮动引起的高度塌陷问题
猜你喜欢

小白学习MySQL - Derived Table

At the 100 billion yogurt track, dairy giants and new brands have started a tug of war

7.27抢先看 | openEuler 志高远,开源汇智创未来-开放原子全球开源峰会欧拉分论坛最详细议程出炉

IDEA的那些环境配置及插件

mysql推荐书

Leetcode 122: the best time to buy and sell stocks II

LeetCode 122:买卖股票的最佳时机 II

Module 8 (message queue MySQL table storing message data)

新兴市场潜力无限,ADVANCE.AI风控产品助中国出海企业筑牢安全发展基础

VCS编译、仿真过程
随机推荐
【Qt多线程之线程的等待和唤醒】
Luo Yonghao bet on the last entrepreneurial credit
MySQL数据库介绍
Which is better, caiqian school or qiniu school? Is it safe
恋爱时各个顺序整理(历时两个月详细整理)
systemctl命令
IDEA的那些环境配置及插件
View绘制流程1-View与Window的关系
博客园美化技巧汇总
Leetcode:857. Minimum cost of employing K workers [think in blocks + start with simplicity]
Leetcode 121: the best time to buy and sell stocks
Makefile相关语法总结(Openc910)
国信证券手机开户收费吗?开户安全吗?
Concept and classification of processes
【Try to Hack】防火墙(一)
在灯塔工厂点亮5G,宁德时代抢先探路中国智造
2022年最新西藏建筑安全员模拟题库及答案
Does Guosen Securities charge for opening a mobile account? Is it safe to open an account?
After changing the password in MySQL under win10, the problem of sudden login failure is solved
判断numpy array数组的维数