📄 easyweb.c
字号:
//------------------------------------------------------------------------------
// Name: easyweb.c
// Func: implements a dynamic HTTP-server by using
// the easyWEB-API
// Ver.: 1.1
// Date: January 2004
// Auth: Andreas Dannenberg
// MSP430 Applications
// Texas Instruments Inc.
// Rem.: - For detailed software/hardware information refer to MSP430
// application note SLAA137 (www.ti.com/msp430)
// - Build with IAR EW V2.21B
// - The compiler option "Formatted write" should be set to "Medium"
// (to ensure proper operation of the sprintf() function)
//------------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "msp430x14x.h"
#include "support.h"
#include "easyweb.h"
#include "tcpip.h" // easyWEB TCP/IP stack
#include "webside.c" // webside for our HTTP server (HTML)
unsigned char data[3]={0x01,0x55,0xff};
//------------------------------------------------------------------------------
// ADC12 Module Temperature Table
//
// These values assume nominal values for the temp sensor and
// temperature coefficient. They also assume the 2.5V internal
// reference is used for the conversion. The transfer function out
// of the MSP430x1xx Family User's Guide has been used.
//------------------------------------------------------------------------------
static const unsigned int Temp_Tab[] =
{
0x064F, // 0C
0x0655,
0x065B,
0x0660,
0x0666,
0x066C, // 5C
0x0672,
0x0678,
0x067D,
0x0683,
0x0689, // 10C
0x068F,
0x0695,
0x069B,
0x06A0,
0x06A6, // 15C
0x06AC,
0x06B2,
0x06B8,
0x06BD,
0x06C3, // 20C
0x06C9,
0x06CF,
0x06D5,
0x06DB,
0x06E0, // 25C
0x06E6,
0x06EC,
0x06F2,
0x06F8,
0x06FD, // 30C
0x0703,
0x0709,
0x070F,
0x0715,
0x071B, // 35C
0x0720,
0x0726,
0x072C,
0x0732,
0x0738, // 40C
0x073D,
0x0743,
0x0749,
0x074F,
0x0755, // 45C
0x0FFF // Too high
};
//------------------------------------------------------------------------------
// Local function prototypes
//------------------------------------------------------------------------------
static void InitOsc(void);
static void InitPorts(void);
static void InitADC12(void);
//static void InsertDynamicValues(void);
//static unsigned int GetAD7Val(void);
//static unsigned int GetTempVal(void);
//------------------------------------------------------------------------------
void main(void)
{
InitOsc();
InitPorts();
//InitADC12();
TCPLowLevelInit();
__enable_interrupt(); // enable interrupts
//HTTPStatus = 0; // clear HTTP-server's flag register
TCPLocalPort = TCP_PORT_HTTP; // set port we want to listen to
while (1) // repeat forever
{
if (!(SocketStatus & SOCK_ACTIVE)) TCPPassiveOpen(); // listen for incoming TCP-connection
//DoNetworkStuff(); // handle network and easyWEB-stack
// events
{ 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
memcpy(TCP_TX_BUF,data,3);
TCPTxDataCount=3;
TCPTransmitTxBuffer(); // send last segment
TCPClose();
}// and close connection
}
}
//------------------------------------------------------------------------------
// 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.
//------------------------------------------------------------------------------
}
//------------------------------------------------------------------------------
// samples and returns the AD-converter value of channel 7
// (associated with Port P6.7)
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// samples and returns AD-converter value of channel 10
// (MSP430 internal temperature reference diode)
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// searches the TX-buffer for special strings and replaces them
// with dynamic values (AD-converter results)
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// enables the 8MHz crystal on XT1 and use
// it as MCLK
//------------------------------------------------------------------------------
static void InitOsc(void)
{
WDTCTL = WDTPW + WDTHOLD; // stop watchdog timer
BCSCTL1 |= XTS; // XT1 as high-frequency
__bic_SR_register(OSCOFF); // turn on XT1 oscillator
do
{
IFG1 &= ~OFIFG; // Clear OFIFG
DelayCycles(100); // Wait ~130us
} while (IFG1 & OFIFG); // Test oscillator fault flag
BCSCTL2 = SELM_3; // set XT1 as MCLK
}
//------------------------------------------------------------------------------
static void InitPorts(void)
{
P1OUT = 0; // switch all unused ports to output
P1DIR = 0xff; // (Rem.: ports 3 & 5 are set in "cs8900.c")
P2OUT = 0;
P2DIR = 0xff;
P4OUT = 0;
P4DIR = 0xff;
P6SEL = 0x80; // use P6.7 for the ADC module
P6OUT = 0;
P6DIR = 0x7f; // all output except P6.7
}
//------------------------------------------------------------------------------
static void InitADC12(void)
{
ADC12CTL0 = ADC12ON + REFON + REF2_5V + SHT0_6;// Turn on ADC12, 2.5Vref, set SHT0
ADC12CTL1 = SHS_0 + SHP + CONSEQ_0; // Use sampling timer, ADC12SC
// triggers conversion,
// single channel single conversion,
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -