#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "tim1.h"
#include "pwm.h"
#include "LCD12864.h"
#include "stdio.h"
#include "adc.h"
#include "key.h"
#include "TLE7209.h"
#include "Sin_curve.h"
#include "Parameter.h"
#include "led.h"
#include "PID.h"
u16 Data_int[20];
u8 Cur_Addr[] = {0x90,0x88,0x85};
u8 mode=1;
u8 addrs = 0, TIM4CH4_CAPTURE_STA = 0,Cursor_flag,Number_add_flag,KEY_Down_flag;
u16 Data[20], Feedback_Analog_value = 0;
float Frequence=1300;
u32 datanumber=0,Duty=50;
u32 CRCI;
float Current_Analog_value = 0,SET_Analog_value = 0, Sent_data1, Sent_data2, Sent_data3,Sent_data4, Sent_data5, Sent_data6,Sent_data7, Sent_Voltage_all;
float SinPoint = 0, SET_Analog_voltage = 0, Feedback_Analog_voltage = 0,Current_Analog_voltage = 0, Sent_Voltage1 = 0,Sent_Voltage2 = 0,Current_Analog_value_view = 0;
int SET_Analog_value_view = 0, Feedback_Analog_value_view = 0, pwm_number = 50,pwm_number1=50,ALL_DATA = 0;
float Sent_Voltage21,Sent_Voltage21_view;
float Tick_time,base_time,one_tick_time;
int Sinpointnumber = 0, first_data;
int TIM4CH4_CAPTURE_value = 0, TIM4CH4_CAPTURE_value_last = 0,TIM4CH4_CAPTURE_value_error, TIM4CH4_CAPTURE_value_number,crc,value1,value2,sent_errorcount=0 ;
void Dis_Cur()
{
Write_Com(Cur_Addr[addrs]);
delay_ms(10);
Write_Com(0x0f);
delay_ms(1000);
Write_Com(0x0c);
}
int main(void) {
Stm32_Clock_Init(9); //系统时钟设置0.1
uart_init(72, 115200); //串口初始化为115200
delay_init(72);
delay_s(1);
KEY_Init(); //按键初始化
//TIM_Init(49, 99, 50);
Init_12864();
PWM_Init();
GPIO_Configuration();
Adc_Init();
//LCD12864xie(0, 0, "eCBV&CPS");
LCD12864xie(0, 0, "SmartACV");
LCD12864xie(0, 1, "Fre: Hz");
LCD12864xie(0, 2, "Duty: %");
LCD12864xie(0, 3, "Volt: V");
TIM3_Int_Init(540, 719);
//TIM4_Capture_Init(0XFFFF, 0);//No frequency division, one cycle time 1/72us
//TIM2_PWM_Init(500, 680);
//Init_TLE7209();
//TLE7209_DIS = 0;
//TLE7209_EN = 0;
//TLE7209_SCK = 1;
//TLE7209_CS = 1;
//TLE7209_SCK =1;
//TLE7209_CS=1;
while (1)
{ if(mode==1)
{LCD12864xie(5, 0, "Manual");}
if(mode==2)
{LCD12864xie(5, 0, "Auto");}
SET_Analog_value = Get_Adc_Average(4, 1)*3.3*11/4095*100;
lcd_sfm(0x8b,Duty);
lcd_sfm(0x9b,SET_Analog_value+60);
if(Frequence!=1300)
{lcd_sfm(0x93,Frequence);
TIM_Init(36000/Frequence, 1999, Duty*20);}
if(Frequence==1300)
{
TIM_Init(36000, 12000, 6000);
lcd1_sfm(0x93,Frequence/10);}
if((Cursor==0)&&(Cursor_flag==1))
{delay_ms(1);
;
if(Cursor==0)
{ addrs ++;
if(addrs == 3)
{ addrs = 0;}
Dis_Cur();
Cursor_flag=0;
}
}
if(Cursor==1)
{Cursor_flag=1;}
if((Number_add==0)&&(Number_add_flag==1))
{
if(Number_add==0)
if(Number_add==0)
{ Number_add_flag=0;
switch(Cur_Addr[addrs])
{
case 0x90:
Frequence ++;
if(Frequence >=251)
{Frequence = 0;
}
break;
case 0x88:
Duty ++;
if(Duty >=100)
{Duty = 0;
}
break;
case 0x85:
mode ++;
if(mode >=3)
{mode =1;
}
break;
default:
break;
}
}
}
if(Number_add==1)
{Number_add_flag=1;}
if((KEY_Down==0)&&(KEY_Down_flag==1))
{
if(KEY_Down==0)
if(KEY_Down==0)
{ KEY_Down_flag=0;
switch(Cur_Addr[addrs])
{
case 0x90:
Frequence --;
if(Frequence ==0)
{Frequence = 251;
}
break;
case 0x88:
Duty --;
if(Duty ==0)
{Duty = 100;
}
break;
case 0x85:
mode--;
if(mode==0)
{mode = 2;
}
break;
default:
break;
}
}
}
if(KEY_Down==1)
{KEY_Down_flag=1;}
}
}
void TIM3_IRQHandler(void) {
u16 tsr;
tsr = TIM3->SR;
if (tsr & 0X02) //capture accident
{
if(mode==2)
{
Sinpointnumber++;
if (Sinpointnumber == 360)
{
Sinpointnumber = 0;
}
Duty = SIN[Sinpointnumber] * 9 + 29;
}}
else if(mode==1)
{Duty=40;}
TIM3->SR = 0; //清除中断标志位
}
void lcd3_sfm(unsigned char add,int data)//显示位置和数据
{
unsigned char wan, qian,bai, shi,ge;
wan=data/10000;
qian =(data-wan*10000)/1000;
bai =(data-wan*10000-qian*1000)/100;
shi=(data-wan*10000-qian*1000-bai*100)/10;
ge=(data-wan*10000-qian*1000-bai*100-shi*10)%10;
Write_Com(add);
Write_Date(0x30+wan);
Write_Date(0x30+qian);
Write_Date(0x30+bai);
Write_Date(0x30+shi);
Write_Date(0x30+ge);
}
|