• 嵌入式第9次实验


    学号:140201236                姓名:沈樟伟

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

    一、实验目的:

    1.熟悉WWW技术中的SSI(Server Side Include)技术。

    2.学会使用SSI技术编写代码把当前开发板内RTC的时钟及日期数据送往PC机浏览器显示。

    3.学会使用SSI技术把当前开发板的按键(KEY2、KEY1)次数信息送往PC机浏览器显示。

    二、实验内容:

    1.编写代码完成Web服务器端发送RTC实时时

    钟信息的任务。

    2.编写代码完成Web服务器端发送按键(KEY2、KEY1)按键次数的任务。

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

    实验器材:STM32F407开发板、LCD显示屏

    1、实验原理

    SSI技术简介

    服务器端嵌入SSI(Server Side Include)是一种基于服务器的网页制作技术。大多数的WEB服务器等均支持SSI

    命令。将内容发送到浏览器之前,可以使用“SSI”指令将文本、图形或应用程序信息包含到网页中。因为包

    含SSI指令的文件要求特殊处理,所以必须为所有SSI文件赋予SSI文件扩展名。默认的扩展名是.stm、.shtm、

    .shtml。

        SSI是为WEB服务器提供的一套命令,这些命令只要直接嵌入到HTML文档的注释内容之中即可。如:<!=--

    #include file = “info.htm”-->就是一条SSI指令,其作用是将“info.htm”的内容拷贝到当前页面中。

    <!=-- -->是HTML语法中的注释,当WEB服务器不支持SSI时,会忽略这些信息。

    2、按键与STM32的硬件连接图

    STM32F407芯片与键盘的连接电路图如下所示:

     

    3、程序代码

    #include "sys.h"

    #include <string.h>

    #include "delay.h"

    #include "httpd.h"

    #include "lwip/tcp.h"

    #include "fs.h"

    #include "lwip_comm.h"

    void system_init(void);

     void RTCTime_Handler(char *pcInsert);

     void RTCDate_Handler(char *pcInsert);

     void RTCKey1_Handler(char *pcInsert);

     void RTCKey2_Handler(char *pcInsert);

    const char *ppcTAGs[]=

    {

      "time",

           "date",

           "key2",

           "key1"

    };

    u8 key1=0,key2=0;

    void EXTI2_IRQHandler(void){

           delay_ms(10);

           key1++;

           printf("%d ",key1);

           EXTI_ClearITPendingBit(EXTI_Line2);

    }

    void EXTI3_IRQHandler(void){

           delay_ms(10);

           key2++;

           printf("%d ",key2);

           EXTI_ClearITPendingBit(EXTI_Line3);

    }

    void EXTIX_Init(void)

    {

           NVIC_InitTypeDef   NVIC_InitStructure;

           EXTI_InitTypeDef   EXTI_InitStructure;

         

           KEY_Init(); //按键对应的I/O初始化

           RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//使能SYSCFG时钟

         

           SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource2);//PE2 连接到中断线2

           SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource3);//PE3 连接到中断线3

         

           /*配置EXTI_Line2,3,4 */

           EXTI_InitStructure.EXTI_Line = EXTI_Line2 | EXTI_Line3 /*| EXTI_Line4*/;

      EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//中断事件

      EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿触发

      EXTI_InitStructure.EXTI_LineCmd = ENABLE;//中断线使能

      EXTI_Init(&EXTI_InitStructure);//配置

         

    NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;//外部中断2

      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x03;//抢占优先级3

      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//子优先级2

      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道

      NVIC_Init(&NVIC_InitStructure);//配置

         

         

           NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;//外部中断3

      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;//抢占优先级2

      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;//子优先级 2

      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道

      NVIC_Init(&NVIC_InitStructure);//配置

         

            

    }

    int main(void)

    {

       system_init();//系统化初始化

           //以下代码对RTC进行初始化

         

           {

                  RTC_InitTypeDef RTC_InitStructure;

                

                  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);//使能电源接口时钟

                  PWR_BackupAccessCmd(ENABLE);//使能RTC+SRAM区域

                

                  RCC_LSEConfig(RCC_LSE_ON);//开启LSE时钟

                  RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); //选择LSE时钟作为RTC时钟

                  while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET); //等待LSE准备好

                

                  RCC_RTCCLKCmd(ENABLE);//使能RTC时钟

                

                  while(RTC_Wait_Synchro());//等待RTC和APB同步

                

                  RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24;//24小时格式

                  RTC_InitStructure.RTC_SynchPrediv = 0xFF;//同步预分频器

                  RTC_InitStructure.RTC_AsynchPrediv = 0x7F;//异步预分频器

                

                  RTC_Set_Time(10,0,0,0);//设置时间

                  RTC_Set_Date(17,3,20,1);//设置日期

         

         

         

           }

        EXTIX_Init();

           //uart_init(115200);       //串口初始化

         

           while(1)

           {

             

         lwip_periodic_handle();//LWIP轮询任务

                

           }

    }

    //SSI的Handler

    u16_t SSIHandler(int iIndex,char *pcInsert,int iInsertLen)

    {

    switch(iIndex)//iIndex索引号

    {

           case 0:

                          RTCTime_Handler(pcInsert);

                     break;

           case 1:

                        RTCDate_Handler(pcInsert);

                     break;

           case 2:

                        RTCKey2_Handler(pcInsert);

                     break;

           case 3:

                        RTCKey1_Handler(pcInsert);

                     break;

    }

    return strlen(pcInsert);

    }

    //SSIHandler中需要用到的处理RTC时间的函数

    void RTCTime_Handler(char *pcInsert)

    {

      u8 hour,min,sec,ampm;

           RTC_Get_Time(&hour,&min,&sec,&ampm);

         

           *(pcInsert+0) = (char)((hour/10)+0x30);

           *(pcInsert+1) = (char)((hour%10)+0x30);

           *(pcInsert+2) = ':';

      *(pcInsert+3) = (char)((min/10)+0x30);

           *(pcInsert+4) = (char)((min%10)+0x30);

           *(pcInsert+5) = ':';

           *(pcInsert+6) = (char)((sec/10)+0x30);

           *(pcInsert+7) = (char)((sec%10)+0x30);

    }

    void RTCDate_Handler(char *pcInsert)

    {

    u8 year,month,day,week;

    RTC_Get_Date(&year,&month,&day,&week);

         

           *(pcInsert+0) = '2';

           *(pcInsert+1) = '0';

           *(pcInsert+2) = (char)((year/10)+0x30);

           *(pcInsert+3) = (char)((year%10)+0x30);

           *(pcInsert+4) = '-';

           *(pcInsert+5) = (char)((month/10)+0x30);

           *(pcInsert+6) = (char)((month%10)+0x30);

           *(pcInsert+7) = '-';

           *(pcInsert+8) = (char)((day/10)+0x30);

           *(pcInsert+9) = (char)((day%10)+0x30);

           *(pcInsert+10) = ' ';

           *(pcInsert+11) = 'w';

           *(pcInsert+12) = 'e';

           *(pcInsert+13) = 'e';

           *(pcInsert+14) = 'k';

           *(pcInsert+15) = ':';;

           *(pcInsert+16) = (char)(week+0x30);

    }

    void RTCKey1_Handler(char *pcInsert)

    {

           if (key1<10)

           {

                  *(pcInsert+0) = (char)(key1+0x30);

                  *(pcInsert+1) = '';

           }

           else

           {

                  *(pcInsert+0) = (char)((key1/10)+0x30);

                  *(pcInsert+1) = (char)((key1%10)+0x30);

                  *(pcInsert+2) = '';

           }

    }

    void RTCKey2_Handler(char *pcInsert)

    {

           if (key2<10)

           {

                  *(pcInsert+0) = (char)(key2+0x30);

                  *(pcInsert+1) = '';

           }

           else

           {

                  *(pcInsert+0) = (char)((key2/10)+0x30);

                  *(pcInsert+1) = (char)((key2%10)+0x30);

                  *(pcInsert+2) = '';     

           }

    }

    实验结果展示:

     

    四、总结及实验心得:

      实验就是将学习到的知识点在实践中的应用。本次实验室熟悉WWW技术中的SSI(Server Side Include)技术,并学会使用SSI技术编写代码把当前开发板内RTC的时钟及日期数据送往PC机浏览器显示。使用SSI技术把当前开发板的按键(KEY2、KEY1)次数信息送往PC机浏览器显示。

      实验过程还算顺利,原本就是因为电脑硬件上除了点问题,本地网络连接异常。在后来,检查了接口的连接之后,解决了这个问题。

      

  • 相关阅读:
    中国的网游,发人深省
    .NET开源Bug管理软件BugTracker.NET使用小记
    开源的学术论文排版软件TeX简介
    在sqlplus中批量执行sql命令
    DotNetBar中ExpandableSplitter使用技巧
    上传一很酷的黑色背景.vssettings文件
    瑞雪兆丰年2008年的第一场雪
    Oracle用Start with...Connect By子句递归查询
    【转载】Making new features with topology tools(ArcInfo and ArcEditor only)
    Geoprocess Execute出错原因?Vb+AE9.2
  • 原文地址:https://www.cnblogs.com/shenzhangwei/p/6623933.html
Copyright © 2020-2023  润新知