ENC28J60 Library V3.3 full source code

General discussion on mikroBasic.
Author
Message
sergio_r
Posts: 7
Joined: 25 Jan 2008 18:08
Location: Ukraine

#46 Post by sergio_r » 08 Feb 2008 18:13

Thanks, Florin!
I did not doubt of your code, I understand, that difficulties somewhere at me....

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#47 Post by guyfoc » 09 Feb 2008 09:32

try to use a tool to see the activity on your network ,ex this one
http://www.wireshark.org/
with it you can see the req and answer
i am also a beginner specialy concerning the port usage and ip add ...and with it easy to find
things we are knowing are always easy

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#48 Post by guyfoc » 15 Feb 2008 19:02

:D thanks to florin :D i found how to display the time from my sec_cnt
easily
florin use the NTP server to have time from the server and use the
Get_Time proc
so doing:
NTP_Time =3408048000 +sec_cnt
and using the formated string : TTime.Str_

then for the udp response in the sub function Eth_UserUDP... doing :

Code: Select all

 Eth_PutByte($0D)
      Eth_PutByte($0A)
      len_tcp_resp = len_tcp_resp + CopyRamStringToEthMem_CP(TTime.Str_)
      Eth_PutByte($0D)
      Eth_PutByte($0A)
or to send via udp :

Code: Select all

                                  '  00000000 =   2036-02-07 06:28:16
         NTP_Time =3408048000 +sec_cnt  '  $FFFFFFFF =   2036-02-07 06:28:15
         Get_Time                       '  3408048000 = 2007-12-31 00:00:00  + c001000000 gives 2008-01-01 00:00:00
         Success = Send_UDP(dest_ip_addr, dest_port, eth_port, Str_Len(TTime.Str_), TTime.Str_)

i suppose i am right ? seams to work well
i just hope that at the end of a month the 28 day or 29 or 30 and 31 day
are always ok ????and the 366 day year ????
if that is changed by the server in that case i am wrong .... :evil:
reg guy
things we are knowing are always easy

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#49 Post by yo2lio » 15 Feb 2008 21:12

guyfoc wrote::D thanks to florin :D i found how to display the time from my sec_cnt
:D :D :D

For me , this library is now piece of cake !!! Must be for you also in the short time !!!
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#50 Post by guyfoc » 16 Feb 2008 08:33

in between , look at the lib and see also that florin control the year and month to be ok for you so ... :D
just to take attention to this :sometime difficulty to found the exact name of the var used ( ex here in the lib description in basic i found TTime.Str without the _
but happily i found it ok with the _ in the proc get_time so do not forget to read a little bit more in ..( sorry for me)..(i print always in 2 pages mode so so small for my view....and brill needed..hi)
things we are knowing are always easy

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#51 Post by guyfoc » 16 Feb 2008 08:38

a suggestion is to add this rtn to the string lib also to txfor a 1sec doublewd ctn to a date with a starting periode :D
things we are knowing are always easy

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#52 Post by yo2lio » 16 Feb 2008 09:10

guyfoc wrote:just to take attention to this :sometime difficulty to found the exact name of the var used ( ex here in the lib description in basic i found TTime.Str without the _
I suggested to use *.mcl file compiled by MikroPascal not source code in MikroBasic. In this *.mcl file name of this string is TTime.Str .

In MikroBasic Str word is highlighted , so, I can't use TTime.Str in MikroBasic source code. :oops:
But is accepted from *.mcl file compiled with MikroPascal.

Also this words can not be used in MikroBasic : time, hour, month, len, input. It's possible to be more ....
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#53 Post by guyfoc » 20 Feb 2008 17:09

hi florin , i think i found a small prob with the Get_Time rtn
when going from january 31 23:59:59 i get in the place of 2008-02-01 :
2008-01-32 and the next day it goes to 2008-02-02

2008-01-31 23:59:59
PwrUp_cnt = 00000086399
MODEM = Not Ready
ACCU = 7,1V
DOORS = ALL CLOSED
SIREN = OFF
SMS = DIS
ALARM = ALARM ACTIVE
10.1.1.2:
2008-01-32 00:00:02
PwrUp_cnt = 00000086402

i do not use the ntp server but put the day and time in my prog and let the sec_cnt running than add an offset
ex:

Code: Select all

NTP_Time =time_offset +sec_cnt
         Get_Time  

Code: Select all

sub procedure  set_date(dim byref new_date as string[7])
    dim ref_year   as word
    dim new_year ,new_month ,new_day as    string[3]
    dim NY ,NM ,ND  as word
    
    new_year ="00"
    new_month = "00"
    new_day   ="00"
    ref_year = 8                     ' ref for 2008 =08
    time_offset =     3408048000     ' for ref 2008-01-01  00:00:00

    new_year[0]  = new_date[0]
    new_year[1]  = new_date[1]
    new_month[0] = new_date[2]
    new_month[1] = new_date[3]
    new_day[0] = new_date[4]
    new_day[1] = new_date[5]

    NY = strtoword(new_year)
    NM = strtoword(new_month)
    ND = strtoword(new_day)

    while NY > ref_year
          if (ref_year and $03)=0 then time_offset = time_offset + 31622400   '366j x 86400 sec bissectille
              else    time_offset = time_offset + 31536000                    '365j
          end if
          inc(ref_year)        ' ref_year = NY at the end
    wend
    for i=2 to NM

    select case i
           case 2,4,6,8,9,11   time_offset = time_offset + 2678400   'if feb add 31d for january ....
           case 3    if (ref_year and $03)=0 then  time_offset = time_offset + 2505600  ' 29 * 86400 sec for feb
                                       else   time_offset = time_offset +  2419200   ' 28 * 86400 sec for feb
                     end if
           case 5,7,10,12    time_offset = time_offset + 2592000   ' add 30d for april ....
    end select

    next  i
    time_offset = time_offset + ND * 86400     ' add day * 86400 sec/d
    
    
end sub

Code: Select all

sub function set_time(dim byref pwr_up_ini as string[11]) as Longint

    dim hours ,min,sec as string[2]
    dim hoursB,minB,secB   as byte
    hours="00"
    min="00"
    sec="00"

    hours[0] = pwr_up_ini[0]
    hours[1] = pwr_up_ini[1]
    min[0]   = pwr_up_ini[2]
    min[1]   = pwr_up_ini[3]
    sec[0]   = pwr_up_ini[4]
    sec[1]   = pwr_up_ini[5]

    hoursB   = Str2Byte(hours)
    minB     = Str2Byte(min)
    secB     = Str2Byte(sec)

    result   = hoursB * 3600  + minB * 60 + secB
end sub

Code: Select all

if getRequest[0] = "c" then           ' clock c235906 for 23h 59m 06 sec
       for i =0 to 5
          msg_recv[i] = getRequest[i+1]   'msg   c092100  c for clock adj    09h  21 min  00sec
       next i
       msg_recv[6] = $00                 ' for end of string
       sec_cnt = set_time(msg_recv)        ' sec_cnt = set_time("092100")
    end if


     if( getRequest[0] = "d" )then
         for i =0 to 5
           msg_recv[i] = getRequest[i+1]   'msg   d120531   =   year 2012, month 05 , day 31
         next i
         msg_recv[6] = $00
         set_date(msg_recv)
     end if
no time yet to look to see what is wrong in your rtn ( suppose you will find it before me..hi) :D
things we are knowing are always easy

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#54 Post by guyfoc » 20 Feb 2008 18:11

may be but not sure: in theses lines missing a test for 30 ????

If (TempDay = 366) And (TTime.Month_ <= 2) Then
TTime.Day = buf + 1

If TTime.Day = 30 Then ' must be added ??????
TTime.Day = 1
TTime.Month_ = TTime.Month_ + 1
end if
goto next1
:D to be tested
things we are knowing are always easy

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#55 Post by guyfoc » 20 Feb 2008 18:14

or test for 32 not 30
things we are knowing are always easy

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#56 Post by yo2lio » 20 Feb 2008 22:53

Mea culpa !

Get_Time routine was ready-made from ... somewhere ... :oops: :oops: :oops:

So, my version :

Code: Select all

sub procedure Get_Time
dim save_intcon,ii as byte
    buf as longword
    TempDay, TempMonth, buf_d as word
    text as string[3]
  save_intcon = INTCON and $80
  INTCON.7 = 0
  TTime.Rfc = NTP_Time
  INTCON = INTCON or save_intcon
  TTime.Unix = TTime.Rfc - 2208988800
  buf = TTime.Unix
  TTime.Sec = buf Mod 60
  buf = buf div 60
  TTime.Min = buf Mod 60
  buf = buf div 60
  TTime.Hour_ = buf Mod 24
  buf = buf div 24
  TTime.Year = 1970
  buf_d = Word(buf)
  While true
    TempDay = 365
    If (TTime.Year And $03) = 0 Then TempDay = 366 end if
    If TempDay > buf_d Then break end if
    buf_d = buf_d - TempDay
    Inc (TTime.Year)
  wend
  inc(buf_d)
  For ii = 1 To 12
    TempMonth = Months_Days[ii]
    if (ii = 2) and (TempDay = 366) then TempMonth = 29 end if
    If buf_d <= TempMonth Then break end if
    buf_d = buf_d - TempMonth
  next ii
  TTime.Month_ = ii
  TTime.Day = buf_d
  Word2Str(TTime.Year,TTime.Str_)
  Str_Cat(TTime.Str_, "-")
  Byte2StrWithZeros(TTime.Month_, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
  Str_Cat(TTime.Str_, "-")
  Byte2StrWithZeros(TTime.Day, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
  Str_Cat(TTime.Str_, " ")
  Byte2StrWithZeros(TTime.Hour_, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
  Str_Cat(TTime.Str_, ":")
  Byte2StrWithZeros(TTime.Min, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
  Str_Cat(TTime.Str_, ":")
  Byte2StrWithZeros(TTime.Sec, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
end sub
Source code and all examples will be updated soon as possible !

Thank you for understanding.
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#57 Post by yo2lio » 21 Feb 2008 05:59

A little bit faster :

Code: Select all

sub procedure Get_Time
dim save_intcon,ii as byte
    buf as longword
    TempDay, TempMonth, buf_d as word
    text as string[3]
  save_intcon = INTCON and $80
  INTCON.7 = 0
  TTime.Rfc = NTP_Time
  INTCON = INTCON or save_intcon
  TTime.Unix = TTime.Rfc - 2208988800
  buf = TTime.Unix
  TTime.Sec = buf Mod 60
  buf = buf div 60
  TTime.Min = buf Mod 60
  buf = buf div 60
  TTime.Hour_ = buf Mod 24
  buf = buf div 24
'  TTime.Year = 1970
  buf_d = Word(buf)
  TTime.Year = (buf_d div 1461)*4 + 1970
  buf_d = buf_d Mod 1461
  While true
    TempDay = 365
    If (TTime.Year And $03) = 0 Then TempDay = 366 end if
    If TempDay > buf_d Then break end if
    buf_d = buf_d - TempDay
    Inc (TTime.Year)
  wend
  inc(buf_d)
  For ii = 1 To 12
    TempMonth = Months_Days[ii]
    if (ii = 2) and (TempDay = 366) then TempMonth = 29 end if
    If buf_d <= TempMonth Then break end if
    buf_d = buf_d - TempMonth
  next ii
  TTime.Month_ = ii
  TTime.Day = buf_d
  Word2Str(TTime.Year,TTime.Str_)
  Str_Cat(TTime.Str_, "-")
  Byte2StrWithZeros(TTime.Month_, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
  Str_Cat(TTime.Str_, "-")
  Byte2StrWithZeros(TTime.Day, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
  Str_Cat(TTime.Str_, " ")
  Byte2StrWithZeros(TTime.Hour_, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
  Str_Cat(TTime.Str_, ":")
  Byte2StrWithZeros(TTime.Min, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
  Str_Cat(TTime.Str_, ":")
  Byte2StrWithZeros(TTime.Sec, text)
  RemoveFirstNChr(text,1)
  Str_Cat(TTime.Str_, text)
end sub
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

guyfoc
Posts: 297
Joined: 09 Sep 2005 11:34
Location: belgium

#58 Post by guyfoc » 21 Feb 2008 16:58

:D tested the 1st version and ok
thks again for promp update
rem: please say us when you have updated the pascal lib1.mcl and lib2.mcl
( keep your time)
because to test this change:
i used the lib1.pbas and modify it, then compile it with the definition_ENC.pbas present in the dir, it compile ok but the lib2.pbas gives prob and i must use my old lib2.mcl)
so after i remove the definition_ENC.mcl and let only the new lib1.mcl and old lib2.mcl
like that it is ok but complicated
as you said i will use in the futur the 2 lib.mcl from pascal
reg s guy
things we are knowing are always easy

Mardaso
Posts: 14
Joined: 23 Apr 2006 12:07
Location: Netherlands

#59 Post by Mardaso » 26 Feb 2008 12:51

Thanks Florin for this Software!

I tried it and love it. I've been waiting for this as a starting point for my web projects.

The software is functioning well on my easypic4 and ME ethernetboard.
However is it possible to adapt/convert it to other boards?
I have a Pic-Web from olimex and would like to run a webserver on that board.
But the pinning is different from the ME board and Eth_Init is for one port.
The Pic-Web board has the connections on different ports.

yo2lio
Posts: 1878
Joined: 19 Sep 2006 12:57
Location: Romania, Arad City
Contact:

#60 Post by yo2lio » 08 Mar 2008 16:11

Hi,

Library updated. Resolved small bug in Get_Time routine.
Renamed all ENC28J60 registers (in unit definitions_ENC).
Added 4 new procedures Eth_SetBank_0, Eth_SetBank_1, Eth_SetBank_2, Eth_SetBank_3, instead of Eth_SetBank(x).

You can download source code from : http://www.microelemente.ro/MikroBasic/ ... amples.zip

Old files : http://www.microelemente.ro/MikroBasic/ ... es_old.zip
Best regards, Florin Andrei Medrea.

http://www.microelemente.ro/
http://www.microelemente.ro/produse-si-servicii/
http://www.microelemente.ro/custom-software/

mail : florin@microelemente.ro

Post Reply

Return to “mikroBasic General”