#opt 8
#include <18f4620.h>
#fuses XT,NOLVP,NOWDT,NOPROTECT,PUT,NODEBUG,BROWNOUT,NOCPD,NOWRT
#define STACK_USE_PICDEM_LCD TRUE //set to true to put out information on the LCD screen
#use delay(clock=20000000) //CCS picnet is 20Mhz
//You must set one (and only) one of these to TRUE to tell the stack what hardware layer you are using
#define STACK_USE_MAC TRUE //use the nic card
#define STACK_USE_PPP FALSE //use PPP on modem
#define STACK_USE_SLIP FALSE //use slip (NOT TESTED)
#define HTTP_PORT 80 //The TCP Port of your HTTP server. (Most are 80)
char HTML_BODY_TOP[]="<HTML><BODY BGCOLOR=#FFFFFF TEXT=#000000><IMG SRC=http://www.ccsinfo.com/pix/index-ccs.gif><P><H1>ex_st_webserver.c</H1><P>";
char HTML_BODY_BOT[]="<P><A HREF=\"http://www.ccsinfo.com/\">CCS</A></BODY></HTML>";
/// *** END USER CONFIGURABLE DEFINITIONS
#if STACK_USE_MAC
#define STACK_USE_DHCP TRUE //for auto resolution of IP address
#define STACK_USE_ARP TRUE //needed to resolve MAC addresses of IP addresses
#define STACK_USE_UDP TRUE //needed for dhcp
#endif
#define STACK_USE_ICMP TRUE //for ping
#define STACK_USE_TCP TRUE //To send TCP packets (talk to SMTP server)
#define STACK_USE_IP_GLEANING FALSE
#include "drivers\StackTsk.c" //include Microchip's TCP/IP stack
//#include "ccshelper.c" //include CCS's PICDEM.net/PICNET helper functions
//#include "ccshelperui.c"
int8 http_socket;
enum {HTTP_IGNORE, HTTP_LISTEN_WAIT, HTTP_CONNECTED, HTTP_GOT_REQUEST, HTTP_CLOSE, HTTP_CLOSE_WAIT} http_state=HTTP_IGNORE;
void http_state_init(void) {
http_socket=TCPListen(HTTP_PORT);
if (http_socket!=INVALID_SOCKET) {
http_state=HTTP_LISTEN_WAIT;
}
else {
fprintf(USER,"\r\nCouldn't open socket");
#IF STACK_USE_PICDEM_LCD
printf(lcd_putc,"\fERROR, NO SOCK");
#ENDIF
}
}
void http_state_machine(void) {
char buffer[300];
static char c0,c1,c2,c3;
int8 ad0,ad1;
if (!TCPIsConnected(http_socket)) {
http_state=HTTP_LISTEN_WAIT;
}
switch(http_state) {
case HTTP_LISTEN_WAIT:
if (!TCPIsConnected(http_socket)) {
return;
}
http_state=HTTP_CONNECTED;
fprintf(USER,"\r\n\nHTTP Connected");
#IF STACK_USE_PICDEM_LCD
printf(lcd_putc,"\fHTTP Connected");
display_ip_lcd();
#ENDIF
//wait until we get '\r\n\r\n', which marks the end of the HTTP request header
case HTTP_CONNECTED:
if (TCPIsGetReady(http_socket)) {
//fprintf(USER,"\r\nCHAR: ");
while(TCPGet(http_socket,&c3)) {
//fprintf(USER,"%X ",c3);
if ((c0=='\r')&&(c1=='\n')&&(c2=='\r')&&(c3=='\n')) {
fprintf(USER,"\r\nGot Request");
#IF STACK_USE_PICDEM_LCD
printf(lcd_putc,"\fGot Request");
display_ip_lcd();
#ENDIF
TCPFlush(http_socket);
http_state=HTTP_GOT_REQUEST;
}
else {
c0=c1;
c1=c2;
c2=c3;
}
}
}
return;
case HTTP_GOT_REQUEST:
if (TCPIsPutReady(http_socket)) {
set_adc_channel(0);
delay_us(100);
ad0=read_adc();
set_adc_channel(1);
delay_us(100);
ad1=read_adc();
sprintf(buffer,"%s<P><B>AD0: </B>%U<BR><B>AD1: </B>%U%s",HTML_BODY_TOP,ad0,ad1,HTML_BODY_BOT);
if (tcp_putd(http_socket, &buffer[0], strlen(buffer))) {
http_state=HTTP_CLOSE;
fprintf(USER,"\r\nSent Response");
#IF STACK_USE_PICDEM_LCD
printf(lcd_putc,"\fSent Response");
display_ip_lcd();
#ENDIF
}
}
return;
case HTTP_CLOSE:
if (TCPIsPutReady(http_socket)) {
TCPDisconnect(http_socket);
http_state=HTTP_CLOSE_WAIT;
fprintf(USER,"\r\nHTTP Closed");
#IF STACK_USE_PICDEM_LCD
printf(lcd_putc,"\fHTTP Closed");
display_ip_lcd();
#ENDIF
}
return;
//default: return;
}
}
void splash(void) {
#IF STACK_USE_PICDEM_LCD
printf(lcd_putc,"\fCCS ex_st_webserver");
#ENDIF
fprintf(USER,"\r\n\r\nCCS ex_st_webserver\r\n");
ui_settings();
ui_menu();
}
void main(void) {
delay_ms(72);
init();
http_state_init();
splash();
while (TRUE) {
restart_wdt();
if (kbhit(USER)) {
ui_handle();
}
//just something to test the buttons
#if STACK_USE_CCS_PICNET
if (!input(USER_BUTTON1)) {output_high(USER_LED2);}
if (!input(USER_BUTTON2)) {output_low(USER_LED2);}
#elif STACK_USE_MICROCHIP_PICDEM
if (!input(USER_BUTTON1)) {output_low(USER_LED3);} else {output_high(USER_LED3);}
#endif
//every second: refresh current IP, blink LED
if (second_counter>=1) {
display_ip_lcd();
toggle_led();
second_counter=0;
}
#if STACK_USE_PPP
if (ppp_is_connected()) {
#endif
StackTask(); //Microchip's TCP/IP stack handler. Must be called routinely.
http_state_machine(); //This example's HTTP handler. Must be called routinely after StackTask().
#if STACK_USE_PPP
}
#endif
}
}
ADC_SPI_ETH.rar_SPI adc
版权申诉
127 浏览量
2022-09-21
08:24:08
上传
评论
收藏 2KB RAR 举报
JonSco
- 粉丝: 72
- 资源: 1万+
最新资源
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
- 092300108.cpp
- 车类型数据集6000张VOC+YOLO格式.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