caramoan tour package

caramoan tour package

Author Topic: MikroC's SPI Ethernet ENC28J60 Library  (Read 9683 times)

Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #420 on: May 28, 2012, 08:20:52 PM »
Malapit na malapit na. ;D ;D Im working on my ARDUINO na para sa scrolling message. ;D +1 boy femfem para sa working code. +1 sir lurker para sa lahat-lahat. +1 kay sir PICUSER sa costumer support. ;D ;D

Ang galing ni boy femfem ahh! ;D ;D
The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Philippine Electronics Forum

Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #420 on: May 28, 2012, 08:20:52 PM »

Offline ΔЅịMø

  • Gas Turbine
  • **
  • Posts: 2903
  • Pogi/Ganda Points: 140
  • Gender: Male
  • "Live Curious"
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #421 on: May 28, 2012, 08:36:33 PM »
galing mo prof! may scrolling kapa ha! bongga! :D :D :D complete na yung project mo sa summer.. :D :D

ginamit mo ba yung tx nung ENC module prof?

Yung tx ng PIC sir. Pinasa nya lang kay arduino yung data. ;D
Computer Engineering National Organization registration thread


Philippine Electronics Forum

Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #421 on: May 28, 2012, 08:36:33 PM »

Offline ΔЅịMø

  • Gas Turbine
  • **
  • Posts: 2903
  • Pogi/Ganda Points: 140
  • Gender: Male
  • "Live Curious"
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #422 on: May 28, 2012, 08:37:32 PM »
Ang galing ni boy femfem ahh! ;D ;D

Salamat sa tulong sir. ;D ;D
Computer Engineering National Organization registration thread


Philippine Electronics Forum

Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #422 on: May 28, 2012, 08:37:32 PM »

Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #423 on: May 28, 2012, 08:38:59 PM »
Eto yung SOIC na PIC sir Lurker. Kaya medjo mahirap mag-solder. ;D

Hindi na pala kailangan palitan ang XTAL.
Baguhin mo lang sa 40Mhz yung clock settings.
Yang 2620 ay nag run sa maximum clock setting niya w/c is 40mhz.
I admire the flexibility of that PIC device, 20 x 4 = 40mhz pa rin!!! ;D ;D
The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Philippine Electronics Forum

Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #423 on: May 28, 2012, 08:38:59 PM »

Offline mini_mouse ^_^

  • Size C Battery
  • *****
  • Posts: 244
  • Pogi/Ganda Points: 7
  • Gender: Female
  • he's keeping it up, I should take pride :)
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #424 on: May 28, 2012, 08:46:42 PM »
Here was the output mga sir.




Congrats lang2... :-) d ko glng napatapos ang video.. Hinay b ang youtube..
...I'm thankful each and every day, coz I found you...

Philippine Electronics Forum

Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #424 on: May 28, 2012, 08:46:42 PM »

Offline ΔЅịMø

  • Gas Turbine
  • **
  • Posts: 2903
  • Pogi/Ganda Points: 140
  • Gender: Male
  • "Live Curious"
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #425 on: May 28, 2012, 08:48:30 PM »

Congrats lang2... :-) d ko glng napatapos ang video.. Hinay b ang youtube..

;D ;D ;D
Computer Engineering National Organization registration thread


Offline carlsberg11

  • Lead Acid Battery
  • *******
  • Posts: 526
  • Pogi/Ganda Points: 30
  • Gender: Male
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #426 on: May 28, 2012, 10:09:30 PM »
Ang galing ni boy femfem ahh! ;D ;D

magaling ka dyan eh sayo nanggaling mga codes eh ...lahat ng makikita dito :D :D kaya ikaw po yung master dito! ;D ;D ;D

indi ko pa rin mapagana yung UART... :( :( ... wala na po ba extra connections mga sirs? good to go na lang po ba yun?



Congrats lang2... :-) d ko glng napatapos ang video.. Hinay b ang youtube..

ilonggo man ni gali si nang lab lab? nang lab lab  mayong gab e :D
Anyone who has never made a mistakes has never tried anything new.

-Albert Einstein

Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #427 on: May 28, 2012, 10:37:52 PM »
^^ Galing daw sayo yung codes ni prof. ;D ;D

Na post ko na ang dapat baguhin sir, please read back nalang.
Dalawang araw ko yan dini debug. ;D
The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Offline ΔЅịMø

  • Gas Turbine
  • **
  • Posts: 2903
  • Pogi/Ganda Points: 140
  • Gender: Male
  • "Live Curious"
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #428 on: May 29, 2012, 11:47:43 AM »
^^ Galing daw sayo yung codes ni prof. ;D ;D

Na post ko na ang dapat baguhin sir, please read back nalang.
Dalawang araw ko yan dini debug. ;D

Yun yung nakalagay sa title ng page eh. ;D BTW, whoever made that code, SALAMAT. ;D ;D ;D
Computer Engineering National Organization registration thread


Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #429 on: May 29, 2012, 12:15:22 PM »
Yup si boy femfem nga... ;D ;D

+1 pala sa video prof.

The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Offline ΔЅịMø

  • Gas Turbine
  • **
  • Posts: 2903
  • Pogi/Ganda Points: 140
  • Gender: Male
  • "Live Curious"
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #430 on: May 29, 2012, 12:22:56 PM »
Yup si boy femfem nga... ;D ;D

+1 pala sa video prof.



Salamat sir. ;D Kaka-download ko lang ng C*MT*CI*, kailangan nya pala ng webcam para syc ang sreen capture sa video capture sa labas. :D Okay lang ba sa inyo mga sir kung post ko dito yung complete code for PIC and ERDUINO? Sa inyo yun eh. :D :D :D
Computer Engineering National Organization registration thread


Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #431 on: May 29, 2012, 12:52:55 PM »
Yung ginawa ko, digicam lang gamit ko pagkuha ng video sa hardware.
Then ini embed ko lang sa screen capture using PIP.
Nandoon sa site nila maraming tutorial to get you started.

Share mo na yang buong codes mo prof. ;D 
The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Offline ΔЅịMø

  • Gas Turbine
  • **
  • Posts: 2903
  • Pogi/Ganda Points: 140
  • Gender: Male
  • "Live Curious"
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #432 on: May 29, 2012, 01:53:47 PM »
Yung ginawa ko, digicam lang gamit ko pagkuha ng video sa hardware.
Then ini embed ko lang sa screen capture using PIP.
Nandoon sa site nila maraming tutorial to get you started.


Ahhh. Sige sir. Pag-aralan ko lang yun muna. Maganda kasing pag video tutorial eh. :)






Share mo na yang buong codes mo prof. ;D


May basbas na galing sa author. ;D Sige sir.

Here is the complete code in PIC where the ENC is connected.

Code: [Select]
// duplex config flags
#include  "__EthEnc28j60.h"
//#pragma orgall 0x200
#define Spi_Ethernet_HALFDUPLEX     0x00  // half duplex
#define Spi_Ethernet_FULLDUPLEX     0x01  // full duplex

// mE ehternet NIC pinout
sfr 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 header
const code unsigned char httpMimeTypeHTML[] = "text/htmlnn" ;              // HTML MIME type
const code unsigned char httpMimeTypeScript[] = "text/plainnn" ;           // TEXT MIME type
unsigned char httpMethod[] = "GET /";

