📄 main.c
字号:
#include <avr/io.h>
#include <avr/delay.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <twi.h>
#include <avr/pgmspace.h>
#include <string.h>
#include <stdio.h>
#include <deprecated.h>
#include <avr/eeprom.h>
#include <stdlib.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long int
#define TRUE 1
#define FAIL 0
#define ON 1
#define OFF 0
#define FREQ 4
//*************时间中断**********
static uchar Flag_1S = OFF;
static uchar Flag_1M = OFF;
static uchar GS_1S,GS_1M;
//**************压力*************************
static uchar PRESS_TX[6] = { '#','0','1','R','D',13 };
static uchar PRESS_RX[13] = { 0 };
static uchar Press_Mid[10] = { 0 };
double Press_Data;
uint WWW;
uint WWW1;
static uchar Re_Press =0;
uchar Flag_ZD = 0;
//***************SC16C2550*************************
#define BTUON 0x80
#define RXRDY 0x04
#define TXRDY 0x02
uchar Re_Sc16A[40]= {0};
uchar Re_Sc16B[40]= {0};
static uchar Re_PB = 0;
static uchar Re_PA = 0;
#define UART_A_DATA (*(volatile uint8_t *) 0x8000)
#define UART_A_IER (*(volatile uint8_t *) 0x8001) //0X03
#define UART_A_STATE (*(volatile uint8_t *) 0x8002)
#define UART_A_DLL (*(volatile uint8_t *) 0x8000) //0C
#define UART_A_DLM (*(volatile uint8_t *) 0x8001) //00
#define UART_A_LCR (*(volatile uint8_t *) 0x8003) //
#define UART_A_MCR (*(volatile uint8_t *) 0x8004)
#define UART_A_LSR (*(volatile uint8_t *) 0x8005)
//
#define UART_B_DATA (*(volatile uint8_t *) 0xC000)
#define UART_B_IER (*(volatile uint8_t *) 0xC001) //0X03
#define UART_B_STATE (*(volatile uint8_t *) 0xC002)
#define UART_B_DLL (*(volatile uint8_t *) 0xC000) //0C
#define UART_B_DLM (*(volatile uint8_t *) 0xC001) //00
#define UART_B_LCR (*(volatile uint8_t *) 0xC003) //
#define UART_B_MCR (*(volatile uint8_t *) 0xC004)
#define UART_B_LSR (*(volatile)uint8_t *) 0xC005)
static uchar Flag_Tx_A;
static uchar Flag_Tx_B;
#define Sc16_Tx_A_OPEN UART_A_IER = 0x03
#define Sc16_Rx_A_OPEN UART_A_IER = 0x01
#define Sc16_Tx_B_OPEN UART_B_IER = 0x03
#define Sc16_Rx_B_OPEN UART_B_IER = 0x01
//**************Flow *****************
static uchar W_One[5]= {'*','@','=','A',13 };//Flow_One[5] = { '*','@','=','A',13 };
static uchar W_P_21[5] = { '*','W','2','1','=' };
static uchar W_D_22[5] = { '*','W','2','2','='};
static uchar W_Enter[2] = { 13,13 };
static uchar W_PD_MID[10] = {0};
static uchar W_RBS[2] = {'A',13 };
static uchar Flow_MID[10] = {0};
static uchar Flag_ReA = 0;
static uchar Flag_Gf = 0;
//***************Plump ********************
static uchar Plump_Open[2] = {'O',13 };
static uchar Plump_Close[2] = { 'C',13 };
static uchar Plump_Set_Point[2] = { 'S','1'};
static uchar Plump_End [2] = { 13,13 };
static uchar Plump_P[1] = { 'G'};
static uchar Plump_D[1] = { 'L'};
//***********KEY-TABLE 左 右 中*****************
static int KEY_LEFT[4] ={6,205,84,234 };
static int KEY_LEFT_P[4] = {0};
static int KEY_RIGH[4] ={230,208,310,235 } ;
static int KEY_RIGH_P[4] = {0};
static int KEY_MID[4] = {110,205,192,234 };
static int KEY_MID_P[4] = { 0 };
//*********Pin_6_KEY *************************
static int KEY_P6_rate[4] = { 116,61,265,98};
static int KEY_P6_rateP[4] = { 0 };
static int KEY_P6_press[4] = { 116,109,265,146 };
static int KEY_P6_pressP[4] = { 0 };
static int KEY_P6_time[4] = { 116,155,265,194 };
static int KEY_P6_timeP[4] = { 0 };
static uint16_t Fix_Flow = 45;
static uint16_t Fix_Press = 388;
static uint16_t Fix_Time = 20;
static uint16_t Buff_Time =0;
static double Valve = 0;
static uint16_t Flow_Ret = 0;
//ZZZZZZZZZZZZZZZZZZZ
static uint16_t Fix_ZX =0;
//XXXXXXXXXXXXXXXXXXXX
//*********Pin_8_KEY***************************
static int KEY_P8_flow[4] = { 105,94,268,131 };
static int KEY_P8_flowP[4] = { 0 };
static int KEY_P8_press[4] = { 105,157,268,194 };
static int KEY_P8_pressP[4] = { 0 };
//*********Pin17_KEY **************************
static uint16_t Fix_P = 200;
static uint16_t Fix_D = 500;
static int KEY_P17_p[4] = { 90,95,251,130 };
static int KEY_P17_pP[4] = { 0 };
static int KEY_P17_d[4] = { 90,158,2251,193 };
static int KEY_P17_dP[4] = { 0 };
//*********Pin16_Key 1 2 3 ***********
static int KEY_P16_1[4] = {56,43,230,75 };
static int KEY_P16_1P[4] = {0};
static int KEY_P16_2[4] = {57,84,213,116 };
static int KEY_P16_2P[4] = {0};
static int KEY_P16_3[4] = {56,126,196,158 };
static int KEY_P16_3P[4] = {0};
//*********Pin15_Key 1 2 ..Q*******************
static int KEY_P15_1[4] = {5,110,54,142 };
static int KEY_P15_1P[4] = {0};
static int KEY_P15_2[4] = {56,110,105,142 };
static int KEY_P15_2P[4] = {0};
static int KEY_P15_3[4] = {107,110,156,142 };
static int KEY_P15_3P[4] = {0};
static int KEY_P15_4[4] = {158,110,207,142 };
static int KEY_P15_4P[4] = {0};
static int KEY_P15_5[4] = {209,110,258,142 };
static int KEY_P15_5P[4] = {0};
static int KEY_P15_6[4] = {260,110,308,142 };
static int KEY_P15_6P[4] = {0};
//
static int KEY_P15_7[4] = {5,149,54,181 };
static int KEY_P15_7P[4] = {0};
static int KEY_P15_8[4] = {56,149,105,181 };
static int KEY_P15_8P[4] = {0};
static int KEY_P15_9[4] = {107,149,156,181 };
static int KEY_P15_9P[4] = {0};
static int KEY_P15_0[4] = {158,149,207,181 };
static int KEY_P15_0P[4] = {0};
static int KEY_P15_c[4] = {209,149,258,181 };
static int KEY_P15_cP[4] = {0};
static int KEY_P15_q[4] = {260,149,308,181 };
static int KEY_P15_qP[4] = {0};
//**********Pin_18_Key**********************
static uint16_t Fix_18_Press = 100;
static uint16_t Fix_18_P = 12;
static uint16_t Fix_18_D = 5;
static uint16_t GonGon=0;
static uint16_t JINYU = 0;
static uint16_t DD = 0;
static uint16_t AAA1 = 0;
static uint16_t AAA2 = 0;
//**********LCD使用***********
#define CONTR_LCD_PORT PORTE //定义LCD控制口
#define LE PE7
#define BUSY 0x04
#define STB PE3
#define LCD_DATA_PORT PORTB
uchar Pin;
uchar RxLen =0;
uchar Receive_Dat[11];
uchar Flag_Rec;
int X_Zb;
int Y_Zb;
static int touch_lefttop_x,touch_lefttop_y;
static int touch_rightbottom_x,touch_rightbottom_y;
float ratio_x,ratio_y;
uchar point[7] = { 0x1B,0x11,0x1B,0x1E,0x1B,0x58,0x01 };
uchar Point_Date[10]= { 0 };
uchar Point_Kong[10] = {0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20 };
//****************************
void DelayMs(uint t)
{
uint i;
for(i =0;i<t;i++)
_delay_loop_2( 250*FREQ );
}
//*******************************
void Send_byte(uchar a);
//****************************
//接受中断触摸屏
SIGNAL(SIG_UART0_RECV)
{
uchar c;
c = UDR0;
if( Flag_Rec == OFF)
{
if(( RxLen == 0) && (c == 'T'))
{
Receive_Dat[RxLen] = c;
RxLen ++;
}
else
{
if( RxLen != 0 )
{
Receive_Dat[RxLen] = c;
RxLen ++;
}
}
if(RxLen == 11)
{
if((Receive_Dat[10]==13) && (Receive_Dat[5]== 44))
{
RxLen = 0 ;
Flag_Rec = ON;
}
else
{
RxLen = 0;
}
}
}
}
//******************************************
//接受中断压力
SIGNAL(SIG_UART1_RECV)
{
uchar c;
c = UDR1;
if( Re_Press != 0 )
{
PRESS_RX[Re_Press] = c;
Re_Press ++;
}
if((Re_Press ==0) && (c == '*'))
{
PRESS_RX[Re_Press] = c;
Re_Press ++;
}
if(Re_Press == 13)
{
Re_Press = 0 ;
Flag_ZD = ON;
}
}
//**********SC162550-UART-A******************
SIGNAL(SIG_INTERRUPT4)
{
uchar a,b,c;
a = UART_A_STATE;
if( a & TXRDY )
{
Flag_Tx_A = ON;
}
if( Flag_ReA == OFF)
{
if( a & RXRDY )
{
b = UART_A_DATA;
Re_Sc16A[Re_PA] = b;
Re_PA ++;
}
}
else
{
c = UART_A_DATA;
}
}
//**********SC162550-UART-B********************
SIGNAL(SIG_INTERRUPT5)
{
uchar a,b;
a = UART_B_STATE;
if( a & TXRDY )
{
Flag_Tx_B = ON;
}
if( a & RXRDY )
{
b = UART_B_DATA;
Re_Sc16B[Re_PB] = b;
Re_PB ++;
}
}
//*******************************
void Asc_Dig(void)
{
char a;
X_Zb = 0;
Y_Zb = 0;
//------X---------
a = Receive_Dat[1];
a -= 48;
X_Zb = a * 1000;
a = Receive_Dat[2];
a -= 48;
X_Zb += a * 100;
a = Receive_Dat[3];
a -= 48;
X_Zb += a * 10;
a = Receive_Dat[4];
a -= 48;
X_Zb += a ;
//-------Y---------
a = Receive_Dat[6];
a -= 48;
Y_Zb += a * 1000;
a = Receive_Dat[7];
a -= 48;
Y_Zb += a * 100;
a = Receive_Dat[8];
a -= 48;
Y_Zb += a * 10;
a = Receive_Dat[9];
a -= 48;
Y_Zb += a ;
}
//*********触摸屏*******************
void Uart0_Init(void)
{
UCSR0B = (1<<RXCIE0) | (1 << RXEN0);
UBRR0L = 47;
}
//*********压力****************
void Uart1_Init(void)
{
UCSR1B = (1 << RXEN1) |(1 << TXEN1) | (1 << RXCIE1); //( 1<<TXCIE1 )|(1<<RXCIE1) |
UBRR1L = 23;
}
//***************************
void LCD_Init(void)
{
DDRB = 0XFF;
PORTB = 0XFF;
DDRE = 0XC8;
PORTE = 0XFF;
}
//********显示触摸屏********************
void Disp_Pin(uchar number)
{
uchar a;
a = number;
a = a *5 -1;
LCD_DATA_PORT = 0x1B;
cbi(CONTR_LCD_PORT,LE);
asm("nop");
//////////////////////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
//////////////////////////////////////////////////////
sbi(CONTR_LCD_PORT,LE);
/////////////////////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
////////////////////////////////////////////////////
while( PINE & BUSY);
cbi(CONTR_LCD_PORT,STB);
asm("nop");
///////////////////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
//////////////////////////////////////////////////
sbi(CONTR_LCD_PORT,STB);
/////////////////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
/////////////////////////////////////////////////
LCD_DATA_PORT = 0x50;
cbi(CONTR_LCD_PORT,LE);
asm("nop");
////////////////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
/////////////////////////////////////////////////
sbi(CONTR_LCD_PORT,LE);
////////////////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
////////////////////////////////////////////////
while( PINE & BUSY);
cbi(CONTR_LCD_PORT,STB);
asm("nop");
///////////////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
//////////////////////////////////////////////
sbi(CONTR_LCD_PORT,STB);
//////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
/////////////////////////////////////
LCD_DATA_PORT = a;
cbi(CONTR_LCD_PORT,LE);
asm("nop");
///////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
//////////////////////////////////////
sbi(CONTR_LCD_PORT,LE);
///////////////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
//////////////////////////////////////
while( PINE & BUSY);
asm("nop");
asm("nop");
//////////////////////////////
asm("nop");
asm("nop");
asm("nop");
asm("nop");
asm("nop");
///////////////////////////////////////
cbi(CONTR_LCD_PORT,STB);
asm("nop");
////////////////////////////////////////
asm("nop");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -