标题:
矩阵键盘stm32f103c8t6源码
[打印本页]
作者:
wangsh123456789
时间:
2018-4-12 15:44
标题:
矩阵键盘stm32f103c8t6源码
矩阵键盘stm32f103c8t6单片机源程序如下:
#include "stm32f10x.h"
#include "GPIO.h"
#include "delay.h"
#include "sys.h"
#include "oled.h"
#include "key.h"
#include "adc.h"
extern int number;
void Delay(uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
//=============================================================================
//文件名称:main
//功能概要:主函数
//参数说明:无
//函数返回:int
//=============================================================================
int main(void)
{
unsigned int i,ADC_Value,times,temp1,time1,temp2,time2;
GPIO_Configuration();
delay_init();
InitKey();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
ADC1_Init();
OLED_Init(); //初始化OLED
OLED_Clear() ;
while (1)
{
i=GetNumer();
temp1=i/1000000;//温度1
time1=i%1000000/10000;//时间1
temp2=i%10000/100;//温度2
time2=i%100;//时间2
OLED_ShowChar(18,2,'W',16);
OLED_ShowChar(36,2,temp1/10+48,16);
OLED_ShowChar(48,2,temp1%10+48,16);
OLED_ShowChar(70,2,'T',16);
OLED_ShowChar(88,2,time1/10+48,16);
OLED_ShowChar(100,2,time1%10+48,16);
OLED_ShowChar(18,4,'W',16);
OLED_ShowChar(36,4,temp2/10+48,16);
OLED_ShowChar(48,4,temp2%10+48,16);
OLED_ShowChar(70,4,'T',16);
OLED_ShowChar(88,4,time2/10+48,16);
OLED_ShowChar(100,4,time2%10+48,16);
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_239Cycles5 );
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));
ADC_Value=ADC_GetConversionValue(ADC1);
ADC_Value=ADC_Value*1000/4096;
OLED_ShowChar(18,6,'W',16);
OLED_ShowChar(48,6,ADC_Value/100+48,16);
OLED_ShowChar(60,6,ADC_Value%100/10+48,16);
OLED_ShowChar(70,6,'.',16);
OLED_ShowChar(80,6,ADC_Value%10+48,16);
if((ADC_Value>(temp1*10-50))&&(ADC_Value<(temp1*50+50))&&(time1!=0))
{
if(ADC_Value>temp1)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_9);//绿灯亮
GPIO_SetBits(GPIOB,GPIO_Pin_7);
}
else
{
GPIO_ResetBits(GPIOB,GPIO_Pin_7);//红灯亮
GPIO_SetBits(GPIOB,GPIO_Pin_9);
}
//保温计时开始
times++;
if(times==30)
{
if(time1!=0)
number=number-10000;
times=0;
}
}
else if((ADC_Value>(temp2*10-50))&&(ADC_Value<(temp2*50+50))&&(time2!=0))
{
if(ADC_Value>temp2)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_9);//绿灯亮
GPIO_SetBits(GPIOB,GPIO_Pin_7);
}
else
{
GPIO_ResetBits(GPIOB,GPIO_Pin_7);//红灯亮
GPIO_SetBits(GPIOB,GPIO_Pin_9);
}
//保温计时开始
times++;
if(times==30)
{
if(time2!=0)
number=number-1;
times=0;
}
}
else
{
GPIO_ResetBits(GPIOB,GPIO_Pin_7);//红灯亮
GPIO_SetBits(GPIOB,GPIO_Pin_9);
}
}
}
复制代码
所有资料51hei提供下载:
STM32F103C8T6核心板程序.rar
(385.19 KB, 下载次数: 122)
2018-4-12 23:43 上传
点击文件名下载附件
下载积分: 黑币 -5
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1