// 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 automation[] ="<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 align="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 yellow. More colors @ http://www.computerhope.com/htmcolor.htmchar 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 LATC6_bit=1; if(!memcmp(getRequest 6, "1=OFF", 5)) // do we have OFF command LATC6_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_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; // Comparators off (see pp. 236 of the datasheet) ADCON1 = 0x0F ; // ADC convertors not will be used (see pp. 226 of the datasheet) PORTA = 0; // initialize PORTA to all low TRISA = 0x00 ; // set PORTA as output (see pp. 93 of the datasheet) TRISC.B0 =0; // PORTC.B0 is output. This is the reset pin for the ENC. TRISC.B1 =0; // PORTC.B1 is output. This is the chip select(CS) pin. PORTB = 0 ; // initialize PORTB to all low TRISB = 0x00 ; // set PORTB as output (see pp. 96 of the datasheet) TRISC.B6 =0; /* * 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 } }
void main() { CMCON |=7; // Comparators off (see pp. 236 of the datasheet) ADCON1 = 0x0F ; // ADC convertors not will be used (see pp. 226 of the datasheet) PORTA = 0; // initialize PORTA to all low TRISA = 0x00 ; // set PORTA as output (see pp. 93 of the datasheet) TRISC.B0 =0; // PORTC.B0 is output. This is the reset pin for the ENC. TRISC.B1 =0; // PORTC.B1 is output. This is the chip select(CS) pin. PORTB = 0 ; // initialize PORTB to all low TRISB = 0x00 ; // set PORTB as output (see pp. 96 of the datasheet) TRISC.B6 =0; UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize UART1_Write_Text("1234567891bcdefg"); Delay_ms(100); UART1_Write_Text("1234567891bcdefg"); /* * 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 } }
if(!memcmp(getRequest+6, "1=ON", 4)) // do we have ON command LATC6_bit=1;if(!memcmp(getRequest+6, "1=OFF", 5)) // do we have OFF command LATC6_bit=0; len = putConstString(httpHeader) ; // HTTP header len += putConstString(httpMimeTypeHTML) ; // with HTML MIME type len += SPI_Ethernet_putString(automation) ;
if(!memcmp(getRequest+6, "1=ON", 4)) // do we have ON command { LATC6_bit=1; len = putConstString(httpHeader) ; // HTTP header len += putConstString(httpMimeTypeHTML) ; // with HTML MIME type len += SPI_Ethernet_putString(automation) ; }if(!memcmp(getRequest+6, "1=OFF", 5)) // do we have OFF command { LATC6_bit=0; len = putConstString(httpHeader) ; // HTTP header len += putConstString(httpMimeTypeHTML) ; // with HTML MIME type len += SPI_Ethernet_putString(automation) ; }
Umiilaw nga yung LED sir. Pero, di po namamatay.
Ako din masakit na ang ulo ko sa gutom.Na stress ako kanina sa assignment ni master. Huwag kang mag-alala kunting problema lang yan.Ang importante ok lang ang ENC mo.
Nandoon yon sa kumander niya nagluluto ng hapunan or naglalaba. Pero napailaw daw niya yung LED.
Sa site nila sir carlsberg marami tutorial doon.
Hindi ko makita ang video sir, CP mode kasi ako ngayon e. Natagalan ka ata sa paglalaba sa bahay ni komander a. Hindi ko pa yun na-solve sir. Hinihintay ko pa ang reaction ni master picuser sa code kung tama ba talaga hinala ko. Kung i-da-download ko na kasi yung code na kasali yung line na naipost ko na dito, wala syang reply sa ping ko. Pero kung tatanggalin ko yun, owkey naman sya. Tama naman siguro PIC model ko at clock speed na 32MHz sa microC e. Baka may dahilan talaga to.