// const code
char automation[] =
"<HTML>
<form name="input" action="/" method="get">
<title>ASIMO</title>
<HEAD></HEAD>
<BODY>
<center>
<table width="500" border="0">
<td colspan="2" style="background-color:#FFA500;">
<h1 align="center">ETHERNET DISPLAY by ASIMO</h1>
<tr valign="top">
<br>
<form name="input" action="/" method="get">
<td align=center bgcolor=#FFD700 <font size=5><b>Message to be displayed:</b></font>
<input name="1" width=120 maxlength=30 type="text" >
<bgcolor=#FFD700><input name="~" width=60 type="submit" value="DISPLAY"></td>
<br>
</tr>
</form>
<tr>
</center>
<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>
";
/***********************************
<script type="text/javascript">
function startTime()
{var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h ":" m ":" s;
t=setTimeout('startTime()',500);
}
function checkTime(i)
{if (i<10)
{i="0"   i;}
return i;}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
*/
/***********************************
 * RAM variables
 */
unsigned char   myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ;   // my MAC address
unsigned char   myIpAddr[4]  = {192, 168, 2, 60 } ;                   // my IP address
unsigned char   gwIpAddr[4]  = {192, 168, 2, 144 } ;                   // gateway (router) IP address
unsigned 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 address

unsigned char   getRequest[15]; //absolute 0x0A00;                                        // HTTP request buffer
unsigned char   dyna[29] ;                                              // buffer for dynamic response
char color1[] = "#FFFF00";                                              // Color yellow. More colors @ http://www.computerhope.com/htmcolor.htm
char color2[] = "#4974E2";                                              // Color blue
unsigned char   dummy[2] ;                                        // HTTP request buffer
bit flag2;
bit flag1;

#define putConstString  SPI_Ethernet_putConstString
#define putString  SPI_Ethernet_putString


unsigned int  SPI_Ethernet_UserTCP (unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength, TEthPktFlags *flags)
       //org 0x200
       {
        unsigned int    len;            // my reply length

        if(localPort != 80)                         // I listen only to web request on port 80
                {
                return(0) ;
                }

        // get 7 first bytes only of the request, the rest does not matter here
        for(len = 0 ; len < 8 ; len  )
        {
        getRequest[len] = SPI_Ethernet_getByte() ;
        }
        getRequest[len] = 0 ;
        len = 0;


        if(memcmp(getRequest, httpMethod, 5))       // only GET method is supported here
                {
                return(0) ;
                }

        for(len = 0 ; len < 25 ; len  )            // Get the rest of the characters. These are the actual characters inputed by
                                                    // by the user on the textbox. Increase this value if you expect more characters.
               {
               getRequest[len] = SPI_Ethernet_getByte() ; // Get the next character.

               if (getRequest[len]==0x26)    // exit if "&" is detected.
                   break;
               if (getRequest[len]==0x2B)       // Detects " ". When the user input a "Hi elabers", the enc receives a "Hi elabers" string.
                         getRequest[len]=0x20;            //  Replace the " " with the actual character "space".
               if (getRequest[len]==0x25)
                  {
{                     getRequest[len] = SPI_Ethernet_getByte();    // Replace the "%" with the next character.
                  switch (getRequest[len]) {
                  case 0x34:  // the first char of the hexa value is 4
                     getRequest[len] = 0x40;   // @
                     dummy[0] = SPI_Ethernet_getByte();          // trash it!!!
                     break;
                  case 0x36:  // the first char of the hexa value is 6
                     getRequest[len] = 0x60;   // '
                     dummy[0] = SPI_Ethernet_getByte();          // trash it!!!
                     break;
                  case 0x32:  // the first char of the hexa value is 2
                     getRequest[len] = SPI_Ethernet_getByte();  // Replace the last character with the next character.
                     switch (getRequest[len]) {                 // The next line of codes will replace it with the actual character.
                    case 0x31: // the second char of the hexa value is 1
                                 getRequest[len] = 0x21;     // !
                                 break;
                    case 0x32: // the second char of the hexa value is 2
                                 getRequest[len] = 0x22;     // "
                                 break;
                    case 0x33: // the second char of the hexa value is 3
                                 getRequest[len] = 0x23;     // #
                                 break;
                    case 0x34: // the second char of the hexa value is 4
                                 getRequest[len] = 0x24;     // $
                                 break;
                    case 0x35: // the second char of the hexa value is 5
                                 getRequest[len] = 0x25;     //%
                                 break;
                    case 0x36: // the second char of the hexa value is 6
                                 getRequest[len] = 0x26;     // &
                                 flag2 = 1;                  // "&" is detected
                                 break;
                    case 0x37: // the second char of the hexa value is 7
                                 getRequest[len] = 0x27;     // '
                                 break;
                    case 0x38: // the second char of the hexa value is 8
                                 getRequest[len] = 0x28;     // (
                                 break;
                    case 0x39: // the second char of the hexa value is 9
                                 getRequest[len] = 0x29;     // )
                                 break;
                    case 0x42: // the second char of the hexa value is B
                                 getRequest[len] = 0x2B;     //  
                                 break;
                    case 0x43: // the second char of the hexa value is C
                                 getRequest[len] = 0x2C;     // ,
                                 break;
                    case 0x46: // the second char of the hexa value is F
                                 getRequest[len] = 0x2F;     // /
                                 break;

                    default: break;
                    }
                     break;
            case 0x33:  // the first char of the hexa value is 3
                     getRequest[len] = SPI_Ethernet_getByte();  // Replace the last character with the next character.
                     switch (getRequest[len]) {                 // The next line of codes will replace it with the actual character.
                      case 0x41: // the second char of the hexa value is A
                                 getRequest[len] = 0x3A;     // :
                                 break;
                      case 0x42: // the second char of the hexa value is B
                                 getRequest[len] = 0x3B;     // ;
                                 break;
                      case 0x43: // the second char of the hexa value is C
                                 getRequest[len] = 0x3C;     // <
                                 break;
                      case 0x44: // the second char of the hexa value is D
                                 getRequest[len] = 0x3D;     // =
                                 break;
                      case 0x45: // the second char of the hexa value is E
                                 getRequest[len] = 0x3E;     // >
                                 break;
                      case 0x46: // the second char of the hexa value is F
                                 getRequest[len] = 0x3F;     // ?
                                 break;

                      default: break;
                     }
                     break;

                    default: break;
                   }
                  
                  }
           }
         }
        getRequest[len] = 0 ;
        len = 0;
        

                UART1_Write_Text(getRequest);
                if(!memcmp(getRequest, "1=ON", 4))   // do we have ON command
                  {PORTB.B5 = 1;}//LATC6_bit = 1;      // set PORTD bit7
                if(!memcmp(getRequest, "1=OFF", 5))     // do we have OFF command
                  {PORTB.B5 = 0;}//LATC6_bit = 0;
                if(!memcmp(getRequest, "reset", 5))     // do we have OFF command
                  {
                  len =  putConstString(httpHeader) ;             // HTTP header
                  len  = putConstString(httpMimeTypeHTML) ;       // with HTML MIME type
                  len  = SPI_Ethernet_putString(automation) ;
                  flag1=1;
                  return(len);
                  }//LATC6_bit = 0;
              //UART1_Write_Text(getRequest);
                 UART1_Write(13);
                  
                 len =  putConstString(httpHeader) ;             // HTTP header
                 len  = putConstString(httpMimeTypeHTML) ;       // with HTML MIME type
                 len  = SPI_Ethernet_putString(automation) ;

                 //SPI_Ethernet_putConstString
        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)
        PORTB.B5 = 0 ;
        TRISB.B5 = 0;
        UART1_Init(9600);
        Delay_ms(100);                  // Wait for UART module to stabilize
        PORTB.B5 = 1;
        delay_ms(100);
        PORTB.B5 = 0;
        delay_ms(100);
        //LATC6_bit=1;
        UART1_Write_Text("READY");
        Delay_ms(100);
        //LATC6_bit=0;
        UART1_Write_Text("1234567891bcdefg");
        flag1=0;
        flag2=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
                 */
                /*
                PORTB.B5 = 1;
                delay_ms(1000);
                PORTB.B5 = 0;
                delay_ms(1000);
                */
                if (flag1)
                asm reset;
                 SPI_Ethernet_doPacket() ;   // process incoming Ethernet packets
                }
        }

