main.c 中的while循环部分:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
adc=getADC(&hadc2);
Work();
hadc.c
#include "hadc.h"
double getADC(ADC_HandleTypeDef *pin)
{
unsigned int adc;
HAL_ADC_Start(pin);
adc=HAL_ADC_GetValue(pin);
return adc*3.3/4096;
}
myfile.c
#include "myfile.h"
#include "led.h"
#include "lcd.h"
#include "key.h"
#include "main.h"
#include "stdio.h"
#include "adc.h"
#include "hadc.h"
#include "tim.h"
extern uint menu_mode; //运行模式标志 0--自动模式 1--手动模式
extern uint signal; //确定按下哪个按键 例如:signal=0 表示B1键 signal=1 表示B2键
extern uint view_chart; //显示界面标志 0--数据界面 1--参数界面
extern uint pa6_duty,pa7_duty ; //占空比
char text1[30];
extern uint adc; //保存转换的电压值
//数据界面显示
void data_menu_show(double v,uint menu_mode)
{
//显示运行模式---自动模式
Led_Display(menu_mode);
//显示数据界面
LCD_DisplayStringLine(Line0 ,(unsigned char *)" Data ");
sprintf(text1," V:%.2fV ",v);
LCD_DisplayStringLine(Line2 ,(unsigned char *)text1);
if(menu_mode)
LCD_DisplayStringLine(Line4 ,(unsigned char *)" Mode:MXNU ");
else
LCD_DisplayStringLine(Line4 ,(unsigned char *)" Mode:AUTO ");
}
//参数界面显示
void para_menu_show(uint pa6_duty,uint pa7_duty)
{
LCD_DisplayStringLine(Line0 ,(unsigned char *)" Para ");
sprintf(text1," PA6:%d%% ",pa6_duty);
LCD_DisplayStringLine(Line2 ,(unsigned char *)text1);
sprintf(text1," PA7:%d%% ",pa7_duty);
LCD_DisplayStringLine(Line4 ,(unsigned char *)text1);
}
void Display()
{
if(view_chart%2==0)
data_menu_show(adc,menu_mode);
else
para_menu_show(pa6_duty,pa7_duty);
Led_Display (menu_mode);
}
void Work()
{
Key_Contr(signal,view_chart,menu_mode);
Display();
}