📄 main.c
字号:
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include "2410addr.h"
#include "def.h"
#include "INT.h"
#include "2410lib.h"
#include "UartLib.h"
#include "lcdlib.h"
#include "touch.h"
#define WIN_485_M 1
#define WIN_485_S 2
// 自定义命令
#define RED_LIGHT_OPEN 101
#define RED_LIGHT_CLOSE 102
#define GREEN_LIGHT_OPEN 103
#define GREEN_LIGHT_CLOSE 104
#define BLUE_LIGHT_OPEN 105
#define BLUE_LIGHT_CLOSE 106
typedef struct{
U16 X;
U16 Y;
U16 W;
U16 H;
COLOR color;
int mode;
char title[30];
U16 status;
} BUTTON_SUB;
void WIN_485(void);
void SetBtn(BUTTON_SUB *Btn, U16 x, U16 y, U16 w, U16 h, char *title, U16 s);
void DrawBtn(BUTTON_SUB bBtn[30], int num);
void DrawGuage(int value);
void WIN_Master(void);
void WIN_Slave(void);
void __irq TouchPane_Choice(void);
void __irq TouchPane_485(void);
void __irq U485_LISR(void);
int FindBtnId(int x, int y,BUTTON_SUB bBtn[30],int num);
void CmdAnalyse(char Cmd);
void WriteCmdFor485(char Cmd);
void OnBtnInc(void);
void OnBtnDec(void);
void OnBtnRed(void);
void OnBtnGreen(void);
void OnBtnBlue(void);
int BtnMax;
BUTTON_SUB Btn[20];
int currentWin;
int g_GuageValue = 0;
volatile int Choice = 0;
int g_redLight = FALSE;
int g_greenLight = FALSE;
int g_blueLight = FALSE;
BUTTON_SUB Btn485[2];
BUTTON_SUB BtnSub485[5];
extern UART_PORT UartPort0;
UART_PORT *Port = &UartPort0;
int main()
{
char Cmd = 0;
ChangeClockDivider(1,1); // 1:2:4
ChangeMPllValue(0xa1,0x3,0x1); // FCLK=202.8MHz
Port_Init();
__vInitHaltHandlers();
LCD_Init();
ISRVector[31] = TouchPane_Choice;
INT_ADC_Enable(TRUE);
ReadAdjustData();
Choice = 0;
WIN_485();
Port->comPort = UART0; // 目标串口
Port->baudRate = 9600; // 波特率
Port->dataBits = 3; // 8 bits per frame
Port->stopBits = 0; // One stop bit per frame
Port->parity = 0; // No parity
Port->dataMode = 0; // UART runs in normal operation
Port->communicationMode = 0;// ???
Port->bufferSize = 1024; // 接收缓冲大小
InitUartPort(Port);
ISRVector[28] = Receive_Uart0;
rGPGCON &= 0xFF3FFFFF;
rGPGCON |= 1<<22;
// rGPGCON &= ~(1<<23);
rGPGUP &= ~(1<<11);
// rGPGDAT &= ~(1<<11);
while(1)
{
switch(Choice)
{
case 1:
{
WIN_Master();
g_GuageValue = 0;
currentWin = WIN_485_M;
//rGPGDAT |= (1<<11);
goto $RUN;
}break;
case 2:
{
WIN_Slave();
g_GuageValue = 0;
currentWin = WIN_485_S;
//rGPGDAT &= ~(1<<11);
goto $RUN;
}break;
default:break;
}
}
$RUN:
while(1)
{
Cmd = UartGetChar(Port);
if(Cmd > 0)
{
CmdAnalyse(Cmd);
}
}
}
void __irq TouchPane_Choice(void)
{
int XData, YData;
int BtnID;
INT_ADC_Enable(FALSE);
tp_rewaite_int();
XData = adc_x_position();
YData = adc_y_position();
BtnID = FindBtnId(XData,YData,Btn,BtnMax);
switch (BtnID)
{
case 0:
{
Choice = 1;
ISRVector[31] = TouchPane_485;
Delay(50);
}break;
case 1:
{
Choice = 2;
ISRVector[31] = TouchPane_485;
Delay(50);
}break;
default :
{
Delay(50);
}
}
ClearInt(); // 清中断
INT_ADC_Enable(TRUE);
}
void __irq TouchPane_485(void)
{
int XData, YData;
int BtnID;
INT_ADC_Enable(FALSE);
tp_rewaite_int();
XData = adc_x_position();
YData = adc_y_position();
BtnID = FindBtnId(XData,YData,Btn,BtnMax);
switch (BtnID)
{
case 0:
{
OnBtnDec();
Delay(50);
}break;
case 1:
{
OnBtnInc();
Delay(50);
}break;
case 2:
{
OnBtnRed();
Delay(50);
}break;
case 3:
{
OnBtnGreen();
Delay(50);
}break;
case 4:
{
OnBtnBlue();
Delay(50);
}break;
default :
{
Delay(50);
}
}
ClearInt(); // 清中断
INT_ADC_Enable(TRUE);
}
int FindBtnId(int x, int y,BUTTON_SUB bBtn[30],int num)
{
int i;
for(i = 0; i < num; i++)
{
if(x>=bBtn[i].X && x<=(bBtn[i].X+bBtn[i].W) &&
y>=(bBtn[i].Y) && y<=(bBtn[i].Y+bBtn[i].H) && (-1 != bBtn[i].status) )
{
fillreverserectangle (bBtn[i].X,bBtn[i].Y,bBtn[i].X+bBtn[i].W,bBtn[i].Y+bBtn[i].H);
WaitForStylusUp();
fillreverserectangle (bBtn[i].X,bBtn[i].Y,bBtn[i].X+bBtn[i].W,bBtn[i].Y+bBtn[i].H);
return i;
}
}
return 0xFF;
}
void WriteCmdFor485(char Cmd)
{
rGPGDAT |= (1<<11); // 配置为发送
UartPutChar(Cmd, Port); // 发送数据
rGPGDAT &= ~(1<<11); // 配置为接收
}
void OnBtnInc(void)
{
g_GuageValue++;
if (g_GuageValue > 30)
g_GuageValue = 30;
if (g_GuageValue < 0)
g_GuageValue = 0;
DrawGuage(g_GuageValue);
WriteCmdFor485(g_GuageValue + 30);
Rewriteletter((g_xMax-180)/2+5 ,g_yMax/2-70+23,"数值增加",1,0,RGB(255,0,0),RGB(255,255,255));
}
void OnBtnDec(void)
{
g_GuageValue--;
if (g_GuageValue > 30)
g_GuageValue = 30;
if (g_GuageValue < 0)
g_GuageValue = 0;
DrawGuage(g_GuageValue);
WriteCmdFor485(g_GuageValue + 30);
Rewriteletter((g_xMax-180)/2+5 ,g_yMax/2-70+23,"数值减小",1,0,RGB(255,0,0),RGB(255,255,255));
}
void OnBtnRed(void)
{
if (g_redLight == TRUE)
{
g_redLight = FALSE;
CmdAnalyse(RED_LIGHT_CLOSE);
WriteCmdFor485(RED_LIGHT_CLOSE);
}
else
{
g_redLight = TRUE;
CmdAnalyse(RED_LIGHT_OPEN);
WriteCmdFor485(RED_LIGHT_OPEN);
}
}
void OnBtnGreen(void)
{
if (g_greenLight == TRUE)
{
g_greenLight = FALSE;
CmdAnalyse(GREEN_LIGHT_CLOSE);
WriteCmdFor485(GREEN_LIGHT_CLOSE);
}
else
{
g_greenLight = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -