PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > RTOS và Thuật toán với PIC

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

RTOS và Thuật toán với PIC RTOS và Các thuật toán dùng cho PIC/dsPIC/PIC32
Mod: phamminhtuan

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 23-09-2013, 02:18 PM   #4
loitoi
Nhập môn đệ tử
 
Tham gia ngày: Feb 2012
Bài gửi: 2
:
các bạn ơi.ai có thể giải thích cai doan code cho minh được không vây


/////////////////////////////////////////////////////////
Chương trình chính
////////////////////////////////////////////////////
#define THIS_IS_STACK_APPLICATION
#include "TCPIP Stack/TCPIP.h"
#include "MainDemo.h"
APP_CONFIG AppConfig;
BYTE AN0String[8];
#if defined(EXPLORER_16)
int __C30_UART = 2;
#endif
static void InitAppConfig(void);
static void InitializeBoard(void);
static void ProcessIO(void);
#if defined(__18CXX)
#if defined(HI_TECH_C)
void interrupt low_priority LowISR(void)
#else
#pragma interruptlow LowISR
void LowISR(void)
#endif
{
TickUpdate();
}
{
#if defined(ZG_CS_TRIS) zgEintISR();
#endif // ZG_CS_TRIS
}
#if defined(__18CXX)
void main(void)
#else
int main(void)
#endif
{
static TICK t = 0;
static DWORD dwLastIP = 0;
InitializeBoard();
TickInit();
#if defined(STACK_USE_MPFS) || defined(STACK_USE_MPFS2)
MPFSInit();
#endif
InitAppConfig();
if(BUTTON0_IO == 0u)
{
#if defined(EEPROM_CS_TRIS) ||
defined(SPIFLASH_CS_TRIS)
TICK StartTime = TickGet();
LED_PUT(0x00);
}
StackInit();
while(1)
{
if(TickGet() - t >= TICK_SECOND/2ul)
{
t = TickGet();
LED0_IO ^= 1;
}
StackTask();
StackApplications();
#if defined(STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE)
GenericTCPClient();
#endif
#if defined(STACK_USE_GENERIC_TCP_SERVER_EXAMPLE)
GenericTCPServer();
#endif
#if defined(STACK_USE_SMTP_CLIENT)
SMTPDemo();
#endif
#if defined(STACK_USE_ICMP_CLIENT)
PingDemo();
#endif
#if defined(STACK_USE_SNMP_SERVER) && !defined(SNMP_TRAP_DISABLED)
SNMPTrapDemo();
if(gSendTrapFlag)
SNMPSendTrap();
#endif
ProcessIO();
if(dwLastIP != AppConfig.MyIPAddr.Val)
{
dwLastIP = AppConfig.MyIPAddr.Val;
#if defined(STACK_USE_UART)
putrsUART((ROM char*)"\r\nNew IP Address: ");
#endif
DisplayIPValue(AppConfig.MyIPAddr);
#if defined(STACK_USE_UART)
putrsUART((ROM char*)"\r\n");
#endif
#if defined(STACK_USE_ANNOUNCE)
AnnounceIP();
#endif
}
}
}

static void InitializeBoard(void)
{
// LEDs
LED0_TRIS = 0;
LED1_TRIS = 0;
LED2_TRIS = 0;
LED3_TRIS = 0;
LED4_TRIS = 0;
LED5_TRIS = 0;
LED6_TRIS = 0;
#if !defined(EXPLORER_16)
LED7_TRIS = 0;
#endif

///////////////////////////////////////////////////////////////
Xử lí dữ liệu
////////////////////////////////////////////////////
#define __CUSTOMHTTPAPP_C
#include "TCPIPConfig.h"
#if defined(STACK_USE_HTTP2_SERVER)
#include "TCPIP Stack/TCPIP.h"
#include "MainDemo.h"
else if(!memcmppgm2ram(filename, "index.htm", 9))
{
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led7");
if(ptr)
LED7_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led6");
if(ptr)
LED6_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led5");
if(ptr)
LED5_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led4");
if(ptr)
LED4_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led3");
if(ptr)
LED3_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led2");
if(ptr)
LED2_IO = (*ptr == '1');
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led1");
if(ptr)
LED1_IO = (*ptr == '1');
}
else if(!memcmppgm2ram(filename, "cookies.htm", 11))
{
curHTTP.hasArgs = 0x01;
}
else if(!memcmppgm2ram(filename, "leds.cgi", 8))
{
ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led");
switch(*ptr) {
case '1':
LED1_IO ^= 1;
break;
case '2':
LED2_IO ^= 1;
break;
case '3':
LED3_IO ^= 1;
break;
case '4':
LED4_IO ^= 1;
break;
case '5':
LED5_IO ^= 1;
break;
case '6':
LED6_IO ^= 1;
break;
case '7':
LED7_IO ^= 1;
break;
}
}
return HTTP_IO_DONE;
}
SMTPPutROMString((ROM BYTE*)"LEDs:,");
SMTPPut(LED0_IO + '0');
SMTPPut(',');
SMTPPut(LED1_IO + '0');
SMTPPut(',');
SMTPPut(LED2_IO + '0');
SMTPPut(',');
SMTPPut(LED3_IO + '0');
SMTPPut(',');
SMTPPut(LED4_IO + '0');
SMTPPut(',');
SMTPPut(LED5_IO + '0');
SMTPPut(',');
SMTPPut(LED6_IO + '0');
SMTPPut(',');
SMTPPut(LED7_IO + '0');
SMTPPut('\r');
SMTPPut('\n');
SMTPFlush();
//////////////////////////////////////////////////////////////////////////////
Định nghĩa hàm sử dụng
//////////////////////////////////////////////////////////////////////////
#ifndef __TCPIPCONFIG_H
#define __TCPIPCONFIG_H
#include "GenericTypeDefs.h"
#include "Compiler.h"
#define GENERATED_BY_TCPIPCONFIG "Version 1.0.3383.23374"
#define STACK_USE_ICMP_SERVER
#define STACK_USE_HTTP2_SERVER
#define STACK_USE_SMTP_CLIENT
#define STACK_USE_ANNOUNCE
#define MPFS_USE_EEPROM
#define MY_DEFAULT_HOST_NAME "k15evt"
#define MY_DEFULT_MAC_BYTE1 (0x00)
#define MY_DEFAULT_MAC_BYTE2 (0x04)
#define MY_DEFAULT_MAC_BYTE3 (0xA3)
#define MY_DEFAULT_MAC_BYTE4 (0x00)
#define MY_DEFAULT_MAC_BYTE5 (0x00)
#define MY_DEFAULT_MAC_BYTE6 (0x00)

