268 lines
7.0 KiB
C
268 lines
7.0 KiB
C
|
#include "main.h"
|
|||
|
#include "public.h"
|
|||
|
#include "key.h"
|
|||
|
#include "sim_eeprom.h"
|
|||
|
#include "tim3_pwm_output.h"
|
|||
|
#include "adc_dma_multichanit.h"
|
|||
|
#include <math.h>
|
|||
|
#include "heater.h"
|
|||
|
#include "fpc.h"
|
|||
|
#include "ST7735S.h"
|
|||
|
#include "pid.h"
|
|||
|
#include "uart.h"
|
|||
|
#include "timer.h"
|
|||
|
#include "adc_anychannel_continuousscan_interrupt.h"
|
|||
|
#include "spi_master_dma_interrupt.h"
|
|||
|
#include "sim_eeprom.h"
|
|||
|
|
|||
|
int temp_pwm;
|
|||
|
u8 T_temp_0 = 0;
|
|||
|
char T_temp_1 = 0;
|
|||
|
float hot_1_C = 0 ; // <20><><EFBFBD><EFBFBD>1s<31><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>
|
|||
|
float PWM_SCALE = 0; // pwm <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
float down_up_rate = 0; // <20>¶<EFBFBD><C2B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
double down_per; // <20>¶ΰٷֱ<D9B7>
|
|||
|
float down_V ;
|
|||
|
|
|||
|
u8 one_times_0 = 0;
|
|||
|
u8 one_times_1 = 0;
|
|||
|
double Q_J = 0;
|
|||
|
u8 last_pwm = 0;
|
|||
|
u8 down_rise_pwm = 0;
|
|||
|
u8 up_down_flag = 0;
|
|||
|
|
|||
|
u8 work_mode = 1; //0 <20><><EFBFBD><EFBFBD>;1<><31><EFBFBD><EFBFBD> 2<><32><EFBFBD><EFBFBD>;
|
|||
|
u8 restart = 1 ;
|
|||
|
u8 heat_start = 0;
|
|||
|
u8 heat_stage = 0;
|
|||
|
void SystemInit(void);
|
|||
|
void GPIO_AIN_ALL(void)
|
|||
|
{
|
|||
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|||
|
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA, ENABLE);
|
|||
|
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOB, ENABLE);
|
|||
|
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOC, ENABLE);
|
|||
|
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOD, ENABLE);
|
|||
|
|
|||
|
GPIO_StructInit(&GPIO_InitStruct);
|
|||
|
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
|
|||
|
GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 |
|
|||
|
GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 |
|
|||
|
GPIO_Pin_12 | GPIO_Pin_15;
|
|||
|
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
|
|||
|
GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|||
|
|
|||
|
GPIO_StructInit(&GPIO_InitStruct);
|
|||
|
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;
|
|||
|
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
|
|||
|
GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|||
|
GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|||
|
GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|||
|
|
|||
|
}
|
|||
|
void PWR_GPIO_Configure(void)
|
|||
|
{
|
|||
|
PVCC_EN_OFF();
|
|||
|
Beep_OFF();
|
|||
|
IR_OFF();
|
|||
|
Charge_ON();
|
|||
|
LCD_OFF();
|
|||
|
|
|||
|
GPIO_AIN_ALL();
|
|||
|
FPC_Init();
|
|||
|
|
|||
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|||
|
|
|||
|
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOA, ENABLE);
|
|||
|
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOB, ENABLE);
|
|||
|
RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOD, ENABLE);
|
|||
|
|
|||
|
|
|||
|
GPIO_StructInit(&GPIO_InitStruct);
|
|||
|
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11 ;//PVCC
|
|||
|
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
|
|||
|
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
|||
|
GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|||
|
|
|||
|
GPIO_StructInit(&GPIO_InitStruct);
|
|||
|
GPIO_InitStruct.GPIO_Pin = PVCC_EN_Pin ;//spi2 sda
|
|||
|
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
|
|||
|
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
|||
|
GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|||
|
|
|||
|
GPIO_StructInit(&GPIO_InitStruct);
|
|||
|
GPIO_InitStruct.GPIO_Pin = ST7735_LED_Pin ;//LED
|
|||
|
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
|
|||
|
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
|||
|
GPIO_Init(ST7735_LED_GPIO_Port, &GPIO_InitStruct);
|
|||
|
|
|||
|
GPIO_StructInit(&GPIO_InitStruct);
|
|||
|
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;//HEAT
|
|||
|
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
|||
|
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
|
|||
|
GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|||
|
|
|||
|
GPIO_ResetBits(GPIOA,GPIO_Pin_2);
|
|||
|
GPIO_ResetBits(GPIOA,GPIO_Pin_11);
|
|||
|
PVCC_EN_OFF();
|
|||
|
Beep_OFF();
|
|||
|
IR_OFF();
|
|||
|
Charge_ON();
|
|||
|
LCD_OFF();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void PWR_EXTI_Configure(void)
|
|||
|
{
|
|||
|
EXTI_InitTypeDef EXTI_InitStruct;
|
|||
|
NVIC_InitTypeDef NVIC_InitStruct;
|
|||
|
//External interrupt Mode
|
|||
|
SYSCFG_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource0); // <20><><EFBFBD><EFBFBD>
|
|||
|
//Interrupt threads where pins are located
|
|||
|
EXTI_InitStruct.EXTI_Line = EXTI_Line0;
|
|||
|
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
|||
|
//rising trigger
|
|||
|
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
|||
|
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
|||
|
EXTI_Init(&EXTI_InitStruct);
|
|||
|
|
|||
|
SYSCFG_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource3); // 5V<35><56><EFBFBD><EFBFBD>
|
|||
|
//Interrupt threads where pins are located
|
|||
|
EXTI_InitStruct.EXTI_Line = EXTI_Line3;
|
|||
|
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
|||
|
//rising trigger
|
|||
|
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
|||
|
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
|||
|
EXTI_Init(&EXTI_InitStruct);
|
|||
|
|
|||
|
SYSCFG_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource5); // <20><><EFBFBD><EFBFBD>
|
|||
|
//Interrupt threads where pins are located
|
|||
|
EXTI_InitStruct.EXTI_Line = EXTI_Line5;
|
|||
|
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
|
|||
|
//rising trigger
|
|||
|
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
|||
|
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
|
|||
|
EXTI_Init(&EXTI_InitStruct);
|
|||
|
|
|||
|
NVIC_InitStruct.NVIC_IRQChannel = EXTI0_1_IRQn;
|
|||
|
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x01;
|
|||
|
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
|
|||
|
NVIC_Init(&NVIC_InitStruct);
|
|||
|
|
|||
|
NVIC_InitStruct.NVIC_IRQChannel = EXTI2_3_IRQn;
|
|||
|
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x01;
|
|||
|
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
|
|||
|
NVIC_Init(&NVIC_InitStruct);
|
|||
|
|
|||
|
NVIC_InitStruct.NVIC_IRQChannel = EXTI4_15_IRQn;
|
|||
|
NVIC_InitStruct.NVIC_IRQChannelPriority = 0x01;
|
|||
|
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
|
|||
|
NVIC_Init(&NVIC_InitStruct);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void PWR_Pretreatment(void)
|
|||
|
{
|
|||
|
#ifdef _debug_
|
|||
|
printf("lowpower in !\n");
|
|||
|
#endif
|
|||
|
ADC_VrefintCmd(DISABLE);
|
|||
|
ADC_Cmd(ADC1,DISABLE);
|
|||
|
DMA_Cmd(DMA1_Channel2, DISABLE);
|
|||
|
DMA_Cmd(DMA1_Channel3, DISABLE);
|
|||
|
DMA_Cmd(DMA1_Channel4, DISABLE);
|
|||
|
DMA_Cmd(DMA1_Channel5, DISABLE);
|
|||
|
SPI_Cmd(SPI1, DISABLE);
|
|||
|
SPI_Cmd(SPI2, DISABLE);
|
|||
|
TIM_Cmd(TIM2, DISABLE);
|
|||
|
UART_Cmd(UART1, DISABLE);
|
|||
|
|
|||
|
RCC_APB2PeriphClockCmd(RCC_APB2ENR_ADC1, ENABLE);
|
|||
|
RCC_AHBPeriphClockCmd(RCC_AHBENR_DMA1,DISABLE);
|
|||
|
RCC_APB2PeriphClockCmd(RCC_APB2ENR_UART1,DISABLE);
|
|||
|
RCC_APB2PeriphClockCmd(RCC_APB2ENR_SPI1,DISABLE);
|
|||
|
RCC_APB1PeriphClockCmd(RCC_APB1ENR_SPI2, DISABLE);
|
|||
|
RCC_APB1PeriphClockCmd(RCC_APB1ENR_TIM2, DISABLE);
|
|||
|
|
|||
|
PWR_GPIO_Configure();
|
|||
|
PWR_EXTI_Configure();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void PWR_Reinitialize(void)
|
|||
|
{
|
|||
|
SystemInit();
|
|||
|
CONSOLE_Init(115200);
|
|||
|
TimerInit();
|
|||
|
g_work.m_work_flag._Uart_match = 0;
|
|||
|
FPC_Init();//<2F><><EFBFBD><EFBFBD>FPC <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ų<EFBFBD>ʼ<EFBFBD><CABC>
|
|||
|
SPI1_Configure();//16M flash
|
|||
|
SPI2_Configure();//LCD spi
|
|||
|
SPI1_FLASH_ReadDeviceID();
|
|||
|
SPI1_FLASH_ReadJEDEC_ID();
|
|||
|
ST7735_Init();
|
|||
|
Heater_Init();
|
|||
|
ADC_Configure();
|
|||
|
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
|
|||
|
OFF_delay_time = 5000;
|
|||
|
FPC_Scan();
|
|||
|
}
|
|||
|
void work_new(void)
|
|||
|
{
|
|||
|
if(work_mode == 0 )//<2F><EFBFBD><CDB9><EFBFBD>
|
|||
|
{
|
|||
|
restart = 1;
|
|||
|
logo1_flag = 0;
|
|||
|
logo2_flag = 0;
|
|||
|
logo3_flag = 0;
|
|||
|
logo4_flag = 0;
|
|||
|
logo5_flag = 0;
|
|||
|
heat_stage = 0;
|
|||
|
PWR_Pretreatment();//<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><CDB9><EFBFBD>ǰ
|
|||
|
/* Deep Stop Mode */
|
|||
|
RCC_APB1PeriphClockCmd(RCC_APB1ENR_PWR, ENABLE);
|
|||
|
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
|
|||
|
PWR_Reinitialize();
|
|||
|
}
|
|||
|
else if(work_mode == 1)//<2F><><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|||
|
{
|
|||
|
logo3_flag = 0;
|
|||
|
logo4_flag = 0;
|
|||
|
logo5_flag = 0;
|
|||
|
heat_stage = 0;
|
|||
|
temp_control_new(0,0);
|
|||
|
if(restart == 1)
|
|||
|
{
|
|||
|
logo2_flag = 0;
|
|||
|
animation_start();//<2F><><EFBFBD>ſ<EFBFBD><C5BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
logo1_flag = 0;
|
|||
|
animation_show_v();
|
|||
|
}
|
|||
|
}
|
|||
|
else if(work_mode == 2)//<2F><><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
logo1_flag = 0;
|
|||
|
logo2_flag = 0;
|
|||
|
heat_control();
|
|||
|
if(heat_stage == 1)//<2F><><EFBFBD><EFBFBD>״̬
|
|||
|
{
|
|||
|
animation_temp_on();
|
|||
|
}
|
|||
|
else if(heat_stage == 2)//<2F><><EFBFBD>³<EFBFBD><C2B3><EFBFBD>״̬
|
|||
|
{
|
|||
|
animation_smoking();
|
|||
|
}
|
|||
|
else if (heat_stage ==3)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
{
|
|||
|
animation_heat_over();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|