Credits to _Lurker_ and  carlsberg11 a.k.a. boy femfem.

Here is the complete code in ARDUINO:

Code: [Select]
// Receives data from the serial port
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char inChar;
int num=0;


void setup()
{
   lcd.clear();
   lcd.begin(16, 2);
   lcd.print(" hello ASIMO =)");
   Serial.begin(9600);
  
}


void loop()
{
  
  lcd.setCursor(16,0);
  
  while (Serial.available()>0)
  {
    inChar = Serial.read();
    num = inChar;
    if (num==13)
    {
      Serial.flush();
      break;
    }
   else
   {  
    lcd.autoscroll();
    lcd.print(inChar);
    delay(1000);
   }    
  }
  
 lcd.noAutoscroll();
 delay(10000);
 lcd.clear();
 lcd.setCursor(16,0);
}

Credits to alyas and glutnix_neo for the Serial.flush() code.

And also, thanks to PICUSER for the hardware.

;D ;D ;D
Computer Engineering National Organization registration thread


Offline carlsberg11

  • Lead Acid Battery
  • *******
  • Posts: 526
  • Pogi/Ganda Points: 30
  • Gender: Male
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #433 on: May 29, 2012, 07:07:13 PM »
Ahhh. Sige sir. Pag-aralan ko lang yun muna. Maganda kasing pag video tutorial eh. :)





May basbas na galing sa author. ;D Sige sir.

Here is the complete code in PIC where the ENC is connected.

Code: [Select]
// duplex config flags
#include  "__EthEnc28j60.h"
//#pragma orgall 0x200
#define Spi_Ethernet_HALFDUPLEX     0x00  // half duplex
#define Spi_Ethernet_FULLDUPLEX     0x01  // full duplex

// mE ehternet NIC pinout
sfr 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 header
const code unsigned char httpMimeTypeHTML[] = "text/htmlnn" ;              // HTML MIME type
const code unsigned char httpMimeTypeScript[] = "text/plainnn" ;           // TEXT MIME type
unsigned char httpMethod[] = "GET /";

// const code
char automation[] =
"<HTML>
<form name="input" action="/" method="get">
<title>ASIMO</title>
<HEAD></HEAD>
<BODY>
<center>
<table width="500" border="0">
<td colspan="2" style="background-color:#FFA500;">
<h1 align="center">ETHERNET DISPLAY by ASIMO</h1>
<tr valign="top">
<br>
<form name="input" action="/" method="get">
<td align=center bgcolor=#FFD700 <font size=5><b>Message to be displayed:</b></font>
<input name="1" width=120 maxlength=30 type="text" >
<bgcolor=#FFD700><input name="~" width=60 type="submit" value="DISPLAY"></td>
<br>
</tr>
</form>
<tr>
</center>
<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>
";
/***********************************
<script type="text/javascript">
function startTime()
{var today=new Date();
var h=today.getHours();
var m=today.getMinutes();
var s=today.getSeconds();
m=checkTime(m);
s=checkTime(s);
document.getElementById('txt').innerHTML=h ":" m ":" s;
t=setTimeout('startTime()',500);
}
function checkTime(i)
{if (i<10)
{i="0"   i;}
return i;}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
*/
/***********************************
 * RAM variables
 */
unsigned char   myMacAddr[6] = {0x00, 0x14, 0xA5, 0x76, 0x19, 0x3f} ;   // my MAC address
unsigned char   myIpAddr[4]  = {192, 168, 2, 60 } ;                   // my IP address
unsigned char   gwIpAddr[4]  = {192, 168, 2, 144 } ;                   // gateway (router) IP address
unsigned 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 address

unsigned char   getRequest[15]; //absolute 0x0A00;                                        // HTTP request buffer
unsigned char   dyna[29] ;                                              // buffer for dynamic response
char color1[] = "#FFFF00";                                              // Color yellow. More colors @ http://www.computerhope.com/htmcolor.htm
char color2[] = "#4974E2";                                              // Color blue
unsigned char   dummy[2] ;                                        // HTTP request buffer
bit flag2;
bit flag1;

#define putConstString  SPI_Ethernet_putConstString
#define putString  SPI_Ethernet_putString


unsigned int  SPI_Ethernet_UserTCP (unsigned char *remoteHost, unsigned int remotePort, unsigned int localPort, unsigned int reqLength, TEthPktFlags *flags)
       //org 0x200
       {
        unsigned int    len;            // my reply length

        if(localPort != 80)                         // I listen only to web request on port 80
                {
                return(0) ;
                }

        // get 7 first bytes only of the request, the rest does not matter here
        for(len = 0 ; len < 8 ; len  )
        {
        getRequest[len] = SPI_Ethernet_getByte() ;
        }
        getRequest[len] = 0 ;
        len = 0;


        if(memcmp(getRequest, httpMethod, 5))       // only GET method is supported here
                {
                return(0) ;
                }

        for(len = 0 ; len < 25 ; len  )            // Get the rest of the characters. These are the actual characters inputed by
                                                    // by the user on the textbox. Increase this value if you expect more characters.
               {
               getRequest[len] = SPI_Ethernet_getByte() ; // Get the next character.

               if (getRequest[len]==0x26)    // exit if "&" is detected.
                   break;
               if (getRequest[len]==0x2B)       // Detects " ". When the user input a "Hi elabers", the enc receives a "Hi elabers" string.
                         getRequest[len]=0x20;            //  Replace the " " with the actual character "space".
               if (getRequest[len]==0x25)
                  {
{                     getRequest[len] = SPI_Ethernet_getByte();    // Replace the "%" with the next character.
                  switch (getRequest[len]) {
                  case 0x34:  // the first char of the hexa value is 4
                     getRequest[len] = 0x40;   // @
                     dummy[0] = SPI_Ethernet_getByte();          // trash it!!!
                     break;
                  case 0x36:  // the first char of the hexa value is 6
                     getRequest[len] = 0x60;   // '
                     dummy[0] = SPI_Ethernet_getByte();          // trash it!!!
                     break;
                  case 0x32:  // the first char of the hexa value is 2
                     getRequest[len] = SPI_Ethernet_getByte();  // Replace the last character with the next character.
                     switch (getRequest[len]) {                 // The next line of codes will replace it with the actual character.
                    case 0x31: // the second char of the hexa value is 1
                                 getRequest[len] = 0x21;     // !
                                 break;
                    case 0x32: // the second char of the hexa value is 2
                                 getRequest[len] = 0x22;     // "
                                 break;
                    case 0x33: // the second char of the hexa value is 3
                                 getRequest[len] = 0x23;     // #
                                 break;
                    case 0x34: // the second char of the hexa value is 4
                                 getRequest[len] = 0x24;     // $
                                 break;
                    case 0x35: // the second char of the hexa value is 5
                                 getRequest[len] = 0x25;     //%
                                 break;
                    case 0x36: // the second char of the hexa value is 6
                                 getRequest[len] = 0x26;     // &
                                 flag2 = 1;                  // "&" is detected
                                 break;
                    case 0x37: // the second char of the hexa value is 7
                                 getRequest[len] = 0x27;     // '
                                 break;
                    case 0x38: // the second char of the hexa value is 8
                                 getRequest[len] = 0x28;     // (
                                 break;
                    case 0x39: // the second char of the hexa value is 9
                                 getRequest[len] = 0x29;     // )
                                 break;
                    case 0x42: // the second char of the hexa value is B
                                 getRequest[len] = 0x2B;     // 
                                 break;
                    case 0x43: // the second char of the hexa value is C
                                 getRequest[len] = 0x2C;     // ,
                                 break;
                    case 0x46: // the second char of the hexa value is F
                                 getRequest[len] = 0x2F;     // /
                                 break;

                    default: break;
                    }
                     break;
            case 0x33:  // the first char of the hexa value is 3
                     getRequest[len] = SPI_Ethernet_getByte();  // Replace the last character with the next character.
                     switch (getRequest[len]) {                 // The next line of codes will replace it with the actual character.
                      case 0x41: // the second char of the hexa value is A
                                 getRequest[len] = 0x3A;     // :
                                 break;
                      case 0x42: // the second char of the hexa value is B
                                 getRequest[len] = 0x3B;     // ;
                                 break;
                      case 0x43: // the second char of the hexa value is C
                                 getRequest[len] = 0x3C;     // <
                                 break;
                      case 0x44: // the second char of the hexa value is D
                                 getRequest[len] = 0x3D;     // =
                                 break;
                      case 0x45: // the second char of the hexa value is E
                                 getRequest[len] = 0x3E;     // >
                                 break;
                      case 0x46: // the second char of the hexa value is F
                                 getRequest[len] = 0x3F;     // ?
                                 break;

                      default: break;
                     }
                     break;

                    default: break;
                   }
                 
                  }
           }
         }
        getRequest[len] = 0 ;
        len = 0;
       

                UART1_Write_Text(getRequest);
                if(!memcmp(getRequest, "1=ON", 4))   // do we have ON command
                  {PORTB.B5 = 1;}//LATC6_bit = 1;      // set PORTD bit7
                if(!memcmp(getRequest, "1=OFF", 5))     // do we have OFF command
                  {PORTB.B5 = 0;}//LATC6_bit = 0;
                if(!memcmp(getRequest, "reset", 5))     // do we have OFF command
                  {
                  len =  putConstString(httpHeader) ;             // HTTP header
                  len  = putConstString(httpMimeTypeHTML) ;       // with HTML MIME type
                  len  = SPI_Ethernet_putString(automation) ;
                  flag1=1;
                  return(len);
                  }//LATC6_bit = 0;
              //UART1_Write_Text(getRequest);
                 UART1_Write(13);
                   
                 len =  putConstString(httpHeader) ;             // HTTP header
                 len  = putConstString(httpMimeTypeHTML) ;       // with HTML MIME type
                 len  = SPI_Ethernet_putString(automation) ;

                 //SPI_Ethernet_putConstString
        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)
        PORTB.B5 = 0 ;
        TRISB.B5 = 0;
        UART1_Init(9600);
        Delay_ms(100);                  // Wait for UART module to stabilize
        PORTB.B5 = 1;
        delay_ms(100);
        PORTB.B5 = 0;
        delay_ms(100);
        //LATC6_bit=1;
        UART1_Write_Text("READY");
        Delay_ms(100);
        //LATC6_bit=0;
        UART1_Write_Text("1234567891bcdefg");
        flag1=0;
        flag2=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
                 */
                /*
                PORTB.B5 = 1;
                delay_ms(1000);
                PORTB.B5 = 0;
                delay_ms(1000);
                */
                if (flag1)
                asm reset;
                 SPI_Ethernet_doPacket() ;   // process incoming Ethernet packets
                }
        }

Credits to _Lurker_ and  carlsberg11 a.k.a. boy femfem.

Here is the complete code in ARDUINO:

Code: [Select]
// Receives data from the serial port
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char inChar;
int num=0;


void setup()
{
   lcd.clear();
   lcd.begin(16, 2);
   lcd.print(" hello ASIMO =)");
   Serial.begin(9600);
   
}


void loop()
{
 
  lcd.setCursor(16,0);
   
  while (Serial.available()>0)
  {
    inChar = Serial.read();
    num = inChar;
    if (num==13)
    {
      Serial.flush();
      break;
    }
   else
   {   
    lcd.autoscroll();
    lcd.print(inChar);
    delay(1000);
   }   
  }
 
 lcd.noAutoscroll();
 delay(10000);
 lcd.clear();
 lcd.setCursor(16,0);
}

Credits to alyas and glutnix_neo for the Serial.flush() code.

And also, thanks to PICUSER for the hardware.

;D ;D ;D

 1 dito prof! ang galing!! clap clap clap   bow bow bow :D :D :D

ibang level na talaga si prof! starting nya mag pic ENCmodule agad... :D :D :D

same goes to sir lurker. everything of this will not be possible kung indi dahil sa ganya.. :D :D

big credits to him! :D

oh ano na next project... taposin ko ngayon assignments ko ....


prof. maganda si miss camt*sia.. ikaw na po bahala mag explore ng body nya.. :D :D :D
Anyone who has never made a mistakes has never tried anything new.

-Albert Einstein

Offline ΔЅịMø

  • Gas Turbine
  • **
  • Posts: 2903
  • Pogi/Ganda Points: 140
  • Gender: Male
  • "Live Curious"
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #434 on: May 29, 2012, 07:10:32 PM »
Nyahahaha. Salamat sir. ;D ;D Aaralin ko lang yun. Mukha kasing maganda eh. :D


Yung dot matrix ko na sir. Bi-build ko muna. Naghahanap na nga ako sa net ng circuit diagram. Meron silang ginamit na shift registers at current sinkers. :D Yun na naman target ko. ;D
Computer Engineering National Organization registration thread


Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #435 on: May 29, 2012, 09:35:27 PM »
Parang merong dot matrix driver sa gizmo prof.
Then mag DIY nalang ng dot matrix LEDs.

Matagal ko na rin gustong gumawa ng dot matrix display.
Pero para sa akin yung serial lcd ang the best pa rin na gamitin. ;D
The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Offline ΔЅịMø

  • Gas Turbine
  • **
  • Posts: 2903
  • Pogi/Ganda Points: 140
  • Gender: Male
  • "Live Curious"
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #436 on: May 29, 2012, 10:43:58 PM »
Parang merong dot matrix driver sa gizmo prof.
Then mag DIY nalang ng dot matrix LEDs.

Matagal ko na rin gustong gumawa ng dot matrix display.
Pero para sa akin yung serial lcd ang the best pa rin na gamitin. ;D


Padala ko nalang kaya yun sir. Baka maayos mo. Kaya lang, pamasko skin yun ni master PICUSER e. :) Remembrance kung baga. Unang bigay ni marter kasi baka meron pang kasunod. ;D

Meron na po akong 8x8 na dot matrix sir. Yung driver nalang ang kulang. Magkano kaya yun sa gizmo?
Computer Engineering National Organization registration thread


Offline PlCUSER

  • Diesel Generator
  • *
  • Posts: 1909
  • Pogi/Ganda Points: 152
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #437 on: May 29, 2012, 10:49:22 PM »
ang gagaling nyo naman mga master. ang gaganda ng mga ginagawa nyo. sana turuan nyo kaming mga newbie. hindi ung kayong mga masters lang ang nag uusap dito. ;D ;D ;D

Offline ΔЅịMø

  • Gas Turbine
  • **
  • Posts: 2903
  • Pogi/Ganda Points: 140
  • Gender: Male
  • "Live Curious"
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #438 on: May 29, 2012, 10:54:04 PM »
ang gagaling nyo naman mga master. ang gaganda ng mga ginagawa nyo. sana turuan nyo kaming mga newbie. hindi ung kayong mga masters lang ang nag uusap dito. ;D ;D ;D

Nyahahahaha. Masters talaga sir huh? ;D Wala narin kasing nagrereply sir e. ;D Na-buzy ata tayo sa quad sir a. :D
Computer Engineering National Organization registration thread


Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #439 on: May 29, 2012, 10:55:44 PM »
Uyy nabuhay na si grand master!

The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Philippine Electronics Forum

Re: MikroC's SPI Ethernet ENC28J60 Library
« Reply #439 on: May 29, 2012, 10:55:44 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com