📄 easyweb.c
字号:
/******************************************************************
***** *****
***** Name: easyweb.c *****
***** Ver.: 1.0 *****
***** Date: 07/05/2001 *****
***** Auth: Andreas Dannenberg *****
***** HTWK Leipzig *****
***** university of applied sciences *****
***** Germany *****
***** adannenb@et.htwk-leipzig.de *****
***** Func: implements a dynamic HTTP-server by using *****
***** the easyWEB-API *****
***** Rem.: In IAR-C, use linker option *****
***** "-e_medium_write=_formatted_write" *****
***** *****
******************************************************************/
#include "msp430x14x.h"
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include "easyweb.h"
#include "cs8900.c" // ethernet packet driver
#include "tcpip.c" // easyWEB TCP/IP stack
#include "webside.c" // webside for our HTTP server (HTML)
#define bitset(var,bitno) ((var) |= 1 << (bitno))
#define bitclr(var,bitno) ((var) &= ~(1 << (bitno)))
#define B1 BIT4&P4IN //B1 - P4.4
#define B2 BIT5&P4IN //B2 - P4.5
#define B3 BIT6&P4IN //B3 - P4.6
#define B4 BIT7&P4IN //B4 - P4.7
#define FREQ BIT0&P1IN //FREQuency input - P1.0
#define DI1 BIT1&P1IN //Digital Input 1 - P1.1
#define DI2 BIT2&P1IN //Digital Input 2 - P1.2
#define DI3 BIT3&P1IN //Digital Input 3 - P1.3
#define DI4 BIT4&P1IN //Digital Input 4 - P1.4
#define DALLAS BIT7&P1IN //DALLAS input - P1.7
#define P20 BIT0&P2IN //P20 input
#define SDA BIT0&P4IN //SDA
#define SCL BIT1&P4IN //SCL
#define STATUS_LED_ON P2OUT &= ~BIT1 //STATUS_LED - P2.1
#define STATUS_LED_OFF P2OUT |= BIT1 //STATUS_LED - P2.1
#define RELAY1_ON P1OUT |= BIT5 //RELAY1 - P1.5
#define RELAY1_OFF P1OUT &= ~BIT5 //RELAY1 - P1.5
#define RELAY2_ON P1OUT |= BIT6 //RELAY1 - P1.6
#define RELAY2_OFF P1OUT &= ~BIT6 //RELAY1 - P1.6
#define BUZ1_ON P4OUT |= BIT2 //P4.2
#define BUZ1_OFF P4OUT &= ~BIT2 //P4.2
#define BUZ2_ON P4OUT |= BIT3 //P4.3
#define BUZ2_OFF P4OUT &= ~BIT3 //P4.3
#define LCD_Data P2OUT
#define _100us 66 //66 cycles *12 + 9 = 801 / 801*125ns = 100us
#define _10us 6 //6 cycles * 12 + 9 = 81 / 81*125ns=10us
#define E 3 //P2.3
#define RS 2 //P2.2
#define CR 0x0d
#define LF 0x0a
#define BUTTON_TIME 100
#define DISP_ON 0x0c //LCD control constants
#define DISP_OFF 0x08 //
#define CLR_DISP 0x01 //
#define CUR_HOME 0x02 //
#define ENTRY_INC 0x06 //
#define DD_RAM_ADDR 0x80 //
#define DD_RAM_ADDR2 0xc0 //
#define DD_RAM_ADDR3 0x28 //
#define CG_RAM_ADDR 0x40 //
unsigned char TXData, RXData,i,j,k,temp,RX_flag,cntr,time_out;
const unsigned char UART_Message [] = "http://www.olimex.com/dev";
const unsigned char LCD_Message[] = " Easy WEB ][ by OLIMEX Ltd. ";
const unsigned char DI1_Message[] = " DI1 ";
const unsigned char DI2_Message[] = " DI2 ";
const unsigned char DI3_Message[] = " DI3 ";
const unsigned char DI4_Message[] = " DI4 ";
const unsigned char DALLAS_Message[] = " DALLAS is Ok ";
const unsigned char FREQ_Message[] = "TIMER is clocked";
const unsigned char P6_error_Message[] = " P6 error ";
const unsigned char EXT_error_Message[] = " EXT error ";
void Delay (unsigned int a);
void UART_transmit (unsigned char transmit_data);
void InitUART0 (void);
void Delayx100us(unsigned char b);
void SEND_CHAR (unsigned char c);
void SEND_CMD (unsigned char e);
void _E(void);
void InitLCD(void);
void stopP6(void);
void stop_ext(void);
void main(void)
{
InitOsc();
InitPorts();
InitUART0();
InitLCD();
TCPLowLevelInit(); //after TCPLowLevelInit() UCLK = ACLK = MCLK/4 = 2 000 000 Hz
UART_transmit (CR);
UART_transmit (LF);
for (i=0; i!=26; i++) UART_transmit (UART_Message[i]);
UART_transmit (CR);
UART_transmit (LF);
for (i=0; i!=32; i++)
{
SEND_CHAR(LCD_Message[i]);
if (i==15) SEND_CMD (DD_RAM_ADDR2);
}
SEND_CMD(DD_RAM_ADDR);
RX_flag=0;
cntr = 0;
/*
*(unsigned char *)RemoteIP = 24; // uncomment those lines to get the
*((unsigned char *)RemoteIP + 1) = 8; // quote of the day from a real
*((unsigned char *)RemoteIP + 2) = 69; // internet server! (gateway must be
*((unsigned char *)RemoteIP + 3) = 7; // set to your LAN-router)
TCPLocalPort = 2025;
TCPRemotePort = TCP_PORT_QOTD;
TCPActiveOpen();
while (SocketStatus & SOCK_ACTIVE) // read the quote from memory
{ // by using the hardware-debugger
DoNetworkStuff();
}
*/
HTTPStatus = 0; // clear HTTP-server's flag register
TCPLocalPort = TCP_PORT_HTTP; // set port we want to listen to
while (1) // repeat forever
{
//***********************************************************************************
//this is the begin of my programm
//***********************************************************************************
/*
//test for P6 short cirquit
P6SEL = 0x00; //set P6 as digital I/O
if (P6IN != 0xff) stopP6(); //test for short cirquit to GND
P6OUT = ~BIT0; //set P6 out
P6DIR = BIT0; //set P6.0 to output
for (i=0; i!=8; i++)
{
if(P6OUT != P6IN) stopP6();
P6OUT = (P6OUT << 1) + 1;
P6DIR = P6DIR << 1;
}
P6SEL = 0x80; //restore default settings for P6(AD7)
//P2.0 test
P2OUT &= ~BIT0; //P2.0 is "0"
P2DIR &= ~BIT0; //P2.0 is input
if ((P20) == 0) stop_ext(); //test for "1"
P2DIR |= BIT0; //set P2.0 as output
if ((P20) != 0) stop_ext(); //test for "0"
P2DIR &= ~BIT0; //restore default (input)
//SDA and SCL test //SDA and SCL are inputs
P4OUT &= ~BIT0 & ~BIT1; //SDA and SCL are "0"
P4DIR &= ~BIT0 &~BIT1; //SDA and SCL are inputs
if (((SDA) || (SCL)) == 0) stop_ext(); //test SDA and SCL for "1"
P4DIR &= ~BIT1; //SCL is input
P4DIR |= BIT0; //SDA is output in "0"
if (((SDA) != 0) || ((SCL) == 0)) stop_ext(); //
P4DIR &= ~BIT0; //SDA is input
P4DIR |= BIT1; //SCL is output in "0"
if (((SDA) == 0) || ((SCL) != 0)) stop_ext();
P4DIR &= ~BIT0 & ~BIT1; //SCL and SDA are inputs
*/
//--------------buttons scan---------------------------------------------------------
if ((B1) == 0) //B1 is pressed
{
STATUS_LED_ON; //switch on status_led
SEND_CMD(CLR_DISP);
SEND_CMD(DD_RAM_ADDR);
cntr=0;
}
else STATUS_LED_OFF; //B1 is released
if ((B2) == 0)
{
// time_out = BUTTON_TIME;
// while (time_out != 0)
// if ((B2) == 0) time_out--;
// else time_out = BUTTON_TIME;
Delayx100us(50);
RELAY1_ON;
}
else
{
// time_out = BUTTON_TIME;
// while (time_out != 0)
// if ((B2) != 0) time_out--;
// else time_out = BUTTON_TIME;
Delayx100us(50);
RELAY1_OFF;
}
if ((B3) == 0)
{
Delayx100us(50);
RELAY2_ON; //B3 is pressed
}
else
{
Delayx100us(50);
RELAY2_OFF; //B3 is released
}
while ((B4) == 0) //B4 is pressed
{
BUZ1_OFF;
BUZ2_ON;
Delay(_100us); //buzzer with 5 000 Hz
BUZ2_OFF;
BUZ1_ON;
Delay(_100us);
}
BUZ1_OFF; //B4 is released
BUZ2_OFF;
//--------UART0 receiv scan------------------------------------------------------------------
if (RX_flag == 1) //new receiv byte
{
STATUS_LED_ON;
if (cntr == 0)
{
SEND_CMD(CLR_DISP);
SEND_CMD(DD_RAM_ADDR); //set address for first row
}
SEND_CHAR(RXData);
if(cntr == 15) SEND_CMD(DD_RAM_ADDR2); //set address for second row
if(cntr++ == 31) cntr = 0;
RX_flag = 0;
STATUS_LED_OFF;
}
//---------Digital Inputs scan--------------------------------------------------------------
if ((DI1) == 0) for (i=0 ; i != 5; i++)UART_transmit(DI1_Message[i]);
if ((DI2) == 0) for (i=0 ; i != 5; i++)UART_transmit(DI2_Message[i]);
if ((DI3) == 0) for (i=0 ; i != 5; i++)UART_transmit(DI3_Message[i]);
if ((DI4) == 0) for (i=0 ; i != 5; i++)UART_transmit(DI4_Message[i]);
//---------DALLAS scan ---------------------------------------------------------------------
if ((DALLAS) == 0)
{
cntr=0;
SEND_CMD(CLR_DISP);
SEND_CMD(DD_RAM_ADDR);
for (i=0 ; i!= 14; i++) SEND_CHAR(DALLAS_Message[i]);
}
//---------FREQ scan ----------------------------------------------------------------------
if ((FREQ) != 0)
{
cntr=0;
SEND_CMD(CLR_DISP);
SEND_CMD(DD_RAM_ADDR);
for (i=0 ; i!= 16; i++) SEND_CHAR(FREQ_Message[i]);
}
//***********************************************************************************
//this is the end of my programm
//***********************************************************************************
if (!(SocketStatus & SOCK_ACTIVE)) TCPPassiveOpen(); // listen for incoming TCP-connection
DoNetworkStuff(); // handle network and easyWEB-stack
// events
HTTPServer();
}
}
// This function implements a very simple dynamic HTTP-server.
// It waits until connected, then sends a HTTP-header and the
// HTML-code stored in memory. Before sending, it replaces
// some special strings with dynamic values.
// NOTE: For strings crossing page boundaries, replacing will
// not work. In this case, simply add some extra lines
// (e.g. CR and LFs) to the HTML-code.
void HTTPServer(void)
{
if (SocketStatus & SOCK_CONNECTED) // check if somebody has connected to our TCP
{
if (SocketStatus & SOCK_DATA_AVAILABLE) // check if remote TCP sent data
TCPReleaseRxBuffer(); // and throw it away
if (SocketStatus & SOCK_TX_BUF_RELEASED) // check if buffer is free for TX
{
if (!(HTTPStatus & HTTP_SEND_PAGE)) // init byte-counter and pointer to webside
{ // if called the 1st time
HTTPBytesToSend = sizeof(WebSide) - 1; // get HTML length, ignore trailing zero
PWebSide = (unsigned char *)WebSide; // pointer to HTML-code
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -