Plz give me some advice with this code

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
aungkyaw
Posts: 7
Joined: 03 Apr 2016 14:13

Plz give me some advice with this code

#1 Post by aungkyaw » 23 May 2016 10:27

Code: Select all

const char HTTPheader[]="HTTP/1.1 200 OK\nContent-type:";
const char HTTPMimeTypeHTML[]="text/html\n\n";
const char HTTPMimeTypeScript[]="text/plain\n\n";

char StrtPage[]="<html><body>\<form name=\"input\"method=\"get\"><table align=center width=500\
bgcolor=Red border=4><tr><td align=center colspan=2><font size=7\
color=white face=\"verdana\"><b>LED CONTROL</b></font></td></tr>\
<tr><td align=center bgcolor=Blue><input name=\"TA\"type=\"submit\"\
value=\"TOGGLE LED A\"></td><td align=center bgcolor=Green>\
<input name=\"TB\"type=\"submit\"value=\"TOGGLE LED B\"></td></tr>\
</table></form></body></html>";

sfr sbit SPI_Ethernet_Rst at RC0_bit;
sfr sbit SPI_Ethernet_CS at RC1_bit;
sfr sbit SPI_Ethernet_Rst_Direction at TRISC0_bit;
sfr sbit SPI_Ethernet_CS_Direction at TRISC1_bit;

unsigned char MACAddr[6]={0x00,0x14,0xA5,0x76,0x19,0x3F};
unsigned char IPAddr[4]={192,168,1,15};
unsigned char getRequest[10];

typedef struct
{
 unsigned canCloseTCP:1;
 unsigned isBroadcast:1;
}TethPktFlags;

unsigned int SPI_Ethernet_UserTCP(unsigned char *remoteHost,unsigned int remotePort,unsigned int localPort,
                                           unsigned int reqLength, TEthPktFlags *flags)
{
 unsigned int Len;
 for(len=0;len<10;len++)getRequest[len]=SPI_Ethernet_getByte();
 getRequest[len]=0;
 if(memcmp(getRequest,"GET/",5))return(0);
 
 if(!memcmp(getRequest+6,"TA",2))RD0_bit=~RD0_bit;
 else if(!memcmp(getRequest+6,"TB",2))RD1_bit=~RD1_bit;
 
 if(localPort!=80)return(0);
 Len=SPI_Ethernet_putConstString(HTTPheader);
 Len+=SPI_Ethernet_putConstString(HTTPMimeTypeHTML);
 Len+=SPI_Ethernet_putString(StrtPage);
 return Len;
}

unsigned int SPI_Ethernet_UserUDP(unsigned char *remoteHost,
             unsigned int remotePort, unsigned int destPort,
             unsigned int reqLength, TEthPktFlags *flags)
{
 return(0);
}

void main() 
{
 ANSELC=0;
 ANSELD=0;
 TRISD=0;
 PORTD=0;
 SPI1_Init();
 SPI_Ethernet_Init(MACAddr,IPAddr,0x01);

 while(1)
 {
  SPI_Ethernet_doPacket();
 }
}
This code doesn't work. When I opened firfox and typed http://192.168.1.15, it shows Unable to connect.
I don't know what to do. Please Somebody fix it.
Kind Regards,
Aung Kyaw Kyaw...

User avatar
biljana.nedeljkovic
mikroElektronika team
Posts: 1043
Joined: 30 Jun 2015 15:15

Re: Plz give me some advice with this code

#2 Post by biljana.nedeljkovic » 25 May 2016 15:40

Hello,

Which hardware do you use?

Please check our examples about the Ethernet in the compiler and on Libstock:
http://libstock.mikroe.com/

Double check all of your Network parameters. Which code have you used as a reference?

Best regards,
Biljana

aungkyaw
Posts: 7
Joined: 03 Apr 2016 14:13

Re: Plz give me some advice with this code

#3 Post by aungkyaw » 25 May 2016 16:26

I use EasyPIC V7 board with PIC18F45K22 and Serial Ethernet board.
That code is written in Dogan Ibrahim's PIC book.
It doesn't work at all after connecting the board with my pc.
Please give me some advice.

User avatar
biljana.nedeljkovic
mikroElektronika team
Posts: 1043
Joined: 30 Jun 2015 15:15

Re: Plz give me some advice with this code

#4 Post by biljana.nedeljkovic » 27 May 2016 10:02

Hello,

Have you checked the example for the SPI ethernet board for our compiler?
You can find it here:
"C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for PIC\Examples\Extra Boards\SPI Ethernet\p18"

As I mentioned, please check the network parameters first.

Best regards,
Biljana

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”