STM32水质检测仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include "stm32f10x.h"
- #include "bsp-lcd1602.h"
- #include "delay.h"
- #include "sys.h"
- #include "adc.h"
- char PH_High = 7;
- char zuodu_High = 50;
- void LED( void )
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_SetBits( GPIOA,GPIO_Pin_10 );
-
- }
- int main(void)
- {
- int ADC_num;
- int temp1,temp2;
-
- ADC1_GPIO_Config();
- ADC_Config();
- LCD1602_Init();
- LCD1602_ShowStr(0,1,"zd_S:50% PH_S:7",15);
- LCD1602_ShowStr(0,0,"zd: PH: ",15);
- LED();
-
- while(1)
- {
- ADC_num=Get_ADC(ADC_Channel_0);
- temp1=ADC_num*100/4096;
- LCD1602_WriteCmd( 0x80 + 3 );
- LCD1602_WriteDat( temp1/10 + 0x30 );
- LCD1602_WriteDat( temp1%10 + 0x30 );
- LCD1602_WriteDat( '%' );
-
- ADC_num=Get_ADC(ADC_Channel_1);
- temp2=ADC_num*10/4096;
- LCD1602_WriteCmd( 0x80 + 13 );
- LCD1602_WriteDat( temp2 + 0x30 );
-
- if(( temp1 >= 50 )||( temp2 >= 7 ))
- {
- GPIO_ResetBits( GPIOA,GPIO_Pin_10 );
- }
- else
- {
- GPIO_SetBits( GPIOA,GPIO_Pin_10 );
- }
- }
- }
- 3、main函数
- #include "stm32f10x.h"
- #include "bsp-lcd1602.h"
- #include "delay.h"
- #include "sys.h"
- #include "adc.h"
- char PH_High = 7;
- char zuodu_High = 50;
- void LED( void )
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_SetBits( GPIOA,GPIO_Pin_10 );
-
- }
- int main(void)
- {
- int ADC_num;
- int temp1,temp2;
-
- ADC1_GPIO_Config();
- ADC_Config();
- LCD1602_Init();
- LCD1602_ShowStr(0,1,"zd_S:50% PH_S:7",15);
- LCD1602_ShowStr(0,0,"zd: PH: ",15);
- LED();
-
- while(1)
- {
- ADC_num=Get_ADC(ADC_Channel_0);
- temp1=ADC_num*100/4096;
- LCD1602_WriteCmd( 0x80 + 3 );
- LCD1602_WriteDat( temp1/10 + 0x30 );
- LCD1602_WriteDat( temp1%10 + 0x30 );
- LCD1602_WriteDat( '%' );
-
- ADC_num=Get_ADC(ADC_Channel_1);
- temp2=ADC_num*10/4096;
- LCD1602_WriteCmd( 0x80 + 13 );
- LCD1602_WriteDat( temp2 + 0x30 );
-
- if(( temp1 >= 50 )||( temp2 >= 7 ))
- {
- GPIO_ResetBits( GPIOA,GPIO_Pin_10 );
- }
- else
- {
- 所有资料51hei提供下载:
- GPIO_SetBits( GPIOA,GPIO_Pin_10 );
- }
- }
- }
复制代码
Keil代码与Proteus仿真下载(注意版本号):
Keil5版本:
程序.7z
(185.48 KB, 下载次数: 428)
|