#define MY_DEFAULT_IP_ADDR_BYTE1 (192ul)
#define MY_DEFAULT_IP_ADDR_BYTE2 (168ul)
#define MY_DEFAULT_IP_ADDR_BYTE3 (1ul)
#define MY_DEFAULT_IP_ADDR_BYTE4 (12ul)

#define MY_DEFAULT_MASK_BYTE1 (255ul)
#define MY_DEFAULT_MASK_BYTE2 (255ul)
#define MY_DEFAULT_MASK_BYTE3 (255ul)
#define MY_DEFAULT_MASK_BYTE4 (0ul)

#define MY_DEFAULT_GATE_BYTE1 (192ul)
#define MY_DEFAULT_GATE_BYTE2 (168ul)
#define MY_DEFAULT_GATE_BYTE3 (1ul)
#define MY_DEFAULT_GATE_BYTE4 (1ul)

#define MY_DEFAULT_PRIMARY_DNS_BYTE1 (192ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE2 (168ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE3 (1ul)
#define MY_DEFAULT_PRIMARY_DNS_BYTE4 (1ul)

#define MY_DEFAULT_SECONDARY_DNS_BYTE1 (0ul)
#define MY_DEFAULT_SECONDARY_DNS_BYTE2 (0ul)
#define MY_DEFAULT_SECONDARY_DNS_BYTE3 (0ul)
#define MY_DEFAULT_SECONDARY_DNS_BYTE4 (0ul)
////////////////////////////////////////////////////////////////////////
Định nghĩa I/O
///////////////////////////////////////////////////////////
#elif defined(YOUR_BOARD)
#define LED0_TRIS (TRISDbits.TRISD0)
#define LED0_IO (LATDbits.LATD0)
#define LED1_TRIS (TRISDbits.TRISD1)
#define LED1_IO (LATDbits.LATD1)
#define LED2_TRIS (TRISDbits.TRISD2)
#define LED2_IO (LATDbits.LATD2)
#define LED3_TRIS (TRISDbits.TRISD3)
#define LED3_IO (LATDbits.LATD3)
#define LED4_TRIS (TRISDbits.TRISD4)
#define LED4_IO (LATDbits.LATD4)
#define LED5_TRIS (TRISDbits.TRISD5)
#define LED5_IO (LATDbits.LATD5)
#define LED6_TRIS (TRISDbits.TRISD6)
#define LED6_IO (LATDbits.LATD6)
#define LED7_TRIS (TRISDbits.TRISD7)
#define LED7_IO (LATDbits.LATD7)
#define ENC_CS_TRIS (TRISEbits.TRISE1)
#define ENC_CS_IO (LATEbits.LATE1)
#define ENC_SCK_TRIS (TRISCbits.TRISC3)
#define ENC_SDI_TRIS (TRISCbits.TRISC4)
#define ENC_SDO_TRIS (TRISCbits.TRISC5)
#define EEPROM_CS_TRIS (TRISEbits.TRISE2)
#define EEPROM_CS_IO (LATEbits.LATE2)
#define LCD_RS_TRIS (TRISBbits.TRISB3)
#define LCD_RS_IO (LATBbits.LATB3)
#define LCD_RD_WR_TRIS (TRISBbits.TRISB4)
#define LCD_RD_WR_IO (LATBbits.LATB4)
#define LCD_E_TRIS (TRISBbits.TRISB5)
#define LCD_E_IO (LATBbits.LATB5)
#define LCD_DATA0_TRIS (TRISAbits.TRISA2)
#define LCD_DATA0_IO (LATAbits.LATA2)
#define LCD_DATA1_TRIS (TRISAbits.TRISA3)
#define LCD_DATA1_IO (LATAbits.LATA3)
#define LCD_DATA2_TRIS (TRISAbits.TRISA4)
#define LCD_DATA2_IO (LATAbits.LATA4)
#define LCD_DATA3_TRIS (TRISAbits.TRISA5)
#define LCD_DATA3_IO (LATAbits.LATA5)
///////////////////////////////////////////////////////
giao diện web
////////////////////////////////////////////////
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>ĐỒ ÁN TỐT NGHIỆP</title>
<link href="/mchp.css" rel="stylesheet" type="text/css" />
<script src="/mchp.js" type="text/javascript"></script>
</head>
<body>
<div id="shadow-one"><div id="shadow-two"><div id="shadow-three"><div id="shadow-four">
<div id="page">
<div style="padding:0 0 5px 5px"><img src="/mchp.gif" alt="Microchip" /></div>
<div id="title"><div class="right">CAO ĐẲNG ĐIỆN TỬ VIỄN THÔNG 08C</div><span id="hello">&nbsp;</span></div>
<div id="menu">
<a href="/index.htm">QUAN SÁT</a>
<a href="/dynvars.htm">CẬP NHẬT</a>
<a href="/forms.htm">ĐIỀU KHIỂN</a>
<a href="/email">GỬI EMAIL</a>
</div>
<div id="content">
<div id="status">
<div id="loading" style="display:none">Error:<br />mất kết nối với mạch.</div>
<div id="display">
<span style="float:right;font-size:9px;font-weight:normal;padding-top:8px;text-indent:0px">(bật/tắt)</span>
<p>LEDs:<br /><span class="leds">
<a id="led0">&bull;<br/>
<a id="led1" onclick="newAJAXCommand('leds.cgi?led=1');">&bull; </a>
<a id="led2" onclick="newAJAXCommand('leds.cgi?led=2');">&bull; </a>
<a id="led3" onclick="newAJAXCommand('leds.cgi?led=3');">&bull; </a>
<a id="led4" onclick="newAJAXCommand('leds.cgi?led=4');">&bull; </a>
<a id="led5" onclick="newAJAXCommand('leds.cgi?led=5');">&bull; </a>
<a id="led6" onclick="newAJAXCommand('leds.cgi?led=6');">&bull; </a>
<a id="led7" onclick="newAJAXCommand('leds.cgi?led=7');">&bull; </a>
</span></p>
<p>Buttons:<br />
<span id="btn3">?</span> &nbsp;
<span id="btn2">?</span> &nbsp;
<span id="btn1">?</span> &nbsp;
<span id="btn0">?</span></p>
<p>Điện áp vào: <span id="pot0" style="font-weight:normal">?</span></p>
</div>
</div>
<h2>ĐỒ ÁN TỐT NGHIỆP</h2>
<h2> ĐIỀU KHIỂN THIẾT BỊ QUA INTERNET</h2>
<br />
<img src="images/caothang.jpg" alt="" title="" width="100" height="100" style="float:left; padding-right: 10px; padding-left: 10px;" />
<h3>GVHD: LÊ PHƯỢNG QUYÊN <br />
SVTH: ĐẶNG NGỌC TÙNG <br />
MSSV:152356195 <br /><br />
<a href="mpfsupload"> upload trang web. </a>
<h6></h6>
<form method="post" action="forms.htm">
<div class="examplebox">
<b>LCD:</b> <input type="text" name="lcd" maxlength="32"> &nbsp; <input type="submit" value="Save">
</div>
</form>
</div>
<script type="text/javascript">
<!--
// Parses the xmlResponse from status.xml and updates the status box
function updateStatus(xmlData) {
// Check if a timeout occurred
if(!xmlData)
{
document.getElementById('display').style.display = 'none';
document.getElementById('loading').style.display = 'inline';
return;
}
// Make sure we're displaying the status display
document.getElementById('loading').style.display = 'none';
document.getElementById('display').style.display = 'inline';
// Loop over all the LEDs
for(i = 0; i < 8; i++) {
if(getXMLValue(xmlData, 'led'+i) == '1')
document.getElementById('led' + i).style.color = '#090';
else
document.getElementById('led' + i).style.color = '#ddd';
}
// Loop over all the buttons
for(i = 0; i < 4; i++) {
if(getXMLValue(xmlData, 'btn'+i) == 'up')
document.getElementById('btn' + i).innerHTML = '&Lambda;';
else
document.getElementById('btn' + i).innerHTML = 'V';
}
// Update the POT value
document.getElementById('pot0').innerHTML = getXMLValue(xmlData, 'pot0');
}
setTimeout("newAJAXCommand('status.xml', updateStatus, true)",500);
//-->
</script>
<script type="text/javascript">
<!--
document.getElementById('hello').innerHTML = "~hellomsg~";
//-->
</script>
<div class="spacer">&nbsp;</div>
<div id="footer">cesfabregas01@gmail.com tel 01267689148, Inc.</div>

</div></div></div></div></div>
</body>
</html>
loitoi vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến


Múi giờ GMT. Hiện tại là 03:24 PM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam