嵌入式软件设计第8次实验报告

嵌入式软件设计第8次实验报告

 

学号:140201135                   姓名:沈锦鑫

 组别:第7组           实验地点:D19

 

一、实验目的:

1.熟悉WWW技术中的CGI(公共网关接口)技术。

2.学会使用CGI技术编写C语言代码驱动嵌入式开发板的LED灯和蜂鸣器。

二、实验内容:

1.编写代码完成Web服务器端蜂鸣器的驱动。

2.编写代码完成Web服务器端LED灯的驱动。

三、实验过程描述及结果展示:

CGI技术简介 公共网关接口CGI(Common Gateway Interface)是WWW技术中最重要的技术之一。CGI是外部应用程序与Web服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的规程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI在物理上是一段程序,运行在服务器上,提供同客户端HTML页面的接口。

绝大多数的CGI程序被用来解释处理来自表单的输入信息,并在服务器产生相应的处理,或将相应的信息反馈给浏览器,CGI程序使网页具有交互功能。

LED及蜂鸣器管脚连接图

STM32F407芯片GPIO管脚与LED连接电路图如下所示:

从图中可以看出: PF9,PF10为低电平时,LED0与LED1亮; PF9,PF10为高电平时,LED0与LED1灭。 PF8为高电平时,蜂鸣器响;为低电平时,蜂鸣器不响。

实验实现代码:

#include "sys.h"
#include <string.h>
#include "lwip_comm.h"

//LED灯端口和BEEP端口定义
#define LED1 PFout(10)
#define BEEP PFout(8)

void system_init(void);//系统初始化函数

//控制LED和BEEP的CGI handle;
const char* LEDS_CGI_Handler(int iIndex,
int iNumParams,
char *pcParam[],
char *pcValue[]);
const char* BEEP_CGI_Handler(int iIndex,
int iNumParams,
char *pcParam[],
char *pcValue[]);

//当web客户端请求浏览器的时候,此函数被调用
extern int FindCGIParameter(const char *pcToFind,
char *pcParam[],
int iNumParams);
int main(void)
{
system_init();

//以下代码对蜂鸣器进行初始化
{
GPIO_InitTypeDef GPIO_InitStructure;
//使能GPIOF管脚时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//配置Pin8管脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//输出模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOF,&GPIO_InitStructure);//调用函数对管脚初始化

GPIO_ResetBits(GPIOF,GPIO_Pin_8);//PF8拉低

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//配置Pin10管脚
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//输出模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOF,&GPIO_InitStructure);//调用函数对管脚初始化

GPIO_ResetBits(GPIOF,GPIO_Pin_10);//PF10拉低
}

while(1)
{
lwip_periodic_handle();//lwip轮询任务
}
}
//BEEP的CGI控制句柄
const char* BEEP_CGI_Handler(int iIndex,
int iNumParams,
char *pcParam[],
char *pcValue[])
{
unsigned char i=0;
//找到BEEP的索引号
iIndex = FindCGIParameter("BEEP_TEST",pcParam,iNumParams);
if(iIndex !=-1)
{
BEEP = 0;
for(i=0;i<iNumParams;i++)
{
if(strcmp(pcParam[i],"BEEP_TEST") == 0)//查找CGI参数
{
if(strcmp(pcValue[i],"BEEP_START") == 0)
BEEP = 1;
else if(strcmp(pcValue[i],"BEEP_STOP")==0)
BEEP = 0;
}
}
}

if(BEEP == 1)
return "/BEEP_ON.html";
else
return "/BEEP_OFF.html";
}
const char* LEDS_CGI_Handler(int iIndex,
int iNumParams,
char *pcParam[],
char *pcValue[])
{
unsigned char i=0;
//找到LED的索引号
iIndex = FindCGIParameter("LED_TEST",pcParam,iNumParams);
if(iIndex !=-1)
{
LED1 = 0;
for(i=0;i<iNumParams;i++)
{
if(strcmp(pcParam[i],"LED_TEST") == 0)//查找CGI参数
{
if(strcmp(pcValue[i],"LED_START") == 0)
LED1 = 0;
else if(strcmp(pcValue[i],"LED_STOP")==0)
LED1 = 1;
}
}
}

if(LED1 == 0)
return "/LED1_ON.html";
else
return "/LED1_OFF.html";
}

四、总结及实验心得:

熟悉了WWW技术中的CGI(公共网关接口)技术,还学会了使用CGI技术编写C语言代码驱动嵌入式开发板的LED灯和蜂鸣器。

 

原文地址:https://www.cnblogs.com/hell/p/6573727.html