📄 main.c
字号:
if(strncmp((char *)RcvBuff, "GET", 3) == 0)
{
if(RcvBuff[5] == ' ') // 处理首页信息
{
length = strlen((char *)index_htm);
send(Order, httpweb, sizeof(httpweb), 0); // 发送响应头
Cnt = 1;
while(length > (1380 * Cnt)) // 发送报文体
{
send(Order, index_htm + (1380 * (Cnt - 1)), 1380, 0);
Cnt++;
}
send(Order, index_htm + (1380 * (Cnt - 1)), length - (1380 * (Cnt - 1)), 0);
}
else if(RcvBuff[5] == 'e') // 处理刷新页信息
{
length = strlen((char *)echo_htm);
send(Order, httpweb, sizeof(httpweb), 0); // 发送响应头
Cnt = 1;
while(length > (1380 * Cnt)) // 发送报文体
{
send(Order, echo_htm + (1380 * (Cnt - 1)), 1380, 0);
Cnt++;
}
send(Order, echo_htm + (1380 * (Cnt - 1)), length - (1380 * (Cnt - 1)), 0);
}
else // 请求内容不在范围内
{
close(Order);
OSTimeDly(10);
TCP_Abort(Order);
OSTimeDly(10);
}
}
/* 处理网页上的按键命令 */
else if(strncmp((char *)RcvBuff, "POST", 4) == 0)
{
for(Cnt = 4; Cnt < RcvNum; Cnt++)
{
if(strncmp((char *)RcvBuff+Cnt, "Buzzer=Set", 10) == 0)
{
gpio_set(BUZZER);
break;
}
else if(strncmp((char *)RcvBuff+Cnt, "Buzzer=Clr", 10) == 0)
{
gpio_clr(BUZZER);
break;
}
}
send(Order, httpweb, sizeof(httpweb), 0); // 发送响应头
}
close(Order);
OSTimeDly(10);
TCP_Abort(Order);
OSTimeDly(10);
break;
}
}
}
OSTimeDly(OS_TICKS_PER_SEC/6);
}
}
/*******************************************************************************************
** Function name: TASK1
** Descriptions: 检测检测AD0~AD3的电压值
** Input: 无
** Output: 无
*******************************************************************************************/
void TASK1(void *pdata)
{
uint8 tmp;
uint8 Err=0;
char DataBuf[4];
uint32 i;
int32 ADC0_Handles =0;
int32 ADC1_Handles =0;
int32 ADC2_Handles =0;
int32 ADC3_Handles =0;
uint16 AdcData,ch[4];
uint32 length;
uint32 AD0_NO;
uint32 AD1_NO;
uint32 AD2_NO;
uint32 AD3_NO;
pdata = pdata;
ADC0_Handles = dopen("ADC0\\0", O_RDWR, SHARE); // 以共享方式打开ADC0的第0通道
if( ADC0_Handles < 0 )
{
Err = getlasterr(ADC0_Handles); // 查看错误状态
while(1)
{
OSTimeDly(OS_TICKS_PER_SEC);
}
}
ADC1_Handles = dopen("ADC0\\1", O_RDWR, SHARE); // 以共享方式打开ADC0的第1通道
if( ADC1_Handles < 0 )
{
Err = getlasterr(ADC1_Handles); // 查看错误状态
while(1)
{
OSTimeDly(OS_TICKS_PER_SEC);
}
}
ADC2_Handles =dopen("ADC0\\2", O_RDWR, SHARE); // 以共享方式打开ADC0的第2通道
if( ADC2_Handles < 0 )
{
Err = getlasterr(ADC2_Handles); // 查看错误状态
while(1)
{
OSTimeDly(OS_TICKS_PER_SEC);
}
}
ADC3_Handles = dopen("ADC0\\3", O_RDWR, SHARE); // 以共享方式打开ADC0的第3通道
if( ADC3_Handles<0 )
{
Err = getlasterr(ADC3_Handles); // 查看错误状态
while(1)
{
OSTimeDly(OS_TICKS_PER_SEC);
}
}
/* 获取AINn电压所在的位置 */
length = strlen((char *)echo_htm);
for(i=0; i<length-4; i++)
{
if(strncmp((char *)echo_htm + i, "AIN0", 4) == 0)
{
AD0_NO = i;
break;
}
}
for(i=0; i<length-4; i++)
{
if(strncmp((char *)echo_htm + i, "AIN1", 4) == 0)
{
AD1_NO = i;
break;
}
}
for(i=0; i<length-4; i++)
{
if(strncmp((char *)echo_htm + i, "AIN2", 4) == 0)
{
AD2_NO = i;
break;
}
}
for(i=0; i<length-4; i++)
{
if(strncmp((char *)echo_htm + i, "AIN3", 4) == 0)
{
AD3_NO = i;
break;
}
}
while (1)
{
diocontrol(ADC0_Handles, GENERAL_SAMPLING, (void *)0); // 使用普通采样
dread(ADC0_Handles, DataBuf, 1); // 读取 ADC 通道 0 转换值
AdcData =(DataBuf[1]<<8) + DataBuf[0]; // 读出电压值,并合并为电压值,单位为mV
ch[0] = AdcData;
OSTimeDly(OS_TICKS_PER_SEC/10);
diocontrol(ADC1_Handles, GENERAL_SAMPLING, (void *)0); // 使用普通采样
dread(ADC1_Handles, DataBuf, 1); // 读取 ADC 通道 1 转换值
AdcData =(DataBuf[1]<<8) + DataBuf[0]; // 读出电压值,并合并为电压值,单位为mV
ch[1] = AdcData;
OSTimeDly(OS_TICKS_PER_SEC/10);
diocontrol(ADC2_Handles, GENERAL_SAMPLING, (void *)0); // 使用普通采样
dread(ADC2_Handles, DataBuf, 1); // 读取 ADC 通道 2 转换值
AdcData =(DataBuf[1]<<8) + DataBuf[0]; // 读出电压值,并合并为电压值,单位为mV
ch[2] = AdcData;
OSTimeDly(OS_TICKS_PER_SEC/10);
diocontrol(ADC3_Handles, GENERAL_SAMPLING, (void *)0); // 使用普通采样
dread(ADC3_Handles, DataBuf, 1); // 读取 ADC 通道 3 转换值
AdcData =(DataBuf[1]<<8) + DataBuf[0]; // 读出电压值,并合并为电压值,单位为mV
ch[3] = AdcData;
OSTimeDly(OS_TICKS_PER_SEC/10);
tmp = echo_htm[AD0_NO + 11];
sprintf((char *)echo_htm + AD0_NO,"AIN0=%4dmV",ch[0]);
echo_htm[AD0_NO + 11] = tmp;
tmp = echo_htm[AD1_NO + 11];
sprintf((char *)echo_htm + AD1_NO,"AIN1=%4dmV",ch[1]);
echo_htm[AD1_NO + 11] = tmp;
tmp = echo_htm[AD2_NO + 11];
sprintf((char *)echo_htm + AD2_NO,"AIN2=%4dmV",ch[2]);
echo_htm[AD2_NO + 11] = tmp;
tmp = echo_htm[AD3_NO + 11];
sprintf((char *)echo_htm + AD3_NO,"AIN3=%4dmV",ch[3]);
echo_htm[AD3_NO + 11] = tmp;
}
}
/*******************************************************************************************
** Function name: TASK2
** Descriptions :
** Input : 无
** Output : 无
*******************************************************************************************/
void TASK2(void *pdata)
{
pdata = pdata;
while (1)
{
OSTimeDly(OS_TICKS_PER_SEC);
}
}
/*******************************************************************************************
** Function name: TASK3
** Descriptions :
** Input : 无
** Output : 无
*******************************************************************************************/
void TASK3(void *pdata)
{
pdata = pdata;
while (1)
{
OSTimeDly(OS_TICKS_PER_SEC);
}
}
/*******************************************************************************************
** Function name: TASK4
** Descriptions :
** Input : 无
** Output : 无
*******************************************************************************************/
void TASK4(void *pdata)
{
pdata = pdata;
while (1)
{
OSTimeDly(OS_TICKS_PER_SEC);
}
}
/*******************************************************************************************
** Function name: TASK5
** Descriptions : 系统正常运行指示灯,如果系统正常运行,LDE会正常闪烁。
** Input : 无
** Output : 无
*******************************************************************************************/
void TASK5(void *pdata)
{
pdata = pdata;
while (1)
{
gpio_clr(LED9);
OSTimeDly(OS_TICKS_PER_SEC/10);
gpio_set(LED9);
OSTimeDly(OS_TICKS_PER_SEC/10);
}
}
/*******************************************************************************************
** End Of File
*******************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -