Prof, femfem,You will need to alter a bit ung code ni master lurker para matest yan without soldering sa pins ng mcu nyo.Consider this as a simple exercise sa inyo. Kaya kaya nyo yan.Let's test your knowledge sa PIC hw architecture and your compiler.ang sisipag nyong magturuan at mag aral. Im considering na gawing give away ung isang sim900 PIM kit ko.Icp muna ko ng magandang challenge.
char automation[] ="<form name=\"input\" action=\"/\" method=\"get\">\<body bgcolor=#99FFCC>\<h1 align=center>ENC28j60 Home Automation System</h1>\<br>\<table align=center width=200 bgcolor=#4974E2 border=2><tr>\<td align=center colspan=2><font size=6><b>Gate</b></font>\</td></tr><tr><td align=center bgcolor=#F52887><input name=\"1\" width=60 \type=\"submit\" value=\"ON\"></td><td align=center bgcolor=#F52887>\<input name=\"1\" type=\"submit\" value=\"OFF\"></td></tr></table>\</form></body></html>";
char automation[] =
"<form name=\"input\" action=\"/\" method=\"get\">\
form name="input"action="/"method="get">
<form name="input" action="/" method="get">
<body bgcolor=#99FFCC>\<h1 align=center>ENC28j60 Home Automation System</h1>\<br>\
<table align=center width=200 bgcolor=#4974E2 border=2><tr>\<td align=center colspan=2><font size=6><b>Gate</b></font>\
</td></tr><tr><td align=center bgcolor=#F52887><input name=\"1\" width=60 \type=\"submit\" value=\"ON\">
input name="1"type="submit"value="ON"
http://192.168.0.111/?1=ON
<td align=center bgcolor=#F52887>\<input name=\"1\" type=\"submit\" value=\"OFF\"></td></tr></table>\
input name="1"type="submit"value="OFF"
http://192.168.0.111/?1=OFF
</form></body></html>";
unsigned int SPI_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength, TEthPktFlags *flags) { unsigned int len; // my reply length if(localPort != 80) // I listen only to web request on port 80 { return(0) ; } // get 15 first bytes only of the request, the rest does not matter here for(len = 0 ; len < 15 ; len++) { getRequest[len] = SPI_Ethernet_getByte() ; } getRequest[len] = 0 ; len = 0; if(memcmp(getRequest, httpMethod, 5)) // only GET method is supported here { return(0) ; } if(!memcmp(getRequest+6, "1=ON", 4)) // do we have ON command LATB0_bit = 1; // set PORTD bit7 if(!memcmp(getRequest+6, "1=OFF", 5)) // do we have OFF command LATB0_bit = 0; len = putConstString(httpHeader) ; // HTTP header len += putConstString(httpMimeTypeHTML) ; // with HTML MIME type len += SPI_Ethernet_putString(automation) ; if(len == 0) // what do to by default { len = putConstString(httpHeader) ; // HTTP header len += putConstString(httpMimeTypeHTML) ; // with HTML MIME type len += SPI_Ethernet_putString(automation) ; } return(len) ; // return to the library with the number of bytes to transmit }
unsigned int SPI_Ethernet_UserTCP()
unsigned int len; // my reply length if(localPort != 80) // I listen only to web request on port 80 { return(0) ; }
for(len = 0 ; len < 15 ; len++) { getRequest[len] = SPI_Ethernet_getByte() ; }
getRequest[len] = 0;
len = 0;
if(memcmp(getRequest, httpMethod, 5)) // only GET method is supported here { return(0) ; }
if(!memcmp(getRequest+6, "1=ON", 4)) // do we have ON command LATB0_bit = 1; // set PORTB bit0
if(!memcmp(getRequest+6, "1=OFF", 5)) // do we have OFF command LATB0_bit = 0; // clear PORTB bit0
len = putConstString(httpHeader) ; // HTTP header len += putConstString(httpMimeTypeHTML) ; // with HTML MIME type len += SPI_Ethernet_putString(automation) ; if(len == 0) // what do to by default { len = putConstString(httpHeader) ; // HTTP header len += putConstString(httpMimeTypeHTML) ; // with HTML MIME type len += SPI_Ethernet_putString(automation) ; } return(len) ; // return to the library with the number of bytes to transmit
^ Grabe si kumander mo makautos.
// duplex config flags#include "__EthEnc28j60.h"#define Spi_Ethernet_HALFDUPLEX 0x00 // half duplex#define Spi_Ethernet_FULLDUPLEX 0x01 // full duplex// mE ehternet NIC pinoutsfr sbit SPI_Ethernet_Rst at LATC0_bit; // for writing to output pin always use latch (PIC18 family)sfr sbit SPI_Ethernet_CS at LATC1_bit; // for writing to output pin always use latch (PIC18 family)sfr sbit SPI_Ethernet_Rst_Direction at TRISC0_bit;sfr sbit SPI_Ethernet_CS_Direction at TRISC1_bit;// end ethernet NIC definitions/************************************************************ * ROM constant strings */const code unsigned char httpHeader[] = "HTTP/1.1 200 OKnContent-type: " ; // HTTP headerconst code unsigned char httpMimeTypeHTML[] = "text/htmlnn" ; // HTML MIME typeconst code unsigned char httpMimeTypeScript[] = "text/plainnn" ; // TEXT MIME typeunsigned char httpMethod[] = "GET /";char Value[] ="<HTML> <title>ASIMO</title><HEAD></HEAD><BODY><center><a href="http://s1262.photobucket.com/albums/ii604/asimo69/?action=view&current=logo.png" target="_blank"><img src="http://i1262.photobucket.com/albums/ii604/asimo69/logo.png" border="0" alt="Photobucket"></a><script src=/s></script><table width="500" border="0"><tr><td colspan="2" style="background-color:#FFA500;"><h1 alighn="center">SWITCH VIA ETHERNET</h1></td></tr><tr valign="top"><br><form name="input" action="/" method="get"><td align=center bgcolor=#FFD700><input name="1" type="submit" value="ON"></td><td align=center bgcolor=#FFD700><input name="1" type="submit" value="OFF"></td></tr></FORM> </td></tr></center><tr><td colspan="2" style="background-color:#FFA500;text-align:center;">Copyright © <a href=http://www.electronicslab.ph/forum/>[url=http://www.electronicslab.ph]www.electronicslab.ph[/url]</a></tr></table></body></html>" ;/*********************************** * RAM variables */unsigned char myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ; // my MAC addressunsigned char myIpAddr[4] = {192, 168, 2, 60 } ; // my IP addressunsigned char gwIpAddr[4] = {192, 168, 2, 144 } ; // gateway (router) IP addressunsigned char ipMask[4] = {255, 255, 255, 0 } ; // network mask (for example : 255.255.255.0)unsigned char dnsIpAddr[4] = {192, 168, 2, 1 } ; // DNS server IP addressunsigned char getRequest[15] ; // HTTP request bufferunsigned char dyna[29] ; // buffer for dynamic responsechar color1[] = "#FFFF00"; // color yellowchar color2[] = "#4974E2"; // color blue#define putConstString SPI_Ethernet_putConstString#define putString SPI_Ethernet_putStringunsigned int SPI_Ethernet_UserTCP(unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength, TEthPktFlags *flags) { unsigned int len; // my reply length if(localPort != 80) // I listen only to web request on port 80 { return(0) ; } // get 15 first bytes only of the request, the rest does not matter here for(len = 0 ; len < 15 ; len ) { getRequest[len] = SPI_Ethernet_getByte() ; } getRequest[len] = 0 ; len = 0; if(memcmp(getRequest, httpMethod, 5)) // only GET method is supported here { return(0) ; } if(!memcmp(getRequest 6, "1=ON", 4)) // do we have ON command PORTC=0x40; if(!memcmp(getRequest 6, "1=OFF", 5)) // do we have OFF command PORTC=0x00; len = putConstString(httpHeader) ; // HTTP header len = putConstString(httpMimeTypeHTML) ; // with HTML MIME type len = SPI_Ethernet_putString(Value) ; if(len == 0) // what do to by default { len = putConstString(httpHeader) ; // HTTP header len = putConstString(httpMimeTypeHTML) ; // with HTML MIME type len = SPI_Ethernet_putString(Value) ; } return(len) ; // return to the library with the number of bytes to transmit }unsigned int SPI_Ethernet_UserUDP(unsigned char *remoteHost, unsigned int remotePort, unsigned int destPort, unsigned int reqLength, TEthPktFlags *flags) { return(0) ; // no UDP reply }/* * main entry */long i;void main() { //CMCON |=7; ADCON0= 0; ADCON1 = 0x0F ; // ADC convertors will be used ADCON2 = 0x40; PORTA = 0 ; TRISA = 0x00 ; // set PORTA as input for ADC TRISC = 0; // set direction to be output /* * starts ENC28J60 with : * reset bit on RC0 * CS bit on RC1 * my MAC & IP address * full duplex */ SPI1_Init(); SPI_Rd_Ptr = SPI1_Read; SPI_Ethernet_Init(myMacAddr, myIpAddr, Spi_Ethernet_FULLDUPLEX) ; // dhcp will not be used here, so use preconfigured addresses SPI_Ethernet_confNetwork(ipMask, gwIpAddr, dnsIpAddr) ; while(1) // do forever { /* * if necessary, test the return value to get error code */ SPI_Ethernet_doPacket() ; // process incoming Ethernet packets } }