硬件设计
链接:https://pan.baidu.com/s/1hJ0fAhdI-9efiTeDu0cmTA
提取码:5wm3
仿真图如下所示:
程序设计
#include "stm32f10x.h"
#include "bsp-lcd1602.h"
#include "delay.h"
#include "sys.h"
#include "adc.h"
int main(void)
{
int ADC_num;
float temp;
ADC1_GPIO_Config();
ADC_Config();
delay_init(); //延时函数初始化
LCD1602_Init();
LCD1602_ShowStr(0,0,"Intelligent LED",15);
LCD1602_ShowStr(0,1," LED:",8);
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
while(1)
{
ADC_num=ADC_GetConversionValue(ADC1);
temp=ADC_num*(3.4/4096)*10;
//表示光线太弱
if( temp < 8 )
{
LCD1602_ShowStr(8,1,"Low ",4);
GPIO_ResetBits( GPIOC,GPIO_Pin_0 );
}
else
{
//光线合适
LCD1602_ShowStr(8,1,"OK ",4);
GPIO_SetBits( GPIOC,GPIO_Pin_0 );
}
}
}
.
.