📄 easyweb.i
字号:
const __no_init volatile unsigned short TAIV @ (0x012E);
__no_init volatile unsigned short TACTL @ (0x0160);
__no_init volatile unsigned short TACCTL0 @ (0x0162);
__no_init volatile unsigned short TACCTL1 @ (0x0164);
__no_init volatile unsigned short TACCTL2 @ (0x0166);
__no_init volatile unsigned short TAR @ (0x0170);
__no_init volatile unsigned short TACCR0 @ (0x0172);
__no_init volatile unsigned short TACCR1 @ (0x0174);
__no_init volatile unsigned short TACCR2 @ (0x0176);
const __no_init volatile unsigned short TBIV @ (0x011E);
__no_init volatile unsigned short TBCTL @ (0x0180);
__no_init volatile unsigned short TBCCTL0 @ (0x0182);
__no_init volatile unsigned short TBCCTL1 @ (0x0184);
__no_init volatile unsigned short TBCCTL2 @ (0x0186);
__no_init volatile unsigned short TBCCTL3 @ (0x0188);
__no_init volatile unsigned short TBCCTL4 @ (0x018A);
__no_init volatile unsigned short TBCCTL5 @ (0x018C);
__no_init volatile unsigned short TBCCTL6 @ (0x018E);
__no_init volatile unsigned short TBR @ (0x0190);
__no_init volatile unsigned short TBCCR0 @ (0x0192);
__no_init volatile unsigned short TBCCR1 @ (0x0194);
__no_init volatile unsigned short TBCCR2 @ (0x0196);
__no_init volatile unsigned short TBCCR3 @ (0x0198);
__no_init volatile unsigned short TBCCR4 @ (0x019A);
__no_init volatile unsigned short TBCCR5 @ (0x019C);
__no_init volatile unsigned short TBCCR6 @ (0x019E);
__no_init volatile unsigned char DCOCTL @ (0x0056);
__no_init volatile unsigned char BCSCTL1 @ (0x0057);
__no_init volatile unsigned char BCSCTL2 @ (0x0058);
__no_init volatile unsigned short FCTL1 @ (0x0128);
__no_init volatile unsigned short FCTL2 @ (0x012A);
__no_init volatile unsigned short FCTL3 @ (0x012C);
__no_init volatile unsigned char CACTL1 @ (0x0059);
__no_init volatile unsigned char CACTL2 @ (0x005A);
__no_init volatile unsigned char CAPD @ (0x005B);
__no_init volatile unsigned short ADC12CTL0 @ (0x01A0);
__no_init volatile unsigned short ADC12CTL1 @ (0x01A2);
__no_init volatile unsigned short ADC12IFG @ (0x01A4);
__no_init volatile unsigned short ADC12IE @ (0x01A6);
__no_init volatile unsigned short ADC12IV @ (0x01A8);
__no_init volatile unsigned short ADC12MEM0 @ (0x0140);
__no_init volatile unsigned short ADC12MEM1 @ (0x0142);
__no_init volatile unsigned short ADC12MEM2 @ (0x0144);
__no_init volatile unsigned short ADC12MEM3 @ (0x0146);
__no_init volatile unsigned short ADC12MEM4 @ (0x0148);
__no_init volatile unsigned short ADC12MEM5 @ (0x014A);
__no_init volatile unsigned short ADC12MEM6 @ (0x014C);
__no_init volatile unsigned short ADC12MEM7 @ (0x014E);
__no_init volatile unsigned short ADC12MEM8 @ (0x0150);
__no_init volatile unsigned short ADC12MEM9 @ (0x0152);
__no_init volatile unsigned short ADC12MEM10 @ (0x0154);
__no_init volatile unsigned short ADC12MEM11 @ (0x0156);
__no_init volatile unsigned short ADC12MEM12 @ (0x0158);
__no_init volatile unsigned short ADC12MEM13 @ (0x015A);
__no_init volatile unsigned short ADC12MEM14 @ (0x015C);
__no_init volatile unsigned short ADC12MEM15 @ (0x015E);
__no_init volatile unsigned char ADC12MCTL0 @ (0x0080);
__no_init volatile unsigned char ADC12MCTL1 @ (0x0081);
__no_init volatile unsigned char ADC12MCTL2 @ (0x0082);
__no_init volatile unsigned char ADC12MCTL3 @ (0x0083);
__no_init volatile unsigned char ADC12MCTL4 @ (0x0084);
__no_init volatile unsigned char ADC12MCTL5 @ (0x0085);
__no_init volatile unsigned char ADC12MCTL6 @ (0x0086);
__no_init volatile unsigned char ADC12MCTL7 @ (0x0087);
__no_init volatile unsigned char ADC12MCTL8 @ (0x0088);
__no_init volatile unsigned char ADC12MCTL9 @ (0x0089);
__no_init volatile unsigned char ADC12MCTL10 @ (0x008A);
__no_init volatile unsigned char ADC12MCTL11 @ (0x008B);
__no_init volatile unsigned char ADC12MCTL12 @ (0x008C);
__no_init volatile unsigned char ADC12MCTL13 @ (0x008D);
__no_init volatile unsigned char ADC12MCTL14 @ (0x008E);
__no_init volatile unsigned char ADC12MCTL15 @ (0x008F);
#pragma language=default
extern void DelayCycles(unsigned int Count);
extern void WriteDWBE(unsigned char *Add, unsigned long Data);
typedef enum
{
CLOSED,
LISTENING,
SYN_SENT,
SYN_RECD,
ESTABLISHED,
FIN_WAIT_1,
FIN_WAIT_2,
CLOSE_WAIT,
CLOSING,
LAST_ACK,
TIME_WAIT
} TTCPStateMachine;
typedef enum
{
ARP_REQUEST,
TCP_SYN_FRAME,
TCP_SYN_ACK_FRAME,
TCP_FIN_FRAME,
TCP_DATA_FRAME
} TLastFrameSent;
void TCPLowLevelInit(void);
void TCPPassiveOpen(void);
void TCPActiveOpen(void);
void TCPClose(void);
void TCPReleaseRxBuffer(void);
void TCPTransmitTxBuffer(void);
void DoNetworkStuff(void);
extern const unsigned int MyIP[];
extern const unsigned int SubnetMask[];
extern const unsigned int GatewayIP[];
extern unsigned char SocketStatus;
extern unsigned int TCPLocalPort;
extern unsigned int TCPRemotePort;
extern unsigned int RemoteMAC[3];
extern unsigned int RemoteIP[2];
extern unsigned int TCPRxDataCount;
extern unsigned int TCPTxDataCount;
extern unsigned int TxFrame1Mem[];
extern unsigned int RxTCPBufferMem[];
const unsigned char WebSide[] =
{
"<html>\r\n"
"<head>\r\n"
"<meta http-equiv=\"refresh\" content=\"5\">\r\n"
"<title>easyWEB - dynamic Webside</title>\r\n"
"</head>\r\n"
"\r\n"
"<body bgcolor=\"#3030A0\" text=\"#FFFF00\">\r\n"
"<p><b><font color=\"#FFFFFF\" size=\"6\"><i>Hello World!</i></font></b></p>\r\n"
"\r\n"
"<p><b>This is a dynamic webside hosted by the embedded Webserver</b> <b>easyWEB.</b></p>\r\n"
"<p><b>Hardware:</b></p>\r\n"
"<ul>\r\n"
"<li><b>MSP430F149, 8 MHz, 60KB Flash, 2KB SRAM</b></li>\r\n"
"<li><b>CS8900A Crystal Ethernet Controller</b></li>\r\n"
"</ul>\r\n"
"\r\n"
"<p><b>A/D Converter Value Port P6.7:</b></p>\r\n"
"\r\n"
"<table bgcolor=\"#ff0000\" border=\"5\" cellpadding=\"0\" cellspacing=\"0\" width=\"500\">\r\n"
"<tr>\r\n"
"<td>\r\n"
"<table width=\"AD7%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\r\n"
"<tr><td bgcolor=\"#00ff00\"> </td></tr>\r\n"
"</table>\r\n"
"</td>\r\n"
"</tr>\r\n"
"</table>\r\n"
"\r\n"
"<table border=\"0\" width=\"500\">\r\n"
"<tr>\r\n"
"<td width=\"20%\">0V</td>\r\n"
"<td width=\"20%\">0.4V</td>\r\n"
"<td width=\"20%\">0.7V</td>\r\n"
"<td width=\"20%\">1.1V</td>\r\n"
"<td width=\"20%\">1.5V</td>\r\n"
"</tr>\r\n"
"</table>\r\n"
"\r\n"
"<p><b>MCU Temperature:</b></p>\r\n"
"\r\n"
"<table bgcolor=\"#ff0000\" border=\"5\" cellpadding=\"0\" cellspacing=\"0\" width=\"500\">\r\n"
"<tr>\r\n"
"<td>\r\n"
"<table width=\"ADA%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\r\n"
"<tr><td bgcolor=\"#00ff00\"> </td></tr> \r\n"
"</table>\r\n"
"</td>\r\n"
"</tr>\r\n"
"</table>\r\n"
"\r\n"
"<table border=\"0\" width=\"500\">\r\n"
"<tr>\r\n"
"<td width=\"20%\">0癈</td>\r\n"
"<td width=\"20%\">10癈</td>\r\n"
"<td width=\"20%\">20癈</td>\r\n"
"<td width=\"20%\">30癈</td>\r\n"
"<td width=\"20%\">40癈</td>\r\n"
"</tr>\r\n"
"</table>\r\n"
"</body>\r\n"
"</html>\r\n"
"\r\n"
};
static const unsigned char GetResponse[] =
{
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"\r\n"
};
static unsigned char *PWebSide;
static unsigned int HTTPBytesToSend;
static unsigned char HTTPStatus;
static const unsigned int Temp_Tab[] =
{
0x064F,
0x0655,
0x065B,
0x0660,
0x0666,
0x066C,
0x0672,
0x0678,
0x067D,
0x0683,
0x0689,
0x068F,
0x0695,
0x069B,
0x06A0,
0x06A6,
0x06AC,
0x06B2,
0x06B8,
0x06BD,
0x06C3,
0x06C9,
0x06CF,
0x06D5,
0x06DB,
0x06E0,
0x06E6,
0x06EC,
0x06F2,
0x06F8,
0x06FD,
0x0703,
0x0709,
0x070F,
0x0715,
0x071B,
0x0720,
0x0726,
0x072C,
0x0732,
0x0738,
0x073D,
0x0743,
0x0749,
0x074F,
0x0755,
0x0FFF
};
static void InitOsc(void);
static void InitPorts(void);
static void InitADC12(void);
static void HTTPServer(void);
static void InsertDynamicValues(void);
static unsigned int GetAD7Val(void);
static unsigned int GetTempVal(void);
void main(void)
{
InitOsc();
InitPorts();
InitADC12();
TCPLowLevelInit();
__enable_interrupt();
HTTPStatus = 0;
TCPLocalPort = 80;
while (1)
{
if (!(SocketStatus & (0x01))) TCPPassiveOpen();
HTTPServer();
}
}
static void HTTPServer(void)
{
if (SocketStatus & (0x02))
{
if (SocketStatus & (0x04))
TCPReleaseRxBuffer();
if (SocketStatus & (0x08))
{
if (!(HTTPStatus & (0x01)))
{
HTTPBytesToSend = sizeof(WebSide) - 1;
PWebSide = (unsigned char *)WebSide;
}
if (HTTPBytesToSend > 768)
{
if (!(HTTPStatus & (0x01)))
{
memcpy(((unsigned char *)TxFrame1Mem + 14 + 20 + 20), GetResponse, sizeof(GetResponse) - 1);
memcpy(((unsigned char *)TxFrame1Mem + 14 + 20 + 20) + sizeof(GetResponse) - 1, PWebSide,
768 - sizeof(GetResponse) + 1);
HTTPBytesToSend -= 768 - sizeof(GetResponse) + 1;
PWebSide += 768 - sizeof(GetResponse) + 1;
}
else
{
memcpy(((unsigned char *)TxFrame1Mem + 14 + 20 + 20), PWebSide, 768);
HTTPBytesToSend -= 768;
PWebSide += 768;
}
TCPTxDataCount = 768;
InsertDynamicValues();
TCPTransmitTxBuffer();
}
else if (HTTPBytesToSend)
{
memcpy(((unsigned char *)TxFrame1Mem + 14 + 20 + 20), PWebSide, HTTPBytesToSend);
TCPTxDataCount = HTTPBytesToSend;
InsertDynamicValues();
TCPTransmitTxBuffer();
TCPClose();
HTTPBytesToSend = 0;
}
HTTPStatus |= (0x01);
}
}
else
HTTPStatus &= ~(0x01);
}
static unsigned int GetAD7Val(void)
{
ADC12MCTL0 = (1*0x10u) + (7);
ADC12CTL0 |= (0x002);
ADC12CTL0 |= (0x001);
while (ADC12CTL0 & (0x001));
ADC12CTL0 &= ~(0x002);
return ADC12MEM0 >> 5;
}
static unsigned int GetTempVal(void)
{
unsigned int i;
unsigned int ADCResult;
ADC12MCTL0 = (1*0x10u) + (10);
ADC12CTL0 |= (0x002);
ADC12CTL0 |= (0x001);
while (ADC12CTL0 & (0x001));
ADC12CTL0 &= ~(0x002);
ADCResult = ADC12MEM0;
for (i = 0; i < sizeof Temp_Tab; i++)
if (ADCResult < Temp_Tab[i])
break;
return i << 1;
}
static void InsertDynamicValues(void)
{
char *Key;
char NewKey[5];
int i;
if (TCPTxDataCount < 4) return;
Key = (char *)((unsigned char *)TxFrame1Mem + 14 + 20 + 20);
for (i = 0; i < TCPTxDataCount - 3; i++)
{
if (*Key == 'A')
if (*(Key + 1) == 'D')
if (*(Key + 3) == '%')
if (*(Key + 2) == '7')
{
sprintf(NewKey, "%3u", GetAD7Val());
memcpy(Key, NewKey, 3);
}
else if (*(Key + 2) == 'A')
{
sprintf(NewKey, "%3u", GetTempVal());
memcpy(Key, NewKey, 3);
}
Key++;
}
}
static void InitOsc(void)
{
WDTCTL = (0x5A00) + (0x0080);
BCSCTL1 |= (0x40);
__bic_SR_register((0x0020));
do
{
IFG1 &= ~(0x02);
DelayCycles(100);
} while (IFG1 & (0x02));
BCSCTL2 = (0xC0);
}
static void InitPorts(void)
{
P1OUT = 0;
P1DIR = 0xff;
P2OUT = 0;
P2DIR = 0xff;
P4OUT = 0;
P4DIR = 0xff;
P6SEL = 0x80;
P6OUT = 0;
P6DIR = 0x7f;
}
static void InitADC12(void)
{
ADC12CTL0 = (0x010) + (0x020) + (0x040) + (6*0x100u);
ADC12CTL1 = (0*0x400u) + (0x0200) + (0*2u);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -