📄 m128_alky_touch_con1.c
字号:
void port_init(void);
void Disp_DQ_LD(unsigned char PN,unsigned int addr,unsigned int n);
void Disp_Set_LD(unsigned char flag,unsigned int addr,unsigned int n);
void Disp_Set_TWO(unsigned char flag,unsigned int addr,unsigned char n);
void Disp_Set_FOUR(unsigned char flag,unsigned int addr,unsigned int n);
void Disp_mgl(unsigned int n,float f);
void Disp_dot(unsigned int addr,float f);
void Disp_Set_LD111(unsigned int addr,unsigned int n);
void Display_Time(unsigned char n);
void Display_Time_CLR(void);
void DS1302_Write(uchar reg,uchar data);
uchar DS1302_Read(uchar reg);
uchar Check_DS1302(void);
void DS1302_Init(void);
void ReadTime(void);
void delay_us(unsigned int n);
void Sound_Nms(unsigned int n);
//*********
void ads1100_start(void); /*i2c start */
void ads1100_stop(void); /*i2c stop*/
uchar ackby_ads1100(void); /*ads1100应答*/
void ackby_master(void); /*主机应答*/
void send_frame(uchar framedata); /*send 8bit to ads1100*/
uchar read_frame(void); /*read bbit from ads1100*/
void ads1100_write(unsigned char addr,unsigned char command); /*write a command to the ads1100*/
unsigned int ads1100_read(unsigned char addr); /*read a convert data from ads1100*/
void QS_ads1100_start(void); /*i2c start */
void QS_ads1100_stop(void); /*i2c stop*/
uchar QS_ackby_ads1100(void); /*ads1100应答*/
void QS_ackby_master(void); /*主机应答*/
void QS_send_frame(uchar framedata); /*send 8bit to ads1100*/
uchar QS_read_frame(void); /*read bbit from ads1100*/
void QS_ads1100_write(unsigned char addr,unsigned char command); /*write a command to the ads1100*/
unsigned int QS_ads1100_read(unsigned char addr); /*read a convert data from ads1100*/
void FL_ads1100_start(void); /*i2c start */
void FL_ads1100_stop(void); /*i2c stop*/
uchar FL_ackby_ads1100(void); /*ads1100应答*/
void FL_ackby_master(void); /*主机应答*/
void FL_send_frame(uchar framedata); /*send 8bit to ads1100*/
uchar FL_read_frame(void); /*read bbit from ads1100*/
void FL_ads1100_write(unsigned char addr,unsigned char command); /*write a command to the ads1100*/
unsigned int FL_ads1100_read(unsigned char addr); /*read a convert data from ads1100*/
void BENG_ads1100_start(void); /*i2c start */
void BENG_ads1100_stop(void); /*i2c stop*/
uchar BENG_ackby_ads1100(void); /*ads1100应答*/
void BENG_ackby_master(void); /*主机应答*/
void BENG_send_frame(uchar framedata); /*send 8bit to ads1100*/
uchar BENG_read_frame(void); /*read bbit from ads1100*/
void BENG_ads1100_write(unsigned char addr,unsigned char command); /*write a command to the ads1100*/
unsigned int BENG_ads1100_read(unsigned char addr); /*read a convert data from ads1100*/
//*********
void Disp_Start_donghua(unsigned int addr,unsigned char n);
uchar keboard(void);
void EEPROM_write(unsigned int uiAddress, unsigned char ucData);
unsigned char EEPROM_read(unsigned int uiAddress);
void EEPROM_init(void);
void Read_EE_10(unsigned char n);
void Write_EE_10(unsigned char n);
uint SYS_ADC(unsigned char n);
int PIDCalc( PID *pp, uint NextPoint);
int PIDCalc_WD( PID *pp, uint NextPoint);
void PIDInit (PID *pp);
float WENDU_TZ(uint ad_v);
void Display_Start_donghua320240(void);
void Display_CON320240(void);
void Display_CLR(void);
void CON_Value_XIANSHI(void);
void F_Value_XIANSHI(void);
void L_LDBD_XIANSHI(void);
void PID_Value_XIANSHI(void);
void XG_CON_Set(unsigned char kkk);
void XG_PID_Set(unsigned char kkk);
void L_LDBD_Set(unsigned char kkk);
unsigned char P_I_D_SUB1(unsigned char XX,unsigned char k);
unsigned int P_I_D_SUB2(unsigned int XX,unsigned char k);
void XG_F_Set(unsigned char kkk);
void Display_F320240(void);
void Display_L320240(void);
void Display_L_PID320240(void);
void Display_TOUCH_KEY(void);
void Display_TOUCH_KEY_VAL(void);
void Display_TOUCH_MENU(void);
void Disp_SJ_MODE_CLR(void);
void Disp_SJ_MODE_DianD(void);
void Disp_SJ_MODE_ChangK(void);
void Disp_Select_BDLD(unsigned int addr);
void Disp_Select_BDLD_Clr(unsigned int addr);
void Disp_MiMa(unsigned char flag,unsigned int addr);
void MiMa_TEMP_Clr(void);
void Button_YN(void);
void Disp_Message(uchar n,unsigned int addr);
void Display_TOUCH_Message(unsigned char n);
void Display_TOUCH_LOCK(unsigned char n);
void Display_TOUCH_KEY_BD(void);
void LD_JiSuan(void);
uchar keyboard(void);
uint ReadFromCharFrom7846(void);
void WriteCharTo7846(unsigned char num);
void ADS7846_start(void);
//******************************************
//******************************************
//******************************************
//******************************************
//******************************************
//******************************************
//******************************************
//******************************************
//******************************************
//=============================PID计算部分==============================================
int PIDCalc( PID *pp, uint NextPoint)
{
int dError,Error,TEMP;
Error = pp->SetPoint - NextPoint; // 偏差
pp->SumError += Error; // 积分
if(pp->SumError > 20000)
{pp->SumError = 20000;}
else
{
// TEMP=pp->SumError+Max;
if(pp->SumError < -20000)
pp->SumError= -20000;
}
dError = pp->LastError - pp->PrevError; // 当前微分
pp->PrevError = pp->LastError;
pp->LastError = Error;
if(Set_LD_Value>299)
return (pp->Proportion * Error + (pp->Integral * pp->SumError)/2 + pp->Derivative * dError);
else
return (pp->Proportion * Error + (pp->Integral * pp->SumError)/4 + pp->Derivative * dError);
}
//******************************************
//=============================PID计算部分==============================================
int PIDCalc_WD( PID *pp, uint NextPoint)
{
int dError,Error,TEMP;
Error = pp->SetPoint - NextPoint; // 偏差
pp->SumError += Error; // 积分
if(pp->SumError > 1000)
{pp->SumError = 1000;}
else
{
// TEMP=pp->SumError+Max;
if(pp->SumError < -1000)
pp->SumError= -1000;
}
dError = pp->LastError - pp->PrevError; // 当前微分
pp->PrevError = pp->LastError;
pp->LastError = Error;
return (pp->Proportion * Error + pp->Integral * pp->SumError + pp->Derivative * dError);
}
//******************************************
void PIDInit (PID *pp)
{ //初始化为0
pp->SetPoint=0;
pp->Proportion=0;
pp->Integral=0;
pp->Derivative=0;
pp->LastError=0;
pp->PrevError=0;
pp->SumError=0;
}
//******************************************
void port_init(void)
{
PORTA = 0x0F;
DDRA = 0xF0;
PORTB = 0x00;
DDRB = 0xFF;
PORTC = 0xFF; //m103 output only
DDRC = 0xFF;
PORTD = 0xFF;
DDRD = 0xFF;
PORTE = 0xC0;
DDRE = 0x3F;
PORTF = 0x00;
DDRF = 0x00;
PORTG = 0x1F;
DDRG = 0x1B;
}
//******************************************
//TIMER0 initialize - prescale:32
// WGM: PWM Fast
// desired value: 1mSec
// actual value: 2.048mSec (-104.8%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = 0x7D; //set count
OCR0 = 0xFF;
//TCCR0 = 0x6B; //start timer
TCCR0 = 0x7B; //start timer
}
//******************************************
#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
TCNT0 = 0x7D; //reload counter value
}
//******************************************
//TIMER1 initialize - prescale:256
// WGM: 14) PWM fast, TOP=ICRn
// desired value: 2Sec
// actual value: 2.000Sec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0x85; //setup
TCNT1L = 0xEF;
OCR1AH = 0x7A;
OCR1AL = 0x11;
OCR1BH = 0x7A;
OCR1BL = 0x11;
OCR1CH = 0x7A;
OCR1CL = 0x11;
ICR1H = 0x7A;
ICR1L = 0x11;
//TCCR1A = 0xC2;
// TCCR1B = 0x1D; //start Timer
}
//******************************************
#pragma interrupt_handler timer1_ovf_isr:iv_TIM1_OVF
void timer1_ovf_isr(void)
{
//TIMER1 has overflowed
//TCNT1H = 0x85; //reload counter high value
//TCNT1L = 0xEF; //reload counter low value
int rOut;
uint TEMP;
rOut=PIDCalc(&LD_PID,DQ_LD_Value);
if(rOut<0) rOut=0;
if(rOut>ICR1_TEMP) rOut=ICR1_TEMP;
TEMP=ICR1_TEMP-rOut;
LDPWM_Value_XianShi = TEMP;
CLI();
// if(P_OK==1)
// {
OCR1A = TEMP;
ICR1 = ICR1_TEMP;
// }
// else
// OCR1A = ICR1_TEMP;
// OCR1AH = TEMP/256;
// OCR1AL = TEMP%256;
SEI();
}
//******************************************
//******************************************
//TIMER3 initialize - prescale:1024
// WGM: 14) PWM fast, TOP=ICRn
// desired value: 10Sec
// actual value: 10.000Sec (0.0%)
void timer3_init(void)
{
TCCR3B = 0x00; //stop
TCNT3H = 0x67; //setup
TCNT3L = 0x6B;
OCR3AH = 0x98;
OCR3AL = 0x95;
OCR3BH = 0x98;
OCR3BL = 0x95;
OCR3CH = 0x98;
OCR3CL = 0x95;
ICR3H = 0x98;
ICR3L = 0x95;
//TCCR3A = 0x32;
//TCCR3A = 0x02;
//TCCR3B = 0x1D; //start Timer
}
//******************************************
//#pragma interrupt_handler timer3_ovf_isr:iv_TIM3_OVF
//void timer3_ovf_isr(void)
//{
//}
//******************************************
#pragma interrupt_handler timer3_ovf_isr:iv_TIM3_OVF
void timer3_ovf_isr(void)
{
//TIMER3 has overflowed
//TCNT3H = 0x67; //reload counter high value
//TCNT3L = 0x6B; //reload counter low value
int rOut;
uint TEMP;
TEMP=(unsigned int)ZhuQi_WenDu_Value;
rOut=PIDCalc_WD(&WD_PID,TEMP);
if(rOut<0) rOut=0;
if(rOut>ICR3_TEMP) rOut=ICR3_TEMP;
TEMP=ICR3_TEMP-rOut;
CLI();
OCR3B = TEMP;
ICR3 = ICR3_TEMP;
// OCR3BH = TEMP/256;
// OCR3BL = TEMP%256;
SEI();
}
//******************************************
//TIMER2 initialize - prescale:1024
// WGM: Normal
// desired value: 50mSec
// actual value: 49.920mSec (0.2%)
void timer2_init(void)
{
TCCR2 = 0x00; //stop
TCNT2 = 0x3D; //setup
OCR2 = 0xC3;
//TCCR2 = 0x05; //start
}
//******************************************
#pragma interrupt_handler timer2_ovf_isr:iv_TIM2_OVF
void timer2_ovf_isr(void)
{
unsigned char i;
unsigned char j,k,Temp,Temp1;
unsigned int addr;
unsigned char addr_t;
unsigned char TEMP_CH;
TCNT2 = 0x3D; //reload counter value
TIMSK = 0x05;
SEI();
/*
ReadTime();
if(!(Last_Second==Second))
{
Display_Time(0);
Last_Second=Second;
}
*/
if(ZhuQi_WenDu_Value>50)
{
TCCR3A = 0x02;
TCCR3B = 0x1D; //start Timer3
PORTE&=~(1<<4);
}
if((Set_WenDu_Value+1) < ((unsigned char)ZhuQi_WenDu_Value));
WD_PID.SumError =0;
//ADC_data_T=ADC_data_T+ads1100_read(ads1100_readaddr);
ADC_data_T=ADC_data_T + SYS_ADC(DQ_LD_ADC);
DQ_WenDu_TOT = DQ_WenDu_TOT + SYS_ADC(DQ_WenDu_ADC);
ZhuQi_WenDu_TOT = ZhuQi_WenDu_TOT + SYS_ADC(ZhuQi_WenDu_ADC);
DQ_ShiDu_TOT = DQ_ShiDu_TOT + SYS_ADC(DQ_ShiDu_ADC);
// k=keboard();
k=keyboard();
if(!(Last_Key==k))
{
Last_Key=k;
if(YN_TOUCH_KEY_DISP_F)
{
if(k<10)
{
KEY_TEMP[5]=KEY_TEMP[4];
KEY_TEMP[4]=KEY_TEMP[3];
KEY_TEMP[3]=KEY_TEMP[2];
KEY_TEMP[2]=KEY_TEMP[1];
KEY_TEMP[1]=KEY_TEMP[0];
KEY_TEMP[0]=k;
}
else
if(k==10) //确定
{
delay_nms(20);
if(keyboard()==10)
switch(MENU_NUM)
{
case 0: //浓度修改
CLI();
Set_LD_Value= KEY_TEMP[2] * 100 +KEY_TEMP[1] * 10 + KEY_TEMP[0];
LD_PID.SetPoint = Set_LD_Value;
EEPROM_write(EE_Set_LD_AddrL, Set_LD_Value%256);